File tree Expand file tree Collapse file tree 3 files changed +40
-0
lines changed
Expand file tree Collapse file tree 3 files changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -316,6 +316,11 @@ static int diff_print_oid_range(
316316static int diff_delta_format_path (
317317 git_str * out , const char * prefix , const char * filename )
318318{
319+ if (!filename ) {
320+ /* don't prefix "/dev/null" */
321+ return git_str_puts (out , "/dev/null" );
322+ }
323+
319324 if (git_str_joinpath (out , prefix , filename ) < 0 )
320325 return -1 ;
321326
Original file line number Diff line number Diff line change @@ -431,6 +431,32 @@ void test_diff_parse__new_file_with_space(void)
431431 git_diff_free (diff );
432432}
433433
434+ void test_diff_parse__new_file_with_space_and_regenerate_patch (void )
435+ {
436+ const char * content = PATCH_ORIGINAL_NEW_FILE_WITH_SPACE ;
437+ git_diff * diff = NULL ;
438+ git_buf buf = GIT_BUF_INIT ;
439+
440+ cl_git_pass (git_diff_from_buffer (& diff , content , strlen (content )));
441+ cl_git_pass (git_diff_to_buf (& buf , diff , GIT_DIFF_FORMAT_PATCH ));
442+
443+ git_buf_dispose (& buf );
444+ git_diff_free (diff );
445+ }
446+
447+ void test_diff_parse__delete_file_with_space_and_regenerate_patch (void )
448+ {
449+ const char * content = PATCH_DELETE_FILE_WITH_SPACE ;
450+ git_diff * diff = NULL ;
451+ git_buf buf = GIT_BUF_INIT ;
452+
453+ cl_git_pass (git_diff_from_buffer (& diff , content , strlen (content )));
454+ cl_git_pass (git_diff_to_buf (& buf , diff , GIT_DIFF_FORMAT_PATCH ));
455+
456+ git_buf_dispose (& buf );
457+ git_diff_free (diff );
458+ }
459+
434460void test_diff_parse__crlf (void )
435461{
436462 const char * text = PATCH_CRLF ;
Original file line number Diff line number Diff line change 933933 "@@ -0,0 +1 @@\n" \
934934 "+a\n"
935935
936+ #define PATCH_DELETE_FILE_WITH_SPACE \
937+ "diff --git a/sp ace.txt b/sp ace.txt\n" \
938+ "deleted file mode 100644\n" \
939+ "index 789819226..000000000\n" \
940+ "--- a/sp ace.txt\n" \
941+ "+++ /dev/null\n" \
942+ "@@ -1 +0,0 @@\n" \
943+ "-a\n"
944+
936945#define PATCH_CRLF \
937946 "diff --git a/test-file b/test-file\r\n" \
938947 "new file mode 100644\r\n" \
You can’t perform that action at this time.
0 commit comments