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:05 UTC
Message-ID
<CAPig+cTkiBhZ70SC=xXQP_RfkDagCRLFxpcZYLidQrz9_v-_Bg@mail.gmail.com>
In-Reply-To
<CACsJy8AgzSZ_Gj9JW2yTdgkGQNCMMLy8i+pH_+A93+V95anQWQ@mail.gmail.com>
On Thu, May 16, 2019 at 7:45 AM Duy Nguyen <pclouds@gmail.com> wrote:
Show 13 quoted lines
> On Thu, May 16, 2019 at 6:39 PM Eric Sunshine <sunshine@sunshineco.com> wrote:
> > Thinking more clearly on it, a better fix might be for git-worktree to
> > deal with this itself, converting such a path to absolute before
> > cd'ing to the new worktree directory (or something -- I don't have the
> > code in front of me to provide a more concrete suggestion).
>
> Our mails crossed. But yeah it's basically the same thing.
>
> Although I still doubt a good $GIT_INDEX_FILE would fix the problem.
> Even if you manage to create a new worktree, when you cd there and
> start using it, this $GIT_INDEX_FILE will still mess things up (unless
> you do mean to ignore the worktree's index file and update one
> provided by pre-commit hook).

I was forgetting that each worktree has its own index. Your advice that his hook should sanitize GIT_INDEX_FILE (and possibly other GIT_* variables) is probably the only sane approach. I don't think it's something we can handle in some automated fashion since we don't know whence GIT_INDEX_FILE arose.

Previous: Duy NguyenNext: Duy Nguyen
Message 8 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.