ai-git-tools 1.0.3 → 1.0.4
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/bin/cli.js +1 -1
- package/package.json +1 -1
- package/src/commands/commit-all.js +34 -3
- package/src/core/git-operations.js +17 -0
package/bin/cli.js
CHANGED
package/package.json
CHANGED
|
@@ -149,16 +149,25 @@ async function commitGroup(group, files, config, logger) {
|
|
|
149
149
|
GitOperations.resetStaged();
|
|
150
150
|
|
|
151
151
|
// Add 這組的檔案
|
|
152
|
+
const addedFiles = [];
|
|
152
153
|
for (const file of files) {
|
|
153
154
|
console.log(` ├─ ${file.filePath}`);
|
|
154
155
|
try {
|
|
155
156
|
GitOperations.addFile(file.filePath);
|
|
157
|
+
addedFiles.push(file.filePath);
|
|
156
158
|
} catch (error) {
|
|
157
159
|
logger.warn(`無法 add 檔案 ${file.filePath}: ${error.message}`);
|
|
158
|
-
|
|
160
|
+
// 繼續處理其他檔案,不要中斷
|
|
161
|
+
continue;
|
|
159
162
|
}
|
|
160
163
|
}
|
|
161
164
|
|
|
165
|
+
// 如果沒有成功 add 任何檔案,跳過這個群組
|
|
166
|
+
if (addedFiles.length === 0) {
|
|
167
|
+
logger.warn('沒有檔案被成功 add,跳過此群組');
|
|
168
|
+
return false;
|
|
169
|
+
}
|
|
170
|
+
|
|
162
171
|
// 生成 commit message
|
|
163
172
|
console.log(` └─ 生成 commit message...`);
|
|
164
173
|
const commitMessage = await generateCommitMessage(group, files, config, logger);
|
|
@@ -245,9 +254,31 @@ export async function commitAllCommand(options) {
|
|
|
245
254
|
let successCount = 0;
|
|
246
255
|
for (let i = 0; i < groups.length; i++) {
|
|
247
256
|
const group = groups[i];
|
|
248
|
-
|
|
257
|
+
|
|
258
|
+
// 驗證並過濾有效的檔案索引
|
|
259
|
+
const validFiles = group.file_indices
|
|
260
|
+
.filter(index => {
|
|
261
|
+
if (index < 0 || index >= changes.length) {
|
|
262
|
+
logger.warn(`無效的檔案索引: ${index}`);
|
|
263
|
+
return false;
|
|
264
|
+
}
|
|
265
|
+
return true;
|
|
266
|
+
})
|
|
267
|
+
.map(index => changes[index])
|
|
268
|
+
.filter(file => {
|
|
269
|
+
if (!file || !file.filePath) {
|
|
270
|
+
logger.warn('檔案資訊不完整,已跳過');
|
|
271
|
+
return false;
|
|
272
|
+
}
|
|
273
|
+
return true;
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
if (validFiles.length === 0) {
|
|
277
|
+
logger.warn(`群組 ${i + 1} 沒有有效的檔案,跳過`);
|
|
278
|
+
continue;
|
|
279
|
+
}
|
|
249
280
|
|
|
250
|
-
const success = await commitGroup(group,
|
|
281
|
+
const success = await commitGroup(group, validFiles, config, logger);
|
|
251
282
|
if (success) {
|
|
252
283
|
successCount++;
|
|
253
284
|
}
|
|
@@ -154,6 +154,23 @@ export class GitOperations {
|
|
|
154
154
|
* Add 檔案
|
|
155
155
|
*/
|
|
156
156
|
static addFile(filePath) {
|
|
157
|
+
// 檢查檔案是否存在(對於新檔案和已修改檔案)
|
|
158
|
+
if (!existsSync(filePath)) {
|
|
159
|
+
// 可能是 git 追蹤的檔案但在工作目錄中不存在
|
|
160
|
+
// 嘗試使用 git ls-files 確認
|
|
161
|
+
try {
|
|
162
|
+
const tracked = GitOperations.exec(`git ls-files "${filePath}"`, {
|
|
163
|
+
silent: true,
|
|
164
|
+
throwOnError: false
|
|
165
|
+
});
|
|
166
|
+
if (!tracked || !tracked.trim()) {
|
|
167
|
+
throw new Error(`檔案不存在: ${filePath}`);
|
|
168
|
+
}
|
|
169
|
+
} catch (error) {
|
|
170
|
+
throw new Error(`檔案不存在或無法追蹤: ${filePath}`);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
157
174
|
GitOperations.exec(`git add "${filePath}"`);
|
|
158
175
|
}
|
|
159
176
|
|