git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Eric Sunshine <sunshine@sunshineco.com>
To: phillip.wood@dunelm.org.uk
Cc: Antoine Bolvy <antoine.bolvy@gmail.com>, git@vger.kernel.org
Subject: Re: [bug report] git diff --relative not doing well with worktree in hooks
Date: Mon, 3 Jun 2024 17:59:34 -0400	[thread overview]
Message-ID: <CAPig+cSzY1YO6KByb3fG0P1jWHbEu_a3s_7QBieDoD6un-MJXQ@mail.gmail.com> (raw)
In-Reply-To: <e0ea930f-3d43-49de-b2e7-c057d95fd7cc@gmail.com>

On Mon, Jun 3, 2024 at 5:30 AM Phillip Wood <phillip.wood123@gmail.com> 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.

      reply	other threads:[~2024-06-03 21:59 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-31 11:38 [bug report] git diff --relative not doing well with worktree in hooks Antoine Bolvy
2024-05-31 21:42 ` Eric Sunshine
2024-06-03  8:38   ` Antoine Bolvy
2024-06-03  9:29   ` Phillip Wood
2024-06-03 21:59     ` Eric Sunshine [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAPig+cSzY1YO6KByb3fG0P1jWHbEu_a3s_7QBieDoD6un-MJXQ@mail.gmail.com \
    --to=sunshine@sunshineco.com \
    --cc=antoine.bolvy@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=phillip.wood@dunelm.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).