zen-gitsync 1.3.5 → 1.3.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/gitCommit.js +17 -10
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zen-gitsync",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.6",
|
|
4
4
|
"description": "一个 git 自动查看差异并提交的工具",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"type": "git",
|
|
31
31
|
"url": "git+https://github.com/xz333221/zen-gitsync.git"
|
|
32
32
|
},
|
|
33
|
-
"keywords": [],
|
|
33
|
+
"keywords": ["gitsync", "git"],
|
|
34
34
|
"author": "",
|
|
35
35
|
"license": "MIT",
|
|
36
36
|
"bugs": {
|
package/src/gitCommit.js
CHANGED
|
@@ -100,6 +100,7 @@ class GitCommit {
|
|
|
100
100
|
process.exit()
|
|
101
101
|
}
|
|
102
102
|
}
|
|
103
|
+
|
|
103
104
|
judgeLog() {
|
|
104
105
|
const logArg = process.argv.find(arg => arg === 'log');
|
|
105
106
|
if (logArg) {
|
|
@@ -107,12 +108,14 @@ class GitCommit {
|
|
|
107
108
|
return true;
|
|
108
109
|
}
|
|
109
110
|
}
|
|
111
|
+
|
|
110
112
|
judgeHelp() {
|
|
111
113
|
if (process.argv.includes('-h') || process.argv.includes('--help')) {
|
|
112
114
|
showHelp();
|
|
113
115
|
return true;
|
|
114
116
|
}
|
|
115
117
|
}
|
|
118
|
+
|
|
116
119
|
execDiff() {
|
|
117
120
|
const no_diff = process.argv.find(arg => arg.startsWith('--no-diff'))
|
|
118
121
|
if (!no_diff) {
|
|
@@ -121,6 +124,7 @@ class GitCommit {
|
|
|
121
124
|
})
|
|
122
125
|
}
|
|
123
126
|
}
|
|
127
|
+
|
|
124
128
|
async execAddAndCommit() {
|
|
125
129
|
// 检查 -m 参数(提交信息)
|
|
126
130
|
const commitMessageArg = process.argv.find(arg => arg.startsWith('-m'));
|
|
@@ -152,8 +156,9 @@ class GitCommit {
|
|
|
152
156
|
this.execSyncGitCommand(`git commit -m "${this.commitMessage || defaultCommitMessage}"`)
|
|
153
157
|
}
|
|
154
158
|
}
|
|
159
|
+
|
|
155
160
|
async judgeRemote() {
|
|
156
|
-
try{
|
|
161
|
+
try {
|
|
157
162
|
const spinner = ora('正在检查远程更新...').start();
|
|
158
163
|
// 检查是否有远程更新
|
|
159
164
|
// 先获取远程最新状态
|
|
@@ -190,20 +195,21 @@ class GitCommit {
|
|
|
190
195
|
spinner.stop();
|
|
191
196
|
console.log(chalk.green('✓ 本地已是最新'));
|
|
192
197
|
}
|
|
193
|
-
}catch (e) {
|
|
198
|
+
} catch (e) {
|
|
194
199
|
// console.log(`e ==> `, e)
|
|
195
200
|
spinner.stop();
|
|
196
201
|
throw new Error(e)
|
|
197
202
|
}
|
|
198
203
|
}
|
|
199
|
-
|
|
200
|
-
|
|
204
|
+
|
|
205
|
+
async execPull() {
|
|
206
|
+
try {
|
|
201
207
|
// 检查是否需要拉取更新
|
|
202
208
|
const spinner = ora('正在拉取代码...').start();
|
|
203
209
|
await this.execGitCommand('git pull', {
|
|
204
210
|
spinner
|
|
205
211
|
})
|
|
206
|
-
}catch (e) {
|
|
212
|
+
} catch (e) {
|
|
207
213
|
console.log(chalk.yellow('⚠️ 拉取远程更新合并失败,可能存在冲突,请手动处理'));
|
|
208
214
|
throw Error(e)
|
|
209
215
|
}
|
|
@@ -214,14 +220,14 @@ class GitCommit {
|
|
|
214
220
|
judgePlatform()
|
|
215
221
|
|
|
216
222
|
// 检查是否有 log 参数
|
|
217
|
-
if(this.judgeLog()) return
|
|
223
|
+
if (this.judgeLog()) return
|
|
218
224
|
|
|
219
225
|
// 检查帮助参数
|
|
220
|
-
if(this.judgeHelp()) return
|
|
226
|
+
if (this.judgeHelp()) return
|
|
221
227
|
|
|
222
228
|
this.statusOutput = this.execSyncGitCommand('git status')
|
|
223
229
|
const hasUnmerged = this.statusOutput.includes('You have unmerged paths');
|
|
224
|
-
if(hasUnmerged){
|
|
230
|
+
if (hasUnmerged) {
|
|
225
231
|
errorLog('错误', '存在未合并的文件,请先解决冲突')
|
|
226
232
|
process.exit(1);
|
|
227
233
|
}
|
|
@@ -239,7 +245,7 @@ class GitCommit {
|
|
|
239
245
|
await this.judgeRemote() // 等待 judgeRemote 完成
|
|
240
246
|
|
|
241
247
|
this.exec_push()
|
|
242
|
-
}else{
|
|
248
|
+
} else {
|
|
243
249
|
if (this.statusOutput.includes('use "git push')) {
|
|
244
250
|
this.exec_push()
|
|
245
251
|
} else if (this.statusOutput.includes('use "git pull')) {
|
|
@@ -250,6 +256,7 @@ class GitCommit {
|
|
|
250
256
|
}
|
|
251
257
|
}
|
|
252
258
|
} catch (e) {
|
|
259
|
+
// console.log(`e ==> `, e)
|
|
253
260
|
// console.log(`e.message ==> `, e.message)
|
|
254
261
|
// 应该提供更具体的错误信息
|
|
255
262
|
// console.error('Git operation failed:', e.message);
|
|
@@ -313,8 +320,8 @@ class GitCommit {
|
|
|
313
320
|
}
|
|
314
321
|
|
|
315
322
|
execSyncGitCommand(command, options = {}) {
|
|
323
|
+
let {encoding = 'utf-8', maxBuffer = 30 * 1024 * 1024, head = command, log = true} = options
|
|
316
324
|
try {
|
|
317
|
-
let {encoding = 'utf-8', maxBuffer = 30 * 1024 * 1024, head = command, log = true} = options
|
|
318
325
|
let cwd = getCwd()
|
|
319
326
|
const output = execSync(command, {encoding, maxBuffer, cwd})
|
|
320
327
|
if (options.spinner) {
|