@@ -31,6 +31,7 @@ export const build_commit_message_prompt = async (
3131 let final_diff_content = full_file_diff
3232 let file_path : string | undefined
3333 let is_deleted = false
34+ const is_binary = lines . some ( ( l ) => l . startsWith ( 'Binary files ' ) )
3435
3536 if ( new_path && new_path != '/dev/null' ) {
3637 file_path = new_path
@@ -75,11 +76,19 @@ export const build_commit_message_prompt = async (
7576 }
7677 }
7778
78- const hunk_start_index = final_diff_content . indexOf ( '\n@@ ' )
79- if ( hunk_start_index != - 1 ) {
80- final_diff_content = final_diff_content . substring ( hunk_start_index + 1 )
81- } else if ( ! final_diff_content . startsWith ( '@@ ' ) ) {
82- final_diff_content = ''
79+ if ( is_binary ) {
80+ if ( status == 'created' ) final_diff_content = 'Binary file created'
81+ else if ( status == 'deleted' ) final_diff_content = 'Binary file deleted'
82+ else final_diff_content = 'Binary file modified'
83+ } else {
84+ const hunk_start_index = final_diff_content . indexOf ( '\n@@ ' )
85+ if ( hunk_start_index != - 1 ) {
86+ final_diff_content = final_diff_content . substring (
87+ hunk_start_index + 1
88+ )
89+ } else if ( ! final_diff_content . startsWith ( '@@ ' ) ) {
90+ final_diff_content = ''
91+ }
8392 }
8493
8594 changes_content += `<file path="${ file_path } " status="${ status } "`
@@ -89,17 +98,19 @@ export const build_commit_message_prompt = async (
8998 changes_content += '>\n'
9099 changes_content += `<![CDATA[\n${ final_diff_content . trimEnd ( ) } \n]]>\n`
91100
92- if ( ! is_deleted && file_path ) {
101+ if ( ! is_deleted && file_path && ! is_binary ) {
93102 try {
94103 let full_content = ''
95104 try {
96105 full_content = await repository . show ( '' , file_path )
97106 } catch ( e ) {
98107 const uri = vscode . Uri . joinPath ( repository . rootUri , file_path )
99108 const content = await vscode . workspace . fs . readFile ( uri )
100- full_content = Buffer . from ( content ) . toString ( 'utf8' )
109+ if ( ! content . includes ( 0 ) ) {
110+ full_content = Buffer . from ( content ) . toString ( 'utf8' )
111+ }
101112 }
102- if ( full_content ) {
113+ if ( full_content && ! full_content . includes ( '\0' ) ) {
103114 const full_content_tokens = Math . ceil ( full_content . length / 4 )
104115 if ( full_content_tokens <= MAX_FILE_TOKENS_FOR_COMMIT_MESSAGE ) {
105116 changes_content += `<![CDATA[\n${ full_content . trimEnd ( ) } \n]]>\n`
0 commit comments