diff --git a/builtin/apply.c b/builtin/apply.c index 30eefc3c7b390800e9452a06da18208d2fef4f11..3979f8bf3de8bc82b1d546f063728094d6ac974b 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 7c398432bad761c1b38c6d15548bed0c389221fd..1618a6dbc7c718677cf669b5f6fc96f2682992fb 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 &&