UNPKG

gchcg-cli

Version:
1 lines 2.96 kB
const Command=require("./command"),log=require("./log"),inquirer=require("inquirer").default,SimpleGit=require("simple-git"),path=require("path"),fs=require("fs"),fse=require("fs-extra");class PushCommand extends Command{async init(){this.branch=this._cmd.branch}async exec(){const e=(new Date).getTime();try{let e;this.prepare(),this.git=SimpleGit(this.projectInfo.dir),e=await this.git.status(),log.info("当前分支:"+e.current),log.info("远程分支:"+e.tracking||"本地分支未关联远程分支"),e.detached&&log.error("当前处于游离状态,需谨慎操作,避免提交丢失。建议创建新分支保存提交:git checkout -b temp/1.0.0"),e.conflicted.length>0?(e.conflicted.forEach((e=>{log.info("冲突文件:",e)})),log.warn("如果在执行合并操作时,某些文件产生了冲突,它们会列在这里,解决完冲突请执行:cg push")):log.success("没有冲突文件"),e.not_added.length?(e.not_added.forEach((e=>{log.info("未添加文件:",e)})),log.warn("如果您对文件进行了更改,但没有运行 git add,这些文件将出现在此列表中,请执行:cg push")):log.success("没有未添加文件"),e.created.length?(e.created.forEach((e=>{log.info("新增文件:",e)})),log.warn("如果您创建了新文件但尚未执行 git add 和 git commit,这些文件将列在这里。请执行:cg push")):log.success("没有新增文件"),e.deleted.length?(e.deleted.forEach((e=>{log.info("删除文件:",e)})),log.warn("如果您删除了文件,但尚未提交这些更改,它们将显示在这里,请执行:cg push")):log.success("没有删除文件"),e.modified.length?(e.modified.forEach((e=>{log.info("修改文件:",e)})),log.warn("表示您对某些文件进行了修改,但没有 git add,请执行:cg push")):log.success("没有修改文件"),e.renamed.length?(e.renamed.forEach((e=>{log.info("重命名文件:",e)})),log.warn("如果您重命名了文件但尚未提交变更,这里会列出重命名的文件,请执行:cg push")):log.success("没有重命名文件"),e.staged.length?(e.staged.forEach((e=>{log.info("暂存文件:",e)})),log.warn("如果您运行了 git add .命令,暂存的文件将出现在此列表中,请执行:cg push 或者 cg publish")):log.success("没有暂存文件"),e.ahead&&log.warn("远程分支落后本地分支:"+e.ahead+"。请推送代码:cg push"),e.behind?log.warn("远程分支领先本地分支:"+e.behind+"次。请拉取代码:cg pull"):log.success("没有需要pull的文件"),log.success("git状态检查完成")}catch(e){log.error(e.message)}log.verbose("本次执行指令耗时:"+((new Date).getTime()-e)/1e3+"秒")}prepare(){const e=process.cwd(),o=path.resolve(e,".git");if(!fs.existsSync(o))throw new Error("未找到 .git 文件夹,初始化 git 后重试");this.projectInfo={dir:e}}}function init(e){return new PushCommand(e)}module.exports=init,module.exports.PushCommand=PushCommand;