git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Eric Sunshine <sunshine@sunshineco.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: Eric Sunshine via GitGitGadget <gitgitgadget@gmail.com>,
	git@vger.kernel.org,
	Preston Tunnell Wilson <prestontunnellwilson@gmail.com>,
	Jeff King <peff@peff.net>
Subject: Re: [PATCH] githooks: discuss Git operations in foreign repositories
Date: Mon, 9 Jan 2023 00:03:37 -0500	[thread overview]
Message-ID: <CAPig+cRMdJy9FdL1_rwuMKcA3F3p4g3RF+0mkh12pqN0aUoUiw@mail.gmail.com> (raw)
In-Reply-To: <xmqqwn5wuwvs.fsf@gitster.g>

On Sun, Jan 8, 2023 at 11:58 PM Junio C Hamano <gitster@pobox.com> wrote:
> "Eric Sunshine via GitGitGadget" <gitgitgadget@gmail.com> writes:
> > +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 local Git
> > +environment variables, such as `GIT_DIR`, `GIT_WORK_TREE`, etc., which could
> > +interfere with Git operations in the foreign repository since those variables
> > +will be referencing the local repository and working tree. For example:
> > +
> > +------------
> > +local_desc=$(git describe)
> > +foreign_desc=$(unset $(git rev-parse --local-env-vars); git -C ../foreign-repo describe)
> > +------------
>
> It is an excellent idea to add the above, but
>
>  * I think adding it one paragraph earlier may make it fit better.

That was my initial choice, as well, and is where I initially inserted
it, but moved it down a paragraph at the last moment. I'm happy to
move it back up again.

>  * The paragraph, after which the above gets inserted, can use a bit
>    of enhancement.
>
> That is, something like this?
>
>  repository. An exception are hooks triggered during a push ('pre-receive',
>  'update', 'post-receive', 'post-update', 'push-to-checkout') which are always
> -executed in $GIT_DIR.
> +executed in $GIT_DIR.  Environment variables like GIT_DIR and GIT_WORK_TREE
> +are exported so that the hook can easily learn which repository it is
> +working with.

Yes, good idea, although I might phrase it something like:

    Environment variables such as ... are exported so that Git
    commands run by the hook can correctly locate the repository.

  reply	other threads:[~2023-01-09  5:03 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-08  9:58 [PATCH] githooks: discuss Git operations in foreign repositories Eric Sunshine via GitGitGadget
2023-01-08 19:45 ` Preston Tunnell Wilson
2023-01-08 23:25   ` Eric Sunshine
2023-01-09  2:54     ` Preston Tunnell Wilson
2023-01-09 21:47       ` Eric Sunshine
2023-01-09  4:58 ` Junio C Hamano
2023-01-09  5:03   ` Eric Sunshine [this message]
2023-01-09  5:43     ` Junio C Hamano
2023-01-09 19:45 ` [PATCH v2] " Eric Sunshine via GitGitGadget
2023-01-09 20:12   ` Preston Tunnell Wilson
2023-01-11 19:01   ` Jeff King

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+cRMdJy9FdL1_rwuMKcA3F3p4g3RF+0mkh12pqN0aUoUiw@mail.gmail.com \
    --to=sunshine@sunshineco.com \
    --cc=git@vger.kernel.org \
    --cc=gitgitgadget@gmail.com \
    --cc=gitster@pobox.com \
    --cc=peff@peff.net \
    --cc=prestontunnellwilson@gmail.com \
    /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).