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

Re: [PATCH v2 2/2] ls-files: fix path used when recursing into submodules

From
Jacob Keller <jacob.keller@gmail.com>
Date
Apr 13, 2017, 18:34 UTC
Message-ID
<CA+P7+xpFVcj=Ssu6mjPs8km-GEsyhzbeVdb0ENH4bdzdqXOTsA@mail.gmail.com>
In-Reply-To
<CAGZ79kYi4X2cE8uF3cEwh5YndoSL6S2GUK-KYSYibqr+O2qG6g@mail.gmail.com>
On Thu, Apr 13, 2017 at 11:15 AM, Stefan Beller <sbeller@google.com> wrote:
Show 9 quoted lines
> On Thu, Apr 13, 2017 at 10:12 AM, Jacob Keller <jacob.e.keller@intel.com> wrote:
>> From: Jacob Keller <jacob.keller@gmail.com>
>>
>> Don't assume that the current working directory is the root of the
>> repository.
>
> 1)  Oh! This bug might be hidden in other commands, too.
> ($ git grep cp.dir -- submodule.c)
>
Almost certainly. I'm not sure how best to audit this.
Show 12 quoted lines
> 2) But why?
> Isn't that what most of setup.c is all about ? (discovery of the root of the
> repository, staying there, and invoking the correct subcommand with a prefix)
>
>> Correctly generate the path for the recursing child
>> processes by building it from the work_tree() root instead. Otherwise if
>> we run ls-files using --git-dir or --work-tree it will not work
>> correctly as it attempts to change directory into a potentially invalid
>> location.
>
> Oh, I see. In that case the setup doesn't cd into the worktree.
>
Yea we aren't in the worktree when we thought we were.
Show 16 quoted lines
>> Best case, it doesn't exist and we produce an error. Worst
>> case we cd into the wrong location and unknown behavior occurs.
>>
>> Add a new test which highlights this possibility.
>>
>> Signed-off-by: Jacob Keller <jacob.keller@gmail.com>
>> ---
>> I'm not sure that I'm convinced by this method of solving the problem as
>> I suspect it has some corner cases (what about when run inside a
>> subdirectory? It seems to work for me but I'm not sure...) Additionally,
>> it felt weird that there's no helper function for creating a toplevel
>> relative path.
>
> Do we want to run ls-files from the working tree or from the git dir?
> For the git dir there would be git_pathdup_submodule.
>

Well prior to this code we're assuming we are in the worktree. I wasn't actually certain if we should run from within the gitdir or the worktree. Probably we actually want to be in the gitdir so that we can work even if we're not checked out. Additionally, we probably need to protect this check with a "is_submodule_initialized" unless ls-files somehow ignores the submodule already in this case.. it didn't look like it at a glance.

Show 7 quoted lines
> We could introduce
>   const char *get_submodule_work_tree(const char *submodule_path);
> as a wrapper around
>   mkpathdup("%s/%s", get_git_work_tree(), ce->name);
>
> Code and test look fine in this patch,
>
Yea adding a helper function seems like a good thing.

Thanks, Jake

> Thanks,
> Stefan
Previous: Stefan BellerNext: Junio C Hamano
Message 8 of 33 in “ls-files: properly prepare submodule environment”
  1. ls-files: properly prepare submodule environmentJacob Keller, Apr 12, 2017
  2. Brandon WilliamsApr 12, 2017
  3. Jacob KellerApr 12, 2017
  4. 1/2 ls-files: fix recurse-submodules with nested submodulesJacob Keller, Apr 13, 2017
  5. 2/2 ls-files: fix path used when recursing into submodulesJacob Keller, Apr 13, 2017
  6. Brandon WilliamsApr 13, 2017
  7. Stefan BellerApr 13, 2017
  8. Jacob KellerApr 13, 2017
  9. Junio C HamanoApr 18, 2017
  10. Jacob KellerApr 18, 2017
  11. Stefan BellerApr 18, 2017
  12. Brandon WilliamsApr 13, 2017
  13. Jacob KellerApr 13, 2017
  14. Stefan BellerApr 13, 2017
  15. Brandon WilliamsApr 13, 2017
  16. 3/2 ls-files: only recurse on active submodulesBrandon Williams, Apr 13, 2017
  17. Stefan BellerApr 13, 2017
  18. Jacob KellerApr 13, 2017
  19. Stefan BellerApr 13, 2017
  20. Jacob KellerApr 13, 2017
  21. Jacob KellerApr 14, 2017
  22. Stefan BellerApr 14, 2017
  23. Jacob KellerApr 14, 2017
  24. Junio C HamanoApr 19, 2017
  25. paul@myitcv.ioMay 12, 2017
  26. Brandon WilliamsMay 12, 2017
  27. Paul JollyMay 12, 2017
  28. Brandon WilliamsMay 12, 2017
  29. Paul JollyAug 1, 2017
  30. Brandon WilliamsAug 1, 2017
  31. Paul JollyAug 1, 2017
  32. Brandon WilliamsAug 1, 2017
  33. Junio C HamanoAug 1, 2017

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.