git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] hook: provide GIT_HOOK for all hooks

From
John Cai <johncai86@gmail.com>
Date
May 28, 2022, 04:26 UTC
Message-ID
<E0D2A9A0-FB95-47ED-B672-93AAFE798CD9@gmail.com>
In-Reply-To
<xmqqzgj21xm4.fsf@gitster.g>
Hi Junio
On 27 May 2022, at 17:20, Junio C Hamano wrote:
Show 17 quoted lines
> "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?
Show 17 quoted lines
>
>> 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.
Show 27 quoted lines
>
> 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
>> +'
Previous: Junio C HamanoNext: Ævar Arnfjörð Bjarmason
Message 3 of 7 in “hook: provide GIT_HOOK for all hooks”
  1. hook: provide GIT_HOOK for all hooksJohn Cai via GitGitGadget, May 27, 2022
  2. Junio C HamanoMay 27, 2022
  3. John CaiMay 28, 2022
  4. Ævar Arnfjörð BjarmasonMay 28, 2022
  5. John CaiMay 28, 2022
  6. Junio C HamanoMay 28, 2022
  7. John CaiMay 31, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.