git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: John Cai <johncai86@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: John Cai via GitGitGadget <gitgitgadget@gmail.com>,
	git@vger.kernel.org, Emily Shaffer <emilyshaffer@google.com>
Subject: Re: [PATCH] hook: provide GIT_HOOK for all hooks
Date: Sat, 28 May 2022 00:26:40 -0400	[thread overview]
Message-ID: <E0D2A9A0-FB95-47ED-B672-93AAFE798CD9@gmail.com> (raw)
In-Reply-To: <xmqqzgj21xm4.fsf@gitster.g>

Hi Junio

On 27 May 2022, at 17:20, Junio C Hamano wrote:

> "John Cai via GitGitGadget" <gitgitgadget@gmail.com> writes:
>
>> From: John Cai <johncai86@gmail.com>
>>
>> In order to allow users to use one executable for multiple hooks,
>> provide a GIT_HOOK variable that is set to the hook event that triggered
>> it.
>
> I agree it would be handy to give hooks to play multiple roles by
> dispatching on its name, just like our "git" potty can dispatch
> built-ins when called "git-foo".
>
> I do not think GIT_HOOK is a good name for the environment variable
> that is used for that purpose, though.  It is easily mistaken as if
> end users can set GIT_HOOK environment themselves to point at a
> program and cause "git" to run it whenever it may want to run any
> hook, for example.  IOW, the name is overly broad.

Yes, I see what you mean. It would be good to pick a more specific variable.

>
> How about calling it with a name with "HOOK" and "NAME" in it?

For lack of imagination, would GIT_HOOK_NAME still be too broad?

>
>> diff --git a/t/t1800-hook.sh b/t/t1800-hook.sh
>> index 26ed5e11bc8..a22c1a82a5e 100755
>> --- a/t/t1800-hook.sh
>> +++ b/t/t1800-hook.sh
>> @@ -38,6 +38,18 @@ test_expect_success 'git hook run: basic' '
>>  	test_cmp expect actual
>>  '
>>
>> +test_expect_success 'git hook run: $GIT_HOOK' '
>> +	test_hook test-hook <<-EOF &&
>> +	printenv GIT_HOOK
>> +	EOF
>
> This will introduce the first hit from "git grep printenv".
>
> It is not even in POSIX.  Do we absolutely need to?

certainly not, I'll change this.

>
> Perhaps
>
>     echo "$GIT_HOOK"
>
> is sufficient, or if you want to distinguish an unset and set to
> empty string:
>
>     if test "${GIT_HOOK+set}" = "set"
>     then
>         echo "GIT_HOOK is set to '$GIT_HOOK'"
>     else
>         echo "GIT_HOOK is unset"
> 	exit 1
>     fi
>
> may be another way.
>
>> +	cat >expect <<-\EOF &&
>> +	test-hook
>> +	EOF
>
> For one-liner,
>
> 	echo test-hook >expect &&
>
> should be a more compact and equally understandable way to write this.

good point!

>
>> +	git hook run test-hook 2>actual &&
>> +	test_cmp expect actual
>> +'

  reply	other threads:[~2022-05-28  4:27 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-27 20:52 [PATCH] hook: provide GIT_HOOK for all hooks John Cai via GitGitGadget
2022-05-27 21:20 ` Junio C Hamano
2022-05-28  4:26   ` John Cai [this message]
2022-05-28 15:53 ` Ævar Arnfjörð Bjarmason
2022-05-28 16:42   ` John Cai
2022-05-28 17:24   ` Junio C Hamano
2022-05-31  1:31     ` John Cai

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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=E0D2A9A0-FB95-47ED-B672-93AAFE798CD9@gmail.com \
    --to=johncai86@gmail.com \
    --cc=emilyshaffer@google.com \
    --cc=git@vger.kernel.org \
    --cc=gitgitgadget@gmail.com \
    --cc=gitster@pobox.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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).