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

Re: [PATCH v4 4/4] hooks: Add ability to specify where the hook directory is

From
Junio C Hamano <gitster@pobox.com>
Date
Apr 26, 2016, 19:55 UTC
Message-ID
<xmqqinz4f8mg.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<1461694402-9629-5-git-send-email-avarab@gmail.com>
Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:
Show 11 quoted lines
> +core.hooksPath::
> +	By default Git will look for your hooks in the
> +	'$GIT_DIR/hooks' directory. Set this to different path,
> +	e.g. '/etc/git/hooks', and Git will try to find your hooks in
> +	that directory, e.g. '/etc/git/hooks/pre-receive' instead of
> +	in '$GIT_DIR/hooks/pre-receive'.
> ++
> +The path can either be absolute or relative. When specifying a
> +relative path see the discussion in the "DESCRIPTION" section of
> +linkgit:githooks[5] for what the relative relative path will be
> +relative to.
    The path can be either absolute or relative.  A relative path is
    taken as relative to the directory where the hooks are run (see
    linkgit:githooks[5]).
perhaps?
> +This configuration is useful in cases where you'd like to
> +e.g. centrally configure your Git hooks instead of configuring them on
s/e.g. //;

I thought "you can do X (if you want to do X)" were getting rewritten to "you can do X", not "you can do e.g. X".

Show 17 quoted lines
> diff --git a/t/t1350-config-hooks-path.sh b/t/t1350-config-hooks-path.sh
> new file mode 100755
> index 0000000..f2f0aa9
> --- /dev/null
> +++ b/t/t1350-config-hooks-path.sh
> @@ -0,0 +1,31 @@
> +#!/bin/sh
> +
> +test_description='Test the core.hooksPath configuration variable'
> +
> +. ./test-lib.sh
> +
> +test_expect_success 'set up a pre-commit hook in core.hooksPath' '
> +	mkdir -p .git/custom-hooks .git/hooks &&
> +	write_script .git/custom-hooks/pre-commit <<-\EOF &&
> +printf "%s" "CUST" >>.git/PRE-COMMIT-HOOK-WAS-CALLED
> +EOF
	write_script .git/custom-hooks/pre-commit <<-\EOF &&
	printf "%s" "CUST" >>.git/PRE-COMMIT-HOOK-WAS-CALLED
	EOF

I however wonder why this is not "echo CUST" (or even "echo CUSTOM").

> +	write_script .git/hooks/pre-commit <<-\EOF
> +printf "%s" "NORM" >>.git/PRE-COMMIT-HOOK-WAS-CALLED
> +EOF
> +'
Likewise.
Show 11 quoted lines
> +test_expect_success 'Check that various forms of specifying core.hooksPath work' '
> +	test_commit no_custom_hook &&
> +	git config core.hooksPath .git/custom-hooks &&
> +	test_commit have_custom_hook &&
> +	git config core.hooksPath .git/custom-hooks/ &&
> +	test_commit have_custom_hook_trailing_slash &&
> +	git config core.hooksPath "$PWD/.git/custom-hooks" &&
> +	test_commit have_custom_hook_abs_path &&
> +	git config core.hooksPath "$PWD/.git/custom-hooks/" &&
> +	test_commit have_custom_hook_abs_path_trailing_slash &&
> +	printf "%s" "NORMCUSTCUSTCUSTCUST" >.git/PRE-COMMIT-HOOK-WAS-CALLED.expect &&
And this will become
	test_write_lines NORM CUST CUST CUST CUST >expect &&
> +	test_cmp .git/PRE-COMMIT-HOOK-WAS-CALLED.expect .git/PRE-COMMIT-HOOK-WAS-CALLED

If you did one-line-at-a-time with 'echo', test_cmp would show line-wise diff, which may make spotting the difference easier.

> +'
> +
> +test_done
Previous: Ævar Arnfjörð BjarmasonNext: Ævar Arnfjörð Bjarmason
Message 8 of 20 in “githooks.txt improvements + core.hooksDirectory”
  1. 0/4 githooks.txt improvements + core.hooksDirectoryÆvar Arnfjörð Bjarmason, Apr 26, 2016
  2. 1/4 githooks.txt: Improve the intro sectionÆvar Arnfjörð Bjarmason, Apr 26, 2016
  3. Junio C HamanoApr 26, 2016
  4. 2/4 githooks.txt: Amend dangerous advice about 'update' hook ACLÆvar Arnfjörð Bjarmason, Apr 26, 2016
  5. Junio C HamanoApr 26, 2016
  6. 3/4 githooks.txt: Minor improvements to the grammar & phrasingÆvar Arnfjörð Bjarmason, Apr 26, 2016
  7. 4/4 hooks: Add ability to specify where the hook directory isÆvar Arnfjörð Bjarmason, Apr 26, 2016
  8. Junio C HamanoApr 26, 2016
  9. 0/4 githooks.txt improvements + core.hooksDirectoryÆvar Arnfjörð Bjarmason, May 4, 2016
  10. 1/4 githooks.txt: Improve the intro sectionÆvar Arnfjörð Bjarmason, May 4, 2016
  11. 2/4 githooks.txt: Amend dangerous advice about 'update' hook ACLÆvar Arnfjörð Bjarmason, May 4, 2016
  12. 3/4 githooks.txt: Minor improvements to the grammar & phrasingÆvar Arnfjörð Bjarmason, May 4, 2016
  13. 4/4 hooks: Add ability to specify where the hook directory isÆvar Arnfjörð Bjarmason, May 4, 2016
  14. Junio C HamanoMay 4, 2016
  15. 0/4 githooks.txt improvements + core.hooksDirectoryÆvar Arnfjörð Bjarmason, May 4, 2016
  16. 1/4 githooks.txt: Improve the intro sectionÆvar Arnfjörð Bjarmason, May 4, 2016
  17. 2/4 githooks.txt: Amend dangerous advice about 'update' hook ACLÆvar Arnfjörð Bjarmason, May 4, 2016
  18. 3/4 githooks.txt: Minor improvements to the grammar & phrasingÆvar Arnfjörð Bjarmason, May 4, 2016
  19. 4/4 hooks: Add ability to specify where the hook directory isÆvar Arnfjörð Bjarmason, May 4, 2016
  20. Junio C HamanoMay 4, 2016

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.