openmatrix 0.1.95 → 0.1.96
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.
|
@@ -342,33 +342,23 @@ class GitCommitManager {
|
|
|
342
342
|
const commitMessage = this.generateCommitMessage(fullInfo, filesWithStatus);
|
|
343
343
|
// 暂存所有文件(.gitignore 已更新,.openmatrix/ 等目录会被排除)
|
|
344
344
|
await execAsync('git add .', { cwd: this.repoPath });
|
|
345
|
-
//
|
|
346
|
-
//
|
|
347
|
-
const
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
'.gradle/',
|
|
363
|
-
'vendor/',
|
|
364
|
-
'.env',
|
|
365
|
-
'.env.local',
|
|
366
|
-
'.env.*.local',
|
|
367
|
-
'*.tsbuildinfo',
|
|
368
|
-
'*.pyc',
|
|
369
|
-
];
|
|
370
|
-
for (const pattern of unstagePatterns) {
|
|
371
|
-
await execAsync(`git reset HEAD -- "${pattern}"`, { cwd: this.repoPath }).catch(() => { });
|
|
345
|
+
// 动态检查:用 git check-ignore 逐个检查暂存文件,移除应被忽略的
|
|
346
|
+
// 这样无论 .gitignore 怎么更新,都不会误提交构建产物、依赖目录等
|
|
347
|
+
const { stdout: stagedFiles } = await execAsync('git diff --cached --name-only', { cwd: this.repoPath });
|
|
348
|
+
const filesToUnstage = [];
|
|
349
|
+
for (const file of stagedFiles.split('\n').filter(Boolean)) {
|
|
350
|
+
try {
|
|
351
|
+
await execAsync(`git check-ignore -q "${file}"`, { cwd: this.repoPath });
|
|
352
|
+
// check-ignore 返回 0 → 文件应该被忽略
|
|
353
|
+
filesToUnstage.push(file);
|
|
354
|
+
}
|
|
355
|
+
catch {
|
|
356
|
+
// check-ignore 返回 1 → 文件不应被忽略,保留暂存
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
if (filesToUnstage.length > 0) {
|
|
360
|
+
const unstageCmd = filesToUnstage.map(f => `"${f}"`).join(' ');
|
|
361
|
+
await execAsync(`git reset HEAD -- ${unstageCmd}`, { cwd: this.repoPath }).catch(() => { });
|
|
372
362
|
}
|
|
373
363
|
// 检查是否有文件被暂存(避免空提交)
|
|
374
364
|
const { stdout: staged } = await execAsync('git diff --cached --name-only', { cwd: this.repoPath });
|