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

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

From
Fede <fedux@lugmen.org.ar>
Date
Oct 22, 2010, 13:42 UTC
Message-ID
<4CC194DF.9040803@lugmen.org.ar>
In-Reply-To
<20101022053140.GB786@burratino>
Jonathan Nieder wrote:
Show 16 quoted lines
> Junio C Hamano wrote:
>> +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
> I had thought -p was only supposed to apply to traditional patches.
> Maybe a documentation update would avoid confusion?
>
> 	-p<n>
> 	   Remove <n> leading slashes from traditional diff paths.
> 	   The default is 1.

Currently, if the patch is mode-change only then the filename is taken from the line "diff --git ...". There is a function git_header_name() that extracts that name. This function could be a lot simpler and I'm working on that, but meanwhile I'd like to provide a quick fix.

Right now, if at least one of the filenames is double quoted then -p greater than 1 works correctly. The only failing case is when both names are unquoted and my patch fixes that.

This work with -p2:
diff --git "a/sub/file1" b/sub/file1
old mode 100644
new mode 100755

diff --git a/sub/file1 "b/sub/file1"
old mode 100644
new mode 100755

diff --git "a/sub/file1" "b/sub/file1"
old mode 100644
new mode 100755

This one doesn't:

diff --git a/sub/file1 b/sub/file1
old mode 100644
new mode 100755

My patch fixes the later case.

There is a similar issue with renames and I'm working on that.
Meanwhile, I'd like to know what do you think of that.

PS: Hamano's test  'apply (-p2) diff, mode change only' fails without my
patch and passes with it. I'll provide a new patch including the test.
Previous: Jonathan NiederNext: Jonathan Nieder
Message 4 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.