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

Re: git-apply does not work in a sub-directory of a Git repository

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Mar 24, 2016, 11:56 UTC
Message-ID
<1458820579-31621-1-git-send-email-pclouds@gmail.com>
In-Reply-To
<CACsJy8CTix-ZwN04MwYTB+JEtDCV27QVf7_0vWmhUSVCwU29Jg@mail.gmail.com>
+Brian who also had issues with git-apply.
On Thu, Mar 24, 2016 at 5:49 PM, Duy Nguyen <pclouds@gmail.com> wrote:
Show 11 quoted lines
> On Wed, Mar 23, 2016 at 11:55 PM, Junio C Hamano <gitster@pobox.com> wrote:
>> Junio C Hamano <gitster@pobox.com> writes:
>>
>>> See
>>>
>>>   http://thread.gmane.org/gmane.comp.version-control.git/288316/focus=288321
>>>
>>> I agree it is bad that it silently ignores the path outside the
>>> directory.  When run with --verbose, we should say "Skipped X that
>>> is outside the directory." or something like that, just like we
>>> issue notices when we applied with offset, etc.
Implemented in [04/04] apply: report patch skipping in verbose mode.
Show 27 quoted lines
>> Another thing we may want to do is to loosen (or redo) the logic
>> in builtin/apply.c::use_patch()
>>
>>         static int use_patch(struct patch *p)
>>         {
>>                 const char *pathname = p->new_name ? p->new_name : p->old_name;
>>                 int i;
>>
>>                 /* Paths outside are not touched regardless of "--include" */
>>                 if (0 < prefix_length) {
>>                         int pathlen = strlen(pathname);
>>                         if (pathlen <= prefix_length ||
>>                             memcmp(prefix, pathname, prefix_length))
>>                                 return 0;
>>                 }
>>
>> The include/exclude mechanism does use wildmatch() but does not use
>> the pathspec mechanism (it predates the pathspec machinery that was
>> made reusable in places like this).  We should be able to
>>
>>     $ cd d/e/e/p/d/i/r
>>     $ git apply --include=:/ ../../../../../../../patch
>>
>> to lift this limitation.  IOW, we can think of the use_patch() to
>> include only the paths in the subdirectory we are in by default, but
>> we can make it allow --include/--exclude command line option to
>> override that default.

I went with a new option instead of changing --include. Making it pathspec can still bite people. And pathspec is not exactly compatible with wildmatch either. This is in

  [03/04] apply: add --whole to apply git patch without prefix filtering
> git-apply.txt should
> probably mention about this because (at least to me) it sounds more
> naturally that if I give a patch, git-apply should apply the whole
> patch.
  [02/04] git-apply.txt: mention the behavior inside a subdir
> We probably should show a warning if everything file is filtered out
> too because silence usually means "good" from a typical unix command.
> It could be guarded with advice config key, and should only show if it
> looks like there are matching paths on worktree, but filtered out.

I'm holding this back. Too much heuristics. -- Duy

Previous: Duy NguyenNext: Nguyễn Thái Ngọc Duy
Message 7 of 18 in “git-apply does not work in a sub-directory of a Git repository”
  1. Mehul JainMar 22, 2016
  2. Stefan BellerMar 22, 2016
  3. Duy NguyenMar 23, 2016
  4. Junio C HamanoMar 23, 2016
  5. Junio C HamanoMar 23, 2016
  6. Duy NguyenMar 24, 2016
  7. Nguyễn Thái Ngọc DuyMar 24, 2016
  8. 1/4 git-apply.txt: remove a spaceNguyễn Thái Ngọc Duy, Mar 24, 2016
  9. 2/4 git-apply.txt: mention the behavior inside a subdirNguyễn Thái Ngọc Duy, Mar 24, 2016
  10. 3/4 apply: add --whole to apply git patch without prefix filteringNguyễn Thái Ngọc Duy, Mar 24, 2016
  11. 4/4 apply: report patch skipping in verbose modeNguyễn Thái Ngọc Duy, Mar 24, 2016
  12. Junio C HamanoMar 24, 2016
  13. Junio C HamanoMar 24, 2016
  14. Duy NguyenMar 30, 2016
  15. Junio C HamanoMar 30, 2016
  16. Duy NguyenMar 30, 2016
  17. Junio C HamanoMar 24, 2016
  18. Mehul JainMar 23, 2016

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.