From: Junio C Hamano Date: Wed, 26 Jun 2013 22:08:09 +0000 (-0700) Subject: Merge branch 'tr/maint-apply-non-git-patch-parsefix' X-Git-Tag: v1.8.4-rc0~119 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/ad76feb55eb7645661421e213796129efcbb7d56?hp=12dd2f69337e29254e743aa6fb3b04937f302209 Merge branch 'tr/maint-apply-non-git-patch-parsefix' Fix for the codepath to parse patches that add new files, generated by programs other than Git. THis is an old breakage in v1.7.11 and will need to be merged down to the maintanance tracks. * tr/maint-apply-non-git-patch-parsefix: apply: carefully strdup a possibly-NULL name --- diff --git a/builtin/apply.c b/builtin/apply.c index faf8e30883..0e9b631db6 100644 --- a/builtin/apply.c +++ b/builtin/apply.c @@ -906,7 +906,7 @@ static void parse_traditional_patch(const char *first, const char *second, struc patch->old_name = name; } else { patch->old_name = name; - patch->new_name = xstrdup(name); + patch->new_name = null_strdup(name); } } if (!name) diff --git a/t/t4111-apply-subdir.sh b/t/t4111-apply-subdir.sh index 7c398432ba..1618a6dbc7 100755 --- a/t/t4111-apply-subdir.sh +++ b/t/t4111-apply-subdir.sh @@ -86,6 +86,20 @@ test_expect_success 'apply --index from subdir of toplevel' ' test_cmp expected sub/dir/file ' +test_expect_success 'apply half-broken patch from subdir of toplevel' ' + ( + cd sub/dir && + test_must_fail git apply <<-EOF + --- sub/dir/file + +++ sub/dir/file + @@ -1,0 +1,0 @@ + --- file_in_root + +++ file_in_root + @@ -1,0 +1,0 @@ + EOF + ) +' + test_expect_success 'apply from .git dir' ' cp postimage expected && cp preimage .git/file &&