aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2024-04-09 14:31:43 -0700
committerJunio C Hamano <gitster@pobox.com>2024-04-09 14:31:43 -0700
commit8289a36f8725d33f5bdff2a5aeaa0b0369ad8ff8 (patch)
treedbbd3962329f6d3a31e6064019e3819051cba5cc
parent19981daefd7c147444462739375462b49412ce33 (diff)
parent776ffd1a303afa8cf581d62e9d0478d112fecdd2 (diff)
downloadgit-8289a36f8725d33f5bdff2a5aeaa0b0369ad8ff8.tar.gz
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
-rw-r--r--apply.c9
-rwxr-xr-xt/t4126-apply-empty.sh24
2 files changed, 32 insertions, 1 deletions
diff --git a/apply.c b/apply.c
index 432837a674..e311013bc4 100644
--- a/apply.c
+++ b/apply.c
@@ -1292,8 +1292,15 @@ static char *git_header_name(int p_value,
return NULL; /* no postimage name */
second = skip_tree_prefix(p_value, name + len + 1,
line_len - (len + 1));
+ /*
+ * If we are at the SP at the end of a directory,
+ * skip_tree_prefix() may return NULL as that makes
+ * it appears as if we have an absolute path.
+ * Keep going to find another SP.
+ */
if (!second)
- return NULL;
+ continue;
+
/*
* Does len bytes starting at "name" and "second"
* (that are separated by one HT or SP we just
diff --git a/t/t4126-apply-empty.sh b/t/t4126-apply-empty.sh
index ece9fae207..56210b5609 100755
--- a/t/t4126-apply-empty.sh
+++ b/t/t4126-apply-empty.sh
@@ -66,4 +66,28 @@ test_expect_success 'apply --index create' '
git diff --exit-code
'
+test_expect_success !MINGW 'apply with no-contents and a funny pathname' '
+ test_when_finished "rm -fr \"funny \"; git reset --hard" &&
+
+ mkdir "funny " &&
+ >"funny /empty" &&
+ git add "funny /empty" &&
+ git diff HEAD -- "funny /" >sample.patch &&
+ git diff -R HEAD -- "funny /" >elpmas.patch &&
+
+ git reset --hard &&
+
+ git apply --stat --check --apply sample.patch &&
+ test_must_be_empty "funny /empty" &&
+
+ git apply --stat --check --apply elpmas.patch &&
+ test_path_is_missing "funny /empty" &&
+
+ git apply -R --stat --check --apply elpmas.patch &&
+ test_must_be_empty "funny /empty" &&
+
+ git apply -R --stat --check --apply sample.patch &&
+ test_path_is_missing "funny /empty"
+'
+
test_done