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

Re: Running 'git worktree add' in 'pre-commit' hook

From
Eric Sunshine <sunshine@sunshineco.com>
Date
May 16, 2019, 12:14 UTC
Message-ID
<CAPig+cTCdBkru-6tJVeYxQSaosv7pb8R5ge_aedzi5C7w39mQg@mail.gmail.com>
In-Reply-To
<CACsJy8BXxVggL7CWA5Q0d7U4B+encfZ85NshxLJ=VvHhf_LUYg@mail.gmail.com>
On Thu, May 16, 2019 at 7:42 AM Duy Nguyen <pclouds@gmail.com> wrote:
Show 18 quoted lines
> On Thu, May 16, 2019 at 6:33 PM Eric Sunshine <sunshine@sunshineco.com> wrote:
> > You run afoul of it in other situations, as well. For instance, say
> > you have your index file in a non-standard location:
> >
> >     $ export GIT_INDEX_FILE=../storage/index
> >     $ git worktree add --detach other
> >     Preparing worktree (detached HEAD c9156d2)
> >     fatal: Unable to create '/.../foo/other/../storage/index.lock': No
> > such file or directory
> >     $
> >
> Oh if it's relative $GIT_INDEX_FILE then I think its our environment.c
> code that does not work so well when we chdir() away. I vaguely recall
> something about this when discussing Jeff's chdir-notify series. But
> it turns out that's about chdir() in run-command.c [1]. But the idea
> is still the same, all variables are supposed to be relative to $CWD.
> Whenever you move $CWD you should reparent all of them, including
> $GIT_INDEX_FILE.

builtin/worktree.c:add_worktree() is already assigning new-worktree-specific values for GIT_DIR and GIT_WORK_TREE, so for the specific example I showed above, the correct fix would be for add_worktree() to remove GIT_INDEX_FILE from the environment before invoking other Git commands, correct?

Previous: Duy NguyenNext: Duy Nguyen
Message 10 of 17 in “Running 'git worktree add' in 'pre-commit' hook”
  1. Cosmin PolifronieMay 14, 2019
  2. Bryan TurnerMay 15, 2019
  3. Cosmin PolifronieMay 15, 2019
  4. Duy NguyenMay 16, 2019
  5. Eric SunshineMay 16, 2019
  6. Eric SunshineMay 16, 2019
  7. Duy NguyenMay 16, 2019
  8. Eric SunshineMay 16, 2019
  9. Duy NguyenMay 16, 2019
  10. Eric SunshineMay 16, 2019
  11. Duy NguyenMay 16, 2019
  12. Eric SunshineMay 16, 2019
  13. Jeff KingMay 16, 2019
  14. Eric SunshineMay 16, 2019
  15. Jeff KingMay 17, 2019
  16. Eric SunshineMay 17, 2019
  17. Jeff KingMay 17, 2019

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.