Re: [bug report] git diff --relative not doing well with worktree in hooks

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Jun 3, 2024 at 5:30 AM Phillip Wood <phillip.wood123@xxxxxxxxx> wrote:
> On 31/05/2024 22:42, Eric Sunshine wrote:
> > 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?

It's been a while since I looked at the code, but my recollection is
that the hook-running machinery unconditionally sets the environment
variables whenever the directory in which the hook is being run is not
the "main" worktree. This is the case whether his hook runs at the
root of the worktree or in a subdirectory.

It's quite possible that this behavior is entirely accidental since
the hook-running machinery existed long before multiple-worktree
support was added, and it may be that the hook-running machinery
simply wasn't revisited when worktree support was implemented. So,
perhaps a "satisfactory resolution" is to "fix" the hook-running
machinery itself to avoid setting those environment variables
unnecessarily.





[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux