Re: [bug report] git diff --relative not doing well with worktree in hooks
- From
- Phillip Wood <phillip.wood123@gmail.com>
- Date
- Jun 3, 2024, 09:29 UTC
- Message-ID
- <e0ea930f-3d43-49de-b2e7-c057d95fd7cc@gmail.com>
- In-Reply-To
- <CAPig+cT1pTkKd1A0o_qjP+Oyx+zyCevV8EAg5Ub9guAyd3UjgA@mail.gmail.com>
Hi Eric
On 31/05/2024 22:42, Eric Sunshine wrote:
Show 17 quoted lines
> On Fri, May 31, 2024 at 7:38 AM Antoine Bolvy <antoine.bolvy@gmail.com> wrote: >> The path is no longer show relative. This causes issues with more complex >> scripts. > > I'm not sure there's a satisfactory resolution here. Your hook is > running afoul of the environment variables Git sets up when the hook > is run outside of the "main" worktree. > [...] > The relevant portion from the "githooks" manual page is: > > Environment variables, such as GIT_DIR, GIT_WORK_TREE, etc., are > exported so that Git commands run by the hook can correctly locate > the repository. If your hook needs to invoke Git commands in a > foreign repository or in a different working tree of the same > repository, then it should clear these environment variables so > they do not interfere with Git operations at the foreign > location. For example:
Maybe I'm missing something but in Antonine's example the hook is being run in the same worktree as the "git commit" - we're changing into a subdirectory of the worktree, not changing to a different worktree so why doesn't it work?
Best Wishes
Phillip