openmatrix 0.1.78 → 0.1.79
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.
|
@@ -225,9 +225,25 @@ class GitCommitManager {
|
|
|
225
225
|
return { success: false, message: 'Auto-commit is disabled' };
|
|
226
226
|
}
|
|
227
227
|
try {
|
|
228
|
-
// 检查是否在 Git
|
|
228
|
+
// 检查是否在 Git 仓库中,如果不是则自动初始化
|
|
229
229
|
if (!await this.isGitRepo()) {
|
|
230
|
-
|
|
230
|
+
await execAsync('git init', { cwd: this.repoPath });
|
|
231
|
+
// 确保 .gitignore 存在并包含 .openmatrix
|
|
232
|
+
const gitignorePath = path.join(this.repoPath, '.gitignore');
|
|
233
|
+
let gitignoreContent = '';
|
|
234
|
+
try {
|
|
235
|
+
gitignoreContent = await fs.readFile(gitignorePath, 'utf-8');
|
|
236
|
+
}
|
|
237
|
+
catch {
|
|
238
|
+
// 文件不存在
|
|
239
|
+
}
|
|
240
|
+
if (!gitignoreContent.includes('.openmatrix')) {
|
|
241
|
+
const addition = (gitignoreContent && !gitignoreContent.endsWith('\n') ? '\n' : '') + '.openmatrix/\n';
|
|
242
|
+
await fs.writeFile(gitignorePath, gitignoreContent + addition, 'utf-8');
|
|
243
|
+
}
|
|
244
|
+
// 初始提交
|
|
245
|
+
await execAsync('git add .gitignore', { cwd: this.repoPath });
|
|
246
|
+
await execAsync('git commit -m "initial commit" --allow-empty', { cwd: this.repoPath }).catch(() => { });
|
|
231
247
|
}
|
|
232
248
|
// 获取未提交的文件
|
|
233
249
|
const files = await this.getUncommittedFiles();
|