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

Re: [PATCH] Teach 'git apply' to look at $GIT_DIR/config

From
Junio C Hamano <junkio@cox.net>
Date
Feb 19, 2007, 23:57 UTC
Message-ID
<7vwt2d4s6c.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<Pine.LNX.4.64.0702191527320.20368@woody.linux-foundation.org>
Linus Torvalds <torvalds@linux-foundation.org> writes:
Show 12 quoted lines
> On Mon, 19 Feb 2007, Junio C Hamano wrote:
>> > ...
>> > git-apply has much saner defaults (it defaults to something pretty safe, 
>> > and you can then make it less safe if the patch doesn't apply).
>> 
>> All true.
>
> One thing I forgot to mention: "git apply" doesn't apply *anything* unless 
> everything applies cleanly. In contrast, when "patch" fails in the middle, 
> it will have done part of the job, and then leaves a reject file. I much 
> prefer the "everything or nothing" approach of git-apply (again, obviously 
> with "--reject" you can make it work the bad old way too).
Yup.
Show 8 quoted lines
> I _think_ that the right answer is to (a) yes, make it be consistent, but 
> (b) _not_ make it be the way we do "--index" now.
>
> Right now, when we see "--index", we do the "setup_git_directory()" and 
> the git_config() stuff - which is (I think) something we should always do, 
> but then we do *not* prefix the patch itself with the prefix we got. And I 
> think that's wrong. I think we should always do the "-p1" behaviour from 
> where we started.

Hmm. I am puzzled. Are you suggesting to change behaviour of "git apply" with --index?

git generated patch, or patches on the kernel list that are not generated with git are always relative to the top-level, so I think the current --index behaviour makes tons of sense.

Show 6 quoted lines
> Then, if somebody is in a sub/directory/, maybe they need to add a "-p3" 
> to indicate that, but at least that's better than having a patch that just 
> says "Makefile", and applying the patch to the *wrong* "Makefile" 
> (top-level one, rather than the one you were in).
>
> Hmm?

I think it boils down to this question: when you have a patch on hand that you are considering to apply to your tree, if the patch talks about just "Makefile" (e.g. it says "a/Makefile b/Makefile") which Makefile is more likely to be what the patch is talking about -- the toplevel one or the one in the subdirectory you happen to be in?

Both (1) diff generated by git are always relative to top, and (2) the BCP on the kernel list (and I suspect many other projects are run this way as well) is to have diff relative to the toplevel, suggests that "a/Makefile b/Makefile" patch is much more likely to be about the top-level Makefile no matter where you happen to be.

Although the fact you *are* in the subdirectory when you are considering that patch makes it a bit more plausible than otherwise that the patch may be about sub/directory/Makefile, I do not think that is strong enough hint to make it more plausible to apply to the sub/directory one than to the toplevel.

If the patch were what you made by running "GNU diff" inside a corresponding subdirectory of another repository (perhaps you wanted to feed uncommitted changes from there to this repository), then you can always use "GNU patch" to apply. If you made such a one-shot patch using git-diff, it will tell you the correct directory to apply to, so...

Previous: Linus TorvaldsNext: Linus Torvalds
Message 10 of 49 in “Teach core.autocrlf to 'git apply'”
  1. Teach core.autocrlf to 'git apply'Junio C Hamano, Feb 17, 2007
  2. Teach 'git apply' to look at $GIT_DIR/configJunio C Hamano, Feb 17, 2007
  3. Jeff KingFeb 17, 2007
  4. Junio C HamanoFeb 17, 2007
  5. Jeff KingFeb 17, 2007
  6. Linus TorvaldsFeb 19, 2007
  7. Shawn O. PearceFeb 19, 2007
  8. Junio C HamanoFeb 19, 2007
  9. Linus TorvaldsFeb 19, 2007
  10. Junio C HamanoFeb 19, 2007
  11. Linus TorvaldsFeb 20, 2007
  12. Junio C HamanoFeb 20, 2007
  13. Johannes SchindelinFeb 20, 2007
  14. Junio C HamanoFeb 20, 2007
  15. Johannes SchindelinFeb 20, 2007
  16. git-apply: require -p<n> when working in a subdirectory.Junio C Hamano, Feb 20, 2007
  17. apply: fix memory leak in prefix_one()Johannes Schindelin, Feb 20, 2007
  18. Junio C HamanoFeb 20, 2007
  19. Johannes SchindelinFeb 20, 2007
  20. git-apply: do not lose cwd when run from a subdirectory.Junio C Hamano, Feb 20, 2007
  21. Junio C HamanoFeb 20, 2007
  22. Linus TorvaldsFeb 20, 2007
  23. Daniel BarkalowFeb 21, 2007
  24. Junio C HamanoFeb 21, 2007
  25. Daniel BarkalowFeb 21, 2007
  26. Linus TorvaldsFeb 21, 2007
  27. Junio C HamanoFeb 21, 2007
  28. git-apply: notice "diff --git" patch againJunio C Hamano, Feb 21, 2007
  29. git-apply: guess correct -p<n> value for non-git patches.Junio C Hamano, Feb 22, 2007
  30. Johannes SchindelinFeb 20, 2007
  31. Simon 'corecode' SchubertFeb 20, 2007
  32. Johannes SchindelinFeb 18, 2007
  33. Junio C HamanoFeb 18, 2007
  34. Johannes SchindelinFeb 18, 2007
  35. Junio C HamanoFeb 18, 2007
  36. Johannes SchindelinFeb 18, 2007
  37. Junio C HamanoFeb 18, 2007
  38. Johannes SchindelinFeb 18, 2007
  39. Junio C HamanoFeb 18, 2007
  40. Johannes SchindelinFeb 18, 2007
  41. Jakub NarebskiFeb 18, 2007
  42. Johannes SchindelinFeb 18, 2007
  43. Junio C HamanoFeb 18, 2007
  44. Johannes SchindelinFeb 18, 2007
  45. Junio C HamanoFeb 18, 2007
  46. Johannes SchindelinFeb 18, 2007
  47. Junio C HamanoFeb 18, 2007
  48. Johannes SchindelinFeb 18, 2007
  49. Junio C HamanoFeb 18, 2007

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.