Skip to content

Commit 4aa6aaf

Browse files
committed
Remove unnecessary metadata lines from git diff outputs
- consider this snippet: [Pasted text], should not place these two lines: [Pasted text] └── apps └── editor └── src └── views └── prompt └── backend └── utils └── symbols ├── git │ └── replace-git-symbols.ts └── replace-symbols.ts
1 parent 93a9b02 commit 4aa6aaf

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

‎apps/editor/src/views/prompt/backend/utils/symbols/git/replace-git-symbols.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,20 @@ const patch_diff_paths = (
4242
return lines.join('\n')
4343
}
4444

45+
const clean_git_diff = (diff_text: string): string => {
46+
return diff_text
47+
.split('\n')
48+
.filter(
49+
(line) =>
50+
!line.startsWith('index ') &&
51+
!line.startsWith('new file mode ') &&
52+
!line.startsWith('deleted file mode ') &&
53+
!line.startsWith('old mode ') &&
54+
!line.startsWith('new mode ')
55+
)
56+
.join('\n')
57+
}
58+
4559
const build_changes_markdown = (
4660
diff: string,
4761
cwd: string,
@@ -119,6 +133,8 @@ const build_changes_markdown = (
119133
)
120134
}
121135

136+
full_file_diff = clean_git_diff(full_file_diff)
137+
122138
changes_content += `\`\`\`\n${full_file_diff}\n\`\`\`\n\n`
123139
if (file_content) {
124140
changes_content += `\`\`\`\n${file_content}\n\`\`\`\n\n`
@@ -400,6 +416,8 @@ const build_commit_changes_markdown = (
400416
)
401417
}
402418

419+
full_file_diff = clean_git_diff(full_file_diff)
420+
403421
changes_content += `\`\`\`\n${full_file_diff}\n\`\`\`\n\n`
404422
if (file_content) {
405423
changes_content += `\`\`\`\n${file_content}\n\`\`\`\n\n`

0 commit comments

Comments
 (0)