From 551562c9ff811fbb05b6c9bb90078f6d41c57c1f Mon Sep 17 00:00:00 2001 From: OBKoro1 <1677593011@qq.com> Date: Tue, 7 Jan 2020 22:34:31 +0800 Subject: [PATCH] =?UTF-8?q?=E9=9A=8F=E6=9C=BAcommit=E6=AC=A1=E6=95=B0?= =?UTF-8?q?=E4=BB=A5=E5=8F=8Acommit=E5=9B=9E=E6=BB=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 6 ++++++ README.md | 2 -- src/models/commitHandle.ts | 43 ++++++++++++++++++++++++++++++++++---- src/views/autoCommit.html | 35 ++++++++++++++++++++++++++++--- 4 files changed, 77 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ace045e..99f6b6d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,12 @@ + + + + + + ### [V1.0.0] - Initial release \ No newline at end of file diff --git a/README.md b/README.md index bfedef5..afd71fd 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,4 @@ # 用于学习交流 - - \ No newline at end of file diff --git a/src/models/commitHandle.ts b/src/models/commitHandle.ts index 55ff5e3..bddf6d5 100644 --- a/src/models/commitHandle.ts +++ b/src/models/commitHandle.ts @@ -2,7 +2,7 @@ * Author : OBKoro1 * Date : 2019-12-30 16:59:30 * LastEditors : OBKoro1 - * LastEditTime : 2020-01-04 15:14:39 + * LastEditTime : 2020-01-07 22:30:03 * FilePath : /autoCommit/src/models/commitHandle.ts * Description : commit 具体操作 * https://github.com/OBKoro1 @@ -91,6 +91,10 @@ class CommitHandle { if (this.cancelCommit()) break; // 每个日期commit次数 let dayCommitNumber = this.paramsObj.commitNumber; + if (this.paramsObj.randomCommit) { + // 随机commit次数 + dayCommitNumber = RandomNumber(1, this.paramsObj.commitNumber); + } if (item.commitNumber !== 0) { // 如果该范围有commit次数 则用该范围的 dayCommitNumber = item.commitNumber; @@ -137,12 +141,43 @@ class CommitHandle { }, 1000); }); } - await outputLog(`${totalNum + 1}commit内容`, commitContent); - await outputLog(`${totalNum + 1}commit信息`, commitMsg); + outputLog(`${totalNum + 1}commit内容`, commitContent); + outputLog(`${totalNum + 1}commit信息`, commitMsg); totalNum++; } } - this.myExecSync(`cd ${this.paramsObj.itemSrc} && git pull && git push`) + if (this.cancelCommit()) { + if (totalNum < 1) return; + outputLog('回滚中...'); + const res = await new Promise((resolve, reject) => { + let cmd = `cd ${this.paramsObj.itemSrc} && git reset --hard HEAD~${totalNum}`; + exec(cmd, (error, stdout, stderr) => { + if (error) { + outputLog(`执行命令出错:${cmd}`); + outputLog(`回滚失败:${error}`, stderr); + reject(error); + return; + } + outputLog('回滚成功:', stdout); + resolve(stdout); + }); + }); + } else { + outputLog('提交中...'); + const res = await new Promise((resolve, reject) => { + let cmd = `cd ${this.paramsObj.itemSrc} && git pull && git push`; + exec(cmd, (error, stdout, stderr) => { + if (error) { + outputLog(`执行命令出错:${cmd}`); + outputLog(`错误信息:${error}`, stderr); + reject(error); + return; + } + resolve(stdout); + }); + }); + outputLog('提交信息:', res); + } this.commitEnd(totalNum); } commitEnd(totalNum: number) { diff --git a/src/views/autoCommit.html b/src/views/autoCommit.html index 58e537c..106af37 100644 --- a/src/views/autoCommit.html +++ b/src/views/autoCommit.html @@ -44,12 +44,33 @@ + + + + + + + + + - + + 删除 @@ -156,6 +177,7 @@ form: { // TODO: 保存其他几个参数 // itemSrc: '/Users/koro/work/web_my/testCommit', + randomCommit: true, itemSrc: '点击选择要commit的项目文件夹', fileName: 'commit.md', commitMsg: 'autoCommit', @@ -165,7 +187,7 @@ commitNumber: 0 } ], - commitNumber: 1, + commitNumber: 10, }, rules: { 'itemSrc': [ @@ -326,6 +348,13 @@ commitNumber: 0 }); }, + switchChange(value){ + if(value){ + this.form.commitNumber = 10; + }else{ + this.form.commitNumber = 1; + } + }, fileNameChange(value) { if (value === '') { this.form.fileName = 'commit.md'