summaryrefslogtreecommitdiff
path: root/t/t4128-apply-root.sh
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2009-11-25 10:56:54 (GMT)
committerJunio C Hamano <gitster@pobox.com>2009-11-27 03:02:24 (GMT)
commitec7fc0b1a46c5a352532ea3f29c5663752fd8ac6 (patch)
tree540136a940dde0e0293f047f6f2ed2a26a21b805 /t/t4128-apply-root.sh
parent4f366275189c06ec26c01ee5ace2f3831b2aa46a (diff)
downloadgit-ec7fc0b1a46c5a352532ea3f29c5663752fd8ac6.zip
git-ec7fc0b1a46c5a352532ea3f29c5663752fd8ac6.tar.gz
git-ec7fc0b1a46c5a352532ea3f29c5663752fd8ac6.tar.bz2
builtin-apply.c: pay attention to -p<n> when determining the name
The patch structure has def_name component that is used to validate the sanity of a "diff --git" patch by checking pathnames that appear on the patch header lines for consistency. The git_header_name() function is used to compute this out of "diff --git a/... b/..." line, but the code always stripped one level of prefix (i.e. "a/" and "b/"), without paying attention to -p<n> option. Code in find_name() function that parses other lines in the patch header (e.g. "--- a/..." and "+++ b/..." lines) however did strip the correct number of leading paths prefixes, and the sanity check between these computed values failed. Teach git_header_name() to honor -p<n> option like find_name() function does. Found and reported by Steven J. Murdoch who also wrote tests. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't/t4128-apply-root.sh')
-rwxr-xr-xt/t4128-apply-root.sh17
1 files changed, 17 insertions, 0 deletions
diff --git a/t/t4128-apply-root.sh b/t/t4128-apply-root.sh
index 8f6aea4..6cc741a 100755
--- a/t/t4128-apply-root.sh
+++ b/t/t4128-apply-root.sh
@@ -58,6 +58,23 @@ test_expect_success 'apply --directory (new file)' '
'
cat > patch << EOF
+diff --git a/c/newfile2 b/c/newfile2
+new file mode 100644
+index 0000000..d95f3ad
+--- /dev/null
++++ b/c/newfile2
+@@ -0,0 +1 @@
++content
+EOF
+
+test_expect_success 'apply --directory -p (new file)' '
+ git reset --hard initial &&
+ git apply -p2 --directory=some/sub/dir/ --index patch &&
+ test content = $(git show :some/sub/dir/newfile2) &&
+ test content = $(cat some/sub/dir/newfile2)
+'
+
+cat > patch << EOF
diff --git a/delfile b/delfile
deleted file mode 100644
index d95f3ad..0000000