@@ -46,25 +46,67 @@ export const build_commit_message_prompt = (
4646 let final_diff_content = full_file_diff
4747
4848 let file_path : string | undefined
49+ let is_deleted = false
4950
5051 if ( new_path && new_path != '/dev/null' ) {
5152 file_path = new_path
5253 } else if ( old_path && old_path != '/dev/null' ) {
5354 file_path = old_path
55+ is_deleted = true
5456 // Shorten diff of a deleted file
5557 const split_diff = full_file_diff . split ( '+++ /dev/null' )
5658 final_diff_content = split_diff [ 0 ] + '+++ /dev/null'
59+ } else {
60+ // Fallback: try to identify file from diff header (e.g. binary files)
61+ const diff_header = lines [ 0 ]
62+ const matched_file = affected_files_data . find ( ( f ) => {
63+ const normalized_path = f . relative_path . replace ( / \\ / g, '/' )
64+ return (
65+ diff_header . includes ( `/${ normalized_path } ` ) ||
66+ diff_header . endsWith ( `/${ normalized_path } ` )
67+ )
68+ } )
69+
70+ if ( matched_file ) {
71+ file_path = matched_file . relative_path
72+ }
5773 }
5874
5975 if ( file_path ) {
6076 const file_data = affected_files_data . find (
6177 ( f ) => f . relative_path == file_path
6278 )
63- changes_content += `\n### File: \`${ file_path } \`\n\n`
79+
80+ let heading = 'Updated file'
81+ let display_path = `\`${ file_path } \``
82+
83+ if ( file_data ) {
84+ if ( file_data . status === 2 ) {
85+ heading = 'New file'
86+ } else if ( file_data . status === 3 ) {
87+ heading = 'Deleted file'
88+ is_deleted = true
89+ } else if ( file_data . status === 4 ) {
90+ heading = 'Renamed file'
91+ if ( file_data . original_relative_path ) {
92+ display_path = `\`${ file_data . original_relative_path } \` (old) \`${ file_path } \` (new)`
93+ }
94+ }
95+ } else {
96+ if ( is_deleted ) {
97+ heading = 'Deleted file'
98+ } else if ( ! old_path && new_path ) {
99+ heading = 'New file'
100+ }
101+ }
102+
103+ changes_content += `\n### ${ heading } : ${ display_path } \n\n`
64104 if ( file_data ) {
65105 changes_content += `The original state of the file for reference:\n\n<![CDATA[\n${ file_data . content } \n]]>\n\n`
66106 }
67- changes_content += `**New changes:**\n\n<![CDATA[\n${ final_diff_content } \n]]>\n`
107+ if ( ! is_deleted ) {
108+ changes_content += `**New changes:**\n\n<![CDATA[\n${ final_diff_content } \n]]>\n`
109+ }
68110 }
69111 }
70112
0 commit comments