Skip to content

Commit 8289a36

Browse files
committed
Merge branch 'jc/apply-parse-diff-git-header-names-fix'
"git apply" failed to extract the filename the patch applied to, when the change was about an empty file created in or deleted from a directory whose name ends with a SP, which has been corrected. * jc/apply-parse-diff-git-header-names-fix: t4126: fix "funny directory name" test on Windows (again) t4126: make sure a directory with SP at the end is usable apply: parse names out of "diff --git" more carefully
2 parents 19981da + 776ffd1 commit 8289a36

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

apply.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1292,8 +1292,15 @@ static char *git_header_name(int p_value,
12921292
return NULL; /* no postimage name */
12931293
second = skip_tree_prefix(p_value, name + len + 1,
12941294
line_len - (len + 1));
1295+
/*
1296+
* If we are at the SP at the end of a directory,
1297+
* skip_tree_prefix() may return NULL as that makes
1298+
* it appears as if we have an absolute path.
1299+
* Keep going to find another SP.
1300+
*/
12951301
if (!second)
1296-
return NULL;
1302+
continue;
1303+
12971304
/*
12981305
* Does len bytes starting at "name" and "second"
12991306
* (that are separated by one HT or SP we just

t/t4126-apply-empty.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,28 @@ test_expect_success 'apply --index create' '
6666
git diff --exit-code
6767
'
6868

69+
test_expect_success !MINGW 'apply with no-contents and a funny pathname' '
70+
test_when_finished "rm -fr \"funny \"; git reset --hard" &&
71+
72+
mkdir "funny " &&
73+
>"funny /empty" &&
74+
git add "funny /empty" &&
75+
git diff HEAD -- "funny /" >sample.patch &&
76+
git diff -R HEAD -- "funny /" >elpmas.patch &&
77+
78+
git reset --hard &&
79+
80+
git apply --stat --check --apply sample.patch &&
81+
test_must_be_empty "funny /empty" &&
82+
83+
git apply --stat --check --apply elpmas.patch &&
84+
test_path_is_missing "funny /empty" &&
85+
86+
git apply -R --stat --check --apply elpmas.patch &&
87+
test_must_be_empty "funny /empty" &&
88+
89+
git apply -R --stat --check --apply sample.patch &&
90+
test_path_is_missing "funny /empty"
91+
'
92+
6993
test_done

0 commit comments

Comments
 (0)