Skip to content

Commit 1ab53b8

Browse files
committed
fix(cli-plugin-ai-index): handle file renames in getChangedFiles function
1 parent 85fdbc7 commit 1ab53b8

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

packages/cli-plugins/ai-index/src/utils/git/file-changes.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@ export const getChangedFiles = async (options: GitDiffOptions): Promise<ChangedF
3636
// Match status and file path
3737
// Format: "A\tfile.ts" or "M\tfile.ts" or "D\tfile.ts"
3838
// Also handle renames: "R100\told.ts\tnew.ts"
39+
const renameMatch = line.match(/^R\d*\s+(.+?)\s+(.+)$/);
40+
if (renameMatch) {
41+
const [, oldFile, newFile] = renameMatch;
42+
// Add both the removed old file and the new file
43+
changedFiles.push({ filepath: `${projectRoot}/${oldFile}`, status: 'removed' });
44+
changedFiles.push({ filepath: `${projectRoot}/${newFile}`, status: 'new' });
45+
continue;
46+
}
47+
3948
const match = line.match(/^([AMD])\s+(.+)$/);
4049
if (match) {
4150
const [, gitStatus, file] = match;
@@ -49,7 +58,7 @@ export const getChangedFiles = async (options: GitDiffOptions): Promise<ChangedF
4958
} else if (gitStatus === 'D') {
5059
status = 'removed';
5160
} else {
52-
// Skip unknown statuses (R=renamed, C=copied, etc.)
61+
// Skip unknown statuses (C=copied, etc.)
5362
continue;
5463
}
5564

0 commit comments

Comments
 (0)