git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] Fix git-apply with -p greater than 1

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 22, 2010, 05:01 UTC
Message-ID
<7viq0urfbz.fsf@alter.siamese.dyndns.org>
In-Reply-To
<1287699122-26702-1-git-send-email-fedux@lugmen.org.ar>
Federico Cuello <fedux@lugmen.org.ar> writes:
Show 6 quoted lines
> Fix the case when the patch is a rename or mode-change only
> and -p is used with a value greater than one.
> The git_header_name function did not remove more than one path
> component.
>
> Signed-off-by: Federico Cuello <fedux@lugmen.org.ar>
Thanks.

It is customary to protect your fix with additional test script so that you do not have to be constantly monitoring the mailing list traffic to make sure somebody else will not break your changes.

Perhaps something like this? Note that I didn't run the test myself, though (for that matter, I haven't applied your patch to see if it compiles, yet).

 t/t4120-apply-popt.sh |   26 ++++++++++++++++++++++++++
 1 files changed, 26 insertions(+), 0 deletions(-)
diff --git a/t/t4120-apply-popt.sh b/t/t4120-apply-popt.sh
index 2b2d00b..579c9e6 100755
--- a/t/t4120-apply-popt.sh
+++ b/t/t4120-apply-popt.sh
@@ -56,4 +56,30 @@ test_expect_success 'apply with too large -p and fancy filename' '
 	grep "removing 3 leading" err
 '
 
+test_expect_success 'apply (-p2) diff, mode change only' '
+	cat >patch.chmod <<-\EOF &&
+	diff --git a/sub/file1 b/sub/file1
+	old mode 100644
+	new mode 100755
+	EOF
+	chmod 644 file1 &&
+	git apply -p2 patch.chmod &&
+	test -x file1
+'
+
+test_expect_success 'apply (-p2) diff, rename' '
+	cat >patch.rename <<-\EOF &&
+	diff --git a/sub/file1 b/sub/file2
+	similarity index 100%
+	rename from sub/file1
+	rename to sub/file2
+	EOF
+	echo A >expected &&
+
+	cp file1.saved file1 &&
+	rm -f file2 &&
+	git apply -p2 patch.rename &&
+	test_cmp expected file2
+'
+
 test_done
Previous: Federico CuelloNext: Jonathan Nieder
Message 2 of 9 in “Fix git-apply with -p greater than 1”
  1. Fix git-apply with -p greater than 1Federico Cuello, Oct 21, 2010
  2. Junio C HamanoOct 22, 2010
  3. Jonathan NiederOct 22, 2010
  4. FedeOct 22, 2010
  5. Jonathan NiederOct 22, 2010
  6. Junio C HamanoOct 22, 2010
  7. Federico CuelloOct 22, 2010
  8. Fix git-apply with -p greater than 1Federico Cuello, Oct 25, 2010
  9. Junio C HamanoOct 22, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.