{"thread":{"id":"42118","subject":"[PATCH] hooks: Add ability to specify where the hook directory is","startedAt":"2016-04-22T23:33:17Z","lastAt":"2016-04-26T19:19:23Z","messageCount":10,"participants":["Ævar Arnfjörð Bjarmason","SZEDER Gábor","Johannes Sixt","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"284213","messageId":"1461367997-28745-1-git-send-email-avarab@gmail.com","threadId":"42118","inReplyTo":null,"subject":"[PATCH] hooks: Add ability to specify where the hook directory is","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2016-04-22T23:33:17Z","receivedAt":"2016-04-22T23:33:17Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Change the hardcoded lookup for .git/hooks/* to optionally lookup in\n$(git config core.hooksDirectory)/* instead if that config key is set.\n\nThis is essentially a more intrusive version of the git-init ability to\nspecify hooks on init time via init templates.\n\nThe difference between that facility and this feature is that this can\nbe set up after the fact via e.g. ~/.gitconfig or /etc/gitconfig to\napply for all your personal repositories, or all repositories on the\nsystem.\n\nI plan on using this on a centralized Git server where users can create\narbitrary repositories under /gitroot, but I'd like to manage all the\nhooks that should be run centrally via a unified dispatch mechanism.\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n Documentation/config.txt          | 10 ++++++++++\n Documentation/githooks.txt        |  5 ++++-\n cache.h                           |  1 +\n config.c                          |  3 +++\n environment.c                     |  1 +\n run-command.c                     |  5 ++++-\n t/t1350-config-hooks-directory.sh | 35 +++++++++++++++++++++++++++++++++++\n 7 files changed, 58 insertions(+), 2 deletions(-)\n create mode 100755 t/t1350-config-hooks-directory.sh\n\ndiff --git a/Documentation/config.txt b/Documentation/config.txt\nindex 42d2b50..2faf3c0 100644\n--- a/Documentation/config.txt\n+++ b/Documentation/config.txt\n@@ -618,6 +618,16 @@ core.attributesFile::\n \t$XDG_CONFIG_HOME/git/attributes. If $XDG_CONFIG_HOME is either not\n \tset or empty, $HOME/.config/git/attributes is used instead.\n \n+core.hooksDirectory::\n+\tBy default Git will look for your hooks in the '$GIT_DIR/hooks'\n+\tdirectory. Set this to different absolute directory name,\n+\te.g. '/etc/git/hooks', and Git will try to find your hooks that\n+\tdirectory, e.g. '/etc/git/hooks/pre-receive' instead of in\n+\t'$GIT_DIR/hooks'.\n++\n+This is useful in cases where you'd like to centrally configure your\n+Git hooks instead of configuring them on a per-repository basis.\n+\n core.editor::\n \tCommands such as `commit` and `tag` that lets you edit\n \tmessages by launching an editor uses the value of this\ndiff --git a/Documentation/githooks.txt b/Documentation/githooks.txt\nindex a2f59b1..e1fe66d 100644\n--- a/Documentation/githooks.txt\n+++ b/Documentation/githooks.txt\n@@ -13,13 +13,16 @@ $GIT_DIR/hooks/*\n DESCRIPTION\n -----------\n \n-Hooks are little scripts you can place in `$GIT_DIR/hooks`\n+Hooks are little scripts you can place in the `hooks`\n directory to trigger action at certain points.  When\n 'git init' is run, a handful of example hooks are copied into the\n `hooks` directory of the new repository, but by default they are\n all disabled.  To enable a hook, rename it by removing its `.sample`\n suffix.\n \n+By default the hooks directory is `$GIT_DIR/hooks`, but that can be\n+changed via the `core.hooksDirectory` (see linkgit:git-config[1]).\n+\n NOTE: It is also a requirement for a given hook to be executable.\n However - in a freshly initialized repository - the `.sample` files are\n executable by default.\ndiff --git a/cache.h b/cache.h\nindex 2711048..85ad594 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -654,6 +654,7 @@ extern int warn_on_object_refname_ambiguity;\n extern const char *apply_default_whitespace;\n extern const char *apply_default_ignorewhitespace;\n extern const char *git_attributes_file;\n+extern const char *git_hooks_directory;\n extern int zlib_compression_level;\n extern int core_compression_level;\n extern int core_compression_seen;\ndiff --git a/config.c b/config.c\nindex 10b5c95..543de4e 100644\n--- a/config.c\n+++ b/config.c\n@@ -717,6 +717,9 @@ static int git_default_core_config(const char *var, const char *value)\n \tif (!strcmp(var, \"core.attributesfile\"))\n \t\treturn git_config_pathname(&git_attributes_file, var, value);\n \n+\tif (!strcmp(var, \"core.hooksdirectory\"))\n+\t\treturn git_config_pathname(&git_hooks_directory, var, value);\n+\n \tif (!strcmp(var, \"core.bare\")) {\n \t\tis_bare_repository_cfg = git_config_bool(var, value);\n \t\treturn 0;\ndiff --git a/environment.c b/environment.c\nindex 57acb2f..ffb5dec 100644\n--- a/environment.c\n+++ b/environment.c\n@@ -31,6 +31,7 @@ const char *git_log_output_encoding;\n const char *apply_default_whitespace;\n const char *apply_default_ignorewhitespace;\n const char *git_attributes_file;\n+const char *git_hooks_directory;\n int zlib_compression_level = Z_BEST_SPEED;\n int core_compression_level;\n int core_compression_seen;\ndiff --git a/run-command.c b/run-command.c\nindex 8c7115a..ae8e470 100644\n--- a/run-command.c\n+++ b/run-command.c\n@@ -815,7 +815,10 @@ const char *find_hook(const char *name)\n \tstatic struct strbuf path = STRBUF_INIT;\n \n \tstrbuf_reset(&path);\n-\tstrbuf_git_path(&path, \"hooks/%s\", name);\n+\tif (git_hooks_directory)\n+\t\tstrbuf_addf(&path, \"%s/%s\", git_hooks_directory, name);\n+\telse\n+\t\tstrbuf_git_path(&path, \"hooks/%s\", name);\n \tif (access(path.buf, X_OK) < 0)\n \t\treturn NULL;\n \treturn path.buf;\ndiff --git a/t/t1350-config-hooks-directory.sh b/t/t1350-config-hooks-directory.sh\nnew file mode 100755\nindex 0000000..556c1d3\n--- /dev/null\n+++ b/t/t1350-config-hooks-directory.sh\n@@ -0,0 +1,35 @@\n+#!/bin/sh\n+\n+test_description='Test the core.hooksDirectory configuration variable'\n+\n+. ./test-lib.sh\n+\n+test_expect_success 'set up a pre-commit hook in core.hooksDirectory' '\n+\tmkdir -p .git/custom-hooks .git/hooks &&\n+\tcat >.git/custom-hooks/pre-commit <<EOF &&\n+#!$SHELL_PATH\n+printf \"%s\" \".\" >>.git/PRE-COMMIT-HOOK-WAS-CALLED\n+EOF\n+\tcat >.git/hooks/pre-commit <<EOF &&\n+\tchmod +x .git/hooks/pre-commit\n+#!$SHELL_PATH\n+printf \"%s\" \"SHOULD NOT BE CALLED\" >>.git/PRE-COMMIT-HOOK-WAS-CALLED\n+EOF\n+\tchmod +x .git/custom-hooks/pre-commit\n+'\n+\n+test_expect_success 'Check that various forms of specifying core.hooksDirectory work' '\n+\ttest_commit no_custom_hook &&\n+\tgit config core.hooksDirectory .git/custom-hooks &&\n+\ttest_commit have_custom_hook &&\n+\tgit config core.hooksDirectory .git/custom-hooks/ &&\n+\ttest_commit have_custom_hook_trailing_slash &&\n+\tgit config core.hooksDirectory \"$PWD/.git/custom-hooks\" &&\n+\ttest_commit have_custom_hook_abs_path &&\n+\tgit config core.hooksDirectory \"$PWD/.git/custom-hooks/\" &&\n+\ttest_commit have_custom_hook_abs_path_trailing_slash &&\n+    printf \"%s\" \"....\" >.git/PRE-COMMIT-HOOK-WAS-CALLED.expect &&\n+    test_cmp .git/PRE-COMMIT-HOOK-WAS-CALLED.expect .git/PRE-COMMIT-HOOK-WAS-CALLED\n+'\n+\n+test_done\n-- \n2.1.3\n"},{"id":"284216","messageId":"1461370382-16524-1-git-send-email-szeder@ira.uka.de","threadId":"42118","inReplyTo":"1461367997-28745-1-git-send-email-avarab@gmail.com","subject":"Re: [PATCH] hooks: Add ability to specify where the hook directory is","fromName":"SZEDER Gábor","fromEmail":"szeder@ira.uka.de","sentAt":"2016-04-23T00:13:02Z","receivedAt":"2016-04-23T00:13:02Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"\n> Change the hardcoded lookup for .git/hooks/* to optionally lookup in\n> $(git config core.hooksDirectory)/* instead if that config key is set.\n> \n> This is essentially a more intrusive version of the git-init ability to\n> specify hooks on init time via init templates.\n> \n> The difference between that facility and this feature is that this can\n> be set up after the fact via e.g. ~/.gitconfig or /etc/gitconfig to\n> apply for all your personal repositories, or all repositories on the\n> system.\n> \n> I plan on using this on a centralized Git server where users can create\n> arbitrary repositories under /gitroot, but I'd like to manage all the\n> hooks that should be run centrally via a unified dispatch mechanism.\n> \n> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n> ---\n>  Documentation/config.txt          | 10 ++++++++++\n>  Documentation/githooks.txt        |  5 ++++-\n>  cache.h                           |  1 +\n>  config.c                          |  3 +++\n>  environment.c                     |  1 +\n>  run-command.c                     |  5 ++++-\n>  t/t1350-config-hooks-directory.sh | 35 +++++++++++++++++++++++++++++++++++\n>  7 files changed, 58 insertions(+), 2 deletions(-)\n>  create mode 100755 t/t1350-config-hooks-directory.sh\n> \n> diff --git a/Documentation/config.txt b/Documentation/config.txt\n> index 42d2b50..2faf3c0 100644\n> --- a/Documentation/config.txt\n> +++ b/Documentation/config.txt\n> @@ -618,6 +618,16 @@ core.attributesFile::\n>  \t$XDG_CONFIG_HOME/git/attributes. If $XDG_CONFIG_HOME is either not\n>  \tset or empty, $HOME/.config/git/attributes is used instead.\n>  \n> +core.hooksDirectory::\n> +\tBy default Git will look for your hooks in the '$GIT_DIR/hooks'\n> +\tdirectory. Set this to different absolute directory name,\n\nMental note: here you say that it should be an absolute directory.\n\n> +\te.g. '/etc/git/hooks', and Git will try to find your hooks that\n\ns/hooks that/hooks in that/\n\n> +\tdirectory, e.g. '/etc/git/hooks/pre-receive' instead of in\n> +\t'$GIT_DIR/hooks'.\n> ++\n> +This is useful in cases where you'd like to centrally configure your\n> +Git hooks instead of configuring them on a per-repository basis.\n> +\n>  core.editor::\n>  \tCommands such as `commit` and `tag` that lets you edit\n>  \tmessages by launching an editor uses the value of this\n\n\n> diff --git a/t/t1350-config-hooks-directory.sh b/t/t1350-config-hooks-directory.sh\n> new file mode 100755\n> index 0000000..556c1d3\n> --- /dev/null\n> +++ b/t/t1350-config-hooks-directory.sh\n> @@ -0,0 +1,35 @@\n> +#!/bin/sh\n> +\n> +test_description='Test the core.hooksDirectory configuration variable'\n> +\n> +. ./test-lib.sh\n> +\n> +test_expect_success 'set up a pre-commit hook in core.hooksDirectory' '\n> +\tmkdir -p .git/custom-hooks .git/hooks &&\n> +\tcat >.git/custom-hooks/pre-commit <<EOF &&\n> +#!$SHELL_PATH\n> +printf \"%s\" \".\" >>.git/PRE-COMMIT-HOOK-WAS-CALLED\n> +EOF\n> +\tcat >.git/hooks/pre-commit <<EOF &&\n> +\tchmod +x .git/hooks/pre-commit\n> +#!$SHELL_PATH\n> +printf \"%s\" \"SHOULD NOT BE CALLED\" >>.git/PRE-COMMIT-HOOK-WAS-CALLED\n> +EOF\n> +\tchmod +x .git/custom-hooks/pre-commit\n> +'\n\nPlease use the 'write_script' helper for, well, writing scripts.\n\n> +\n> +test_expect_success 'Check that various forms of specifying core.hooksDirectory work' '\n> +\ttest_commit no_custom_hook &&\n> +\tgit config core.hooksDirectory .git/custom-hooks &&\n> +\ttest_commit have_custom_hook &&\n> +\tgit config core.hooksDirectory .git/custom-hooks/ &&\n> +\ttest_commit have_custom_hook_trailing_slash &&\n\nThese two cases ensure that it should work even when the configured\nhook directory is given as a relative path, though the docs say it\nshould be an absolute path.\n\n> +\tgit config core.hooksDirectory \"$PWD/.git/custom-hooks\" &&\n> +\ttest_commit have_custom_hook_abs_path &&\n> +\tgit config core.hooksDirectory \"$PWD/.git/custom-hooks/\" &&\n> +\ttest_commit have_custom_hook_abs_path_trailing_slash &&\n> +    printf \"%s\" \"....\" >.git/PRE-COMMIT-HOOK-WAS-CALLED.expect &&\n> +    test_cmp .git/PRE-COMMIT-HOOK-WAS-CALLED.expect .git/PRE-COMMIT-HOOK-WAS-CALLED\n\nIndentation with spaces.\n\n> +'\n> +\n> +test_done\n> -- \n> 2.1.3\n"},{"id":"284217","messageId":"CACBZZX7jTHqSq0ADJxO0cP+1MZMWAowLMMj4J0NHkFTYOYsJiw@mail.gmail.com","threadId":"42118","inReplyTo":"1461370382-16524-1-git-send-email-szeder@ira.uka.de","subject":"Re: [PATCH] hooks: Add ability to specify where the hook directory is","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2016-04-23T00:44:11Z","receivedAt":"2016-04-23T00:44:11Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"On Sat, Apr 23, 2016 at 2:13 AM, SZEDER Gábor <szeder@ira.uka.de> wrote:\n>\n>> Change the hardcoded lookup for .git/hooks/* to optionally lookup in\n>> $(git config core.hooksDirectory)/* instead if that config key is set.\n>>\n>> This is essentially a more intrusive version of the git-init ability to\n>> specify hooks on init time via init templates.\n>>\n>> The difference between that facility and this feature is that this can\n>> be set up after the fact via e.g. ~/.gitconfig or /etc/gitconfig to\n>> apply for all your personal repositories, or all repositories on the\n>> system.\n>>\n>> I plan on using this on a centralized Git server where users can create\n>> arbitrary repositories under /gitroot, but I'd like to manage all the\n>> hooks that should be run centrally via a unified dispatch mechanism.\n>>\n>> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n>> ---\n>>  Documentation/config.txt          | 10 ++++++++++\n>>  Documentation/githooks.txt        |  5 ++++-\n>>  cache.h                           |  1 +\n>>  config.c                          |  3 +++\n>>  environment.c                     |  1 +\n>>  run-command.c                     |  5 ++++-\n>>  t/t1350-config-hooks-directory.sh | 35 +++++++++++++++++++++++++++++++++++\n>>  7 files changed, 58 insertions(+), 2 deletions(-)\n>>  create mode 100755 t/t1350-config-hooks-directory.sh\n>>\n>> diff --git a/Documentation/config.txt b/Documentation/config.txt\n>> index 42d2b50..2faf3c0 100644\n>> --- a/Documentation/config.txt\n>> +++ b/Documentation/config.txt\n>> @@ -618,6 +618,16 @@ core.attributesFile::\n>>       $XDG_CONFIG_HOME/git/attributes. If $XDG_CONFIG_HOME is either not\n>>       set or empty, $HOME/.config/git/attributes is used instead.\n>>\n>> +core.hooksDirectory::\n>> +     By default Git will look for your hooks in the '$GIT_DIR/hooks'\n>> +     directory. Set this to different absolute directory name,\n\nThanks for the review. I'll submit a new patch with fixes pending any\nmore comments from others to reduce list churn.\n\n> Mental note: here you say that it should be an absolute directory.\n>\n>> +     e.g. '/etc/git/hooks', and Git will try to find your hooks that\n>\n> s/hooks that/hooks in that/\n\nWill fix.\n\n>> +     directory, e.g. '/etc/git/hooks/pre-receive' instead of in\n>> +     '$GIT_DIR/hooks'.\n>> ++\n>> +This is useful in cases where you'd like to centrally configure your\n>> +Git hooks instead of configuring them on a per-repository basis.\n>> +\n>>  core.editor::\n>>       Commands such as `commit` and `tag` that lets you edit\n>>       messages by launching an editor uses the value of this\n>\n>\n>> diff --git a/t/t1350-config-hooks-directory.sh b/t/t1350-config-hooks-directory.sh\n>> new file mode 100755\n>> index 0000000..556c1d3\n>> --- /dev/null\n>> +++ b/t/t1350-config-hooks-directory.sh\n>> @@ -0,0 +1,35 @@\n>> +#!/bin/sh\n>> +\n>> +test_description='Test the core.hooksDirectory configuration variable'\n>> +\n>> +. ./test-lib.sh\n>> +\n>> +test_expect_success 'set up a pre-commit hook in core.hooksDirectory' '\n>> +     mkdir -p .git/custom-hooks .git/hooks &&\n>> +     cat >.git/custom-hooks/pre-commit <<EOF &&\n>> +#!$SHELL_PATH\n>> +printf \"%s\" \".\" >>.git/PRE-COMMIT-HOOK-WAS-CALLED\n>> +EOF\n>> +     cat >.git/hooks/pre-commit <<EOF &&\n>> +     chmod +x .git/hooks/pre-commit\n>> +#!$SHELL_PATH\n>> +printf \"%s\" \"SHOULD NOT BE CALLED\" >>.git/PRE-COMMIT-HOOK-WAS-CALLED\n>> +EOF\n>> +     chmod +x .git/custom-hooks/pre-commit\n>> +'\n>\n> Please use the 'write_script' helper for, well, writing scripts.\n\nWill fix.\n\n>> +\n>> +test_expect_success 'Check that various forms of specifying core.hooksDirectory work' '\n>> +     test_commit no_custom_hook &&\n>> +     git config core.hooksDirectory .git/custom-hooks &&\n>> +     test_commit have_custom_hook &&\n>> +     git config core.hooksDirectory .git/custom-hooks/ &&\n>> +     test_commit have_custom_hook_trailing_slash &&\n>\n> These two cases ensure that it should work even when the configured\n> hook directory is given as a relative path, though the docs say it\n> should be an absolute path.\n\nYeah I didn't mention this in the docs or commit message, but I\nfigured not promising anything else in the docs made sense.\n\nI.e. a relative path of e.g. .git/custom-hook/* won't work if you're\ncd'd into a subdirectory of your repository, so telling users that it\nhas to be absolute is probably an OK white lie.\n\n>> +     git config core.hooksDirectory \"$PWD/.git/custom-hooks\" &&\n>> +     test_commit have_custom_hook_abs_path &&\n>> +     git config core.hooksDirectory \"$PWD/.git/custom-hooks/\" &&\n>> +     test_commit have_custom_hook_abs_path_trailing_slash &&\n>> +    printf \"%s\" \"....\" >.git/PRE-COMMIT-HOOK-WAS-CALLED.expect &&\n>> +    test_cmp .git/PRE-COMMIT-HOOK-WAS-CALLED.expect .git/PRE-COMMIT-HOOK-WAS-CALLED\n>\n> Indentation with spaces.\n\nWill fix.\n\n>> +'\n>> +\n>> +test_done\n>> --\n>> 2.1.3\n"},{"id":"284367","messageId":"1461532702-4045-1-git-send-email-avarab@gmail.com","threadId":"42118","inReplyTo":"CACBZZX7jTHqSq0ADJxO0cP+1MZMWAowLMMj4J0NHkFTYOYsJiw@mail.gmail.com","subject":"[PATCH v2] hooks: Add ability to specify where the hook directory is","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2016-04-24T21:18:22Z","receivedAt":"2016-04-24T21:18:22Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Change the hardcoded lookup for .git/hooks/* to optionally lookup in\n$(git config core.hooksPath)/* instead.\n\nThis is essentially a more intrusive version of the git-init ability to\nspecify hooks on init time via init templates.\n\nThe difference between that facility and this feature is that this can\nbe set up after the fact via e.g. ~/.gitconfig or /etc/gitconfig to\napply for all your personal repositories, or all repositories on the\nsystem.\n\nI plan on using this on a centralized Git server where users can create\narbitrary repositories under /gitroot, but I'd like to manage all the\nhooks that should be run centrally via a unified dispatch mechanism.\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n\nThis is based off the githooks.txt series I just sent, I thought it\nmade the most sense to address the questions the previous version\nraised about how we treat the working directory with unrelated\ngithooks.txt doc improvements.\n\nThis version also address all the other issues SZEDER Gábor noted.\n\n Documentation/config.txt     | 17 +++++++++++++++++\n Documentation/githooks.txt   | 12 ++++++++----\n cache.h                      |  1 +\n config.c                     |  3 +++\n environment.c                |  1 +\n run-command.c                |  5 ++++-\n t/t1350-config-hooks-path.sh | 33 +++++++++++++++++++++++++++++++++\n 7 files changed, 67 insertions(+), 5 deletions(-)\n create mode 100755 t/t1350-config-hooks-path.sh\n\ndiff --git a/Documentation/config.txt b/Documentation/config.txt\nindex 42d2b50..6a079c1 100644\n--- a/Documentation/config.txt\n+++ b/Documentation/config.txt\n@@ -618,6 +618,23 @@ core.attributesFile::\n \t$XDG_CONFIG_HOME/git/attributes. If $XDG_CONFIG_HOME is either not\n \tset or empty, $HOME/.config/git/attributes is used instead.\n \n+core.hooksPath::\n+\tBy default Git will look for your hooks in the\n+\t'$GIT_DIR/hooks' directory. Set this to different path,\n+\te.g. '/etc/git/hooks', and Git will try to find your hooks in\n+\tthat directory, e.g. '/etc/git/hooks/pre-receive' instead of\n+\tin '$GIT_DIR/hooks/pre-receive'.\n++\n+The path can either be absolute or relative. In the latter case see\n+the discussion in the \"DESCRIPTION\" section of linkgit:githooks[5]\n+about what the relative path will be relative to.\n++\n+This configuration is useful in cases where you'd like to\n+e.g. centrally configure your Git hooks instead of configuring them on\n+a per-repository basis, or a more flexible and centralized alterantive\n+having an `init.templateDir` where you've changed the 'hooks'\n+directory.\n+\n core.editor::\n \tCommands such as `commit` and `tag` that lets you edit\n \tmessages by launching an editor uses the value of this\ndiff --git a/Documentation/githooks.txt b/Documentation/githooks.txt\nindex d30492c..3b1591f 100644\n--- a/Documentation/githooks.txt\n+++ b/Documentation/githooks.txt\n@@ -7,15 +7,19 @@ githooks - Hooks used by Git\n \n SYNOPSIS\n --------\n-$GIT_DIR/hooks/*\n+$GIT_DIR/hooks/* (or `git config core.hooksPath`/*)\n \n \n DESCRIPTION\n -----------\n \n-Hooks are programs you can place in the `$GIT_DIR/hooks` directory to\n-trigger action at certain points. Hooks that don't have the executable\n-bit set are ignored.\n+Hooks are programs you can place in a hooks directory to trigger action\n+at certain points. Hooks that don't have the executable bit set are\n+ignored.\n+\n+By default the hooks directory is `$GIT_DIR/hooks`, but that can be\n+changed via the `core.hooksPath` configuration variable (see\n+linkgit:git-config[1]).\n \n When a hook is called in a non-bare repository the working directory\n is guaranteed to be the root of the working tree, in a bare repository\ndiff --git a/cache.h b/cache.h\nindex 2711048..4f7d222 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -654,6 +654,7 @@ extern int warn_on_object_refname_ambiguity;\n extern const char *apply_default_whitespace;\n extern const char *apply_default_ignorewhitespace;\n extern const char *git_attributes_file;\n+extern const char *git_hooks_path;\n extern int zlib_compression_level;\n extern int core_compression_level;\n extern int core_compression_seen;\ndiff --git a/config.c b/config.c\nindex 10b5c95..51f80e4 100644\n--- a/config.c\n+++ b/config.c\n@@ -717,6 +717,9 @@ static int git_default_core_config(const char *var, const char *value)\n \tif (!strcmp(var, \"core.attributesfile\"))\n \t\treturn git_config_pathname(&git_attributes_file, var, value);\n \n+\tif (!strcmp(var, \"core.hookspath\"))\n+\t\treturn git_config_pathname(&git_hooks_path, var, value);\n+\n \tif (!strcmp(var, \"core.bare\")) {\n \t\tis_bare_repository_cfg = git_config_bool(var, value);\n \t\treturn 0;\ndiff --git a/environment.c b/environment.c\nindex 57acb2f..2857e3f 100644\n--- a/environment.c\n+++ b/environment.c\n@@ -31,6 +31,7 @@ const char *git_log_output_encoding;\n const char *apply_default_whitespace;\n const char *apply_default_ignorewhitespace;\n const char *git_attributes_file;\n+const char *git_hooks_path;\n int zlib_compression_level = Z_BEST_SPEED;\n int core_compression_level;\n int core_compression_seen;\ndiff --git a/run-command.c b/run-command.c\nindex 8c7115a..39d7237 100644\n--- a/run-command.c\n+++ b/run-command.c\n@@ -815,7 +815,10 @@ const char *find_hook(const char *name)\n \tstatic struct strbuf path = STRBUF_INIT;\n \n \tstrbuf_reset(&path);\n-\tstrbuf_git_path(&path, \"hooks/%s\", name);\n+\tif (git_hooks_path)\n+\t\tstrbuf_addf(&path, \"%s/%s\", git_hooks_path, name);\n+\telse\n+\t\tstrbuf_git_path(&path, \"hooks/%s\", name);\n \tif (access(path.buf, X_OK) < 0)\n \t\treturn NULL;\n \treturn path.buf;\ndiff --git a/t/t1350-config-hooks-path.sh b/t/t1350-config-hooks-path.sh\nnew file mode 100755\nindex 0000000..31461aa\n--- /dev/null\n+++ b/t/t1350-config-hooks-path.sh\n@@ -0,0 +1,33 @@\n+#!/bin/sh\n+\n+test_description='Test the core.hooksPath configuration variable'\n+\n+. ./test-lib.sh\n+\n+test_expect_success 'set up a pre-commit hook in core.hooksPath' '\n+\tmkdir -p .git/custom-hooks .git/hooks &&\n+\twrite_script .git/custom-hooks/pre-commit <<EOF &&\n+printf \"%s\" \".\" >>.git/PRE-COMMIT-HOOK-WAS-CALLED\n+EOF\n+\tcat >.git/hooks/pre-commit <<EOF &&\n+\twrite_script .git/hooks/pre-commit &&\n+printf \"%s\" \"SHOULD NOT BE CALLED\" >>.git/PRE-COMMIT-HOOK-WAS-CALLED\n+EOF\n+\tchmod +x .git/custom-hooks/pre-commit\n+'\n+\n+test_expect_success 'Check that various forms of specifying core.hooksPath work' '\n+\ttest_commit no_custom_hook &&\n+\tgit config core.hooksPath .git/custom-hooks &&\n+\ttest_commit have_custom_hook &&\n+\tgit config core.hooksPath .git/custom-hooks/ &&\n+\ttest_commit have_custom_hook_trailing_slash &&\n+\tgit config core.hooksPath \"$PWD/.git/custom-hooks\" &&\n+\ttest_commit have_custom_hook_abs_path &&\n+\tgit config core.hooksPath \"$PWD/.git/custom-hooks/\" &&\n+\ttest_commit have_custom_hook_abs_path_trailing_slash &&\n+\tprintf \"%s\" \"....\" >.git/PRE-COMMIT-HOOK-WAS-CALLED.expect &&\n+\ttest_cmp .git/PRE-COMMIT-HOOK-WAS-CALLED.expect .git/PRE-COMMIT-HOOK-WAS-CALLED\n+'\n+\n+test_done\n-- \n2.1.3\n"},{"id":"284408","messageId":"CACBZZX6T-vmgbMTyrbU+228mQoRFzgCjkV13uiQyedmc8SfyAg@mail.gmail.com","threadId":"42118","inReplyTo":"1461532702-4045-1-git-send-email-avarab@gmail.com","subject":"Re: [PATCH v2] hooks: Add ability to specify where the hook directory is","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2016-04-25T14:19:20Z","receivedAt":"2016-04-25T14:19:20Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"On Sun, Apr 24, 2016 at 11:18 PM, Ævar Arnfjörð Bjarmason\n<avarab@gmail.com> wrote:\n> Change the hardcoded lookup for .git/hooks/* to optionally lookup in\n> $(git config core.hooksPath)/* instead.\n>\n> This is essentially a more intrusive version of the git-init ability to\n> specify hooks on init time via init templates.\n>\n> The difference between that facility and this feature is that this can\n> be set up after the fact via e.g. ~/.gitconfig or /etc/gitconfig to\n> apply for all your personal repositories, or all repositories on the\n> system.\n>\n> I plan on using this on a centralized Git server where users can create\n> arbitrary repositories under /gitroot, but I'd like to manage all the\n> hooks that should be run centrally via a unified dispatch mechanism.\n>\n> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n> ---\n>\n> This is based off the githooks.txt series I just sent, I thought it\n> made the most sense to address the questions the previous version\n> raised about how we treat the working directory with unrelated\n> githooks.txt doc improvements.\n>\n> This version also address all the other issues SZEDER Gábor noted.\n\nThis still applies cleanly on top of the v3 githooks.txt series I just sent.\n\nI forgot to note one thing, when I re-rolled this I changed the\nconfiguration variable from core.hooksDirectory to core.hooksPath,\neverything else in config.txt that dealt with paths was *Path\nsomething, so I thought that made more sense for consistency.\n"},{"id":"284470","messageId":"571E6BCF.5020606@kdbg.org","threadId":"42118","inReplyTo":"1461532702-4045-1-git-send-email-avarab@gmail.com","subject":"Re: [PATCH v2] hooks: Add ability to specify where the hook directory is","fromName":"Johannes Sixt","fromEmail":"j6t@kdbg.org","sentAt":"2016-04-25T19:11:11Z","receivedAt":"2016-04-25T19:11:11Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Am 24.04.2016 um 23:18 schrieb Ævar Arnfjörð Bjarmason:\n> +test_expect_success 'set up a pre-commit hook in core.hooksPath' '\n> +\tmkdir -p .git/custom-hooks .git/hooks &&\n> +\twrite_script .git/custom-hooks/pre-commit <<EOF &&\n> +printf \"%s\" \".\" >>.git/PRE-COMMIT-HOOK-WAS-CALLED\n> +EOF\n> +\tcat >.git/hooks/pre-commit <<EOF &&\n> +\twrite_script .git/hooks/pre-commit &&\n> +printf \"%s\" \"SHOULD NOT BE CALLED\" >>.git/PRE-COMMIT-HOOK-WAS-CALLED\n> +EOF\n> +\tchmod +x .git/custom-hooks/pre-commit\n\nHere I see a half-baked attempt to use write_script. Once you've fixed \nthat, we have a pre-commit hook in the regular hook directory. \nObviously, the hook is expected not to be called...\n\n> +'\n> +\n> +test_expect_success 'Check that various forms of specifying core.hooksPath work' '\n> +\ttest_commit no_custom_hook &&\n\n... but at this point, it *will* be called...\n\n> +\tgit config core.hooksPath .git/custom-hooks &&\n> +\ttest_commit have_custom_hook &&\n> +\tgit config core.hooksPath .git/custom-hooks/ &&\n> +\ttest_commit have_custom_hook_trailing_slash &&\n> +\tgit config core.hooksPath \"$PWD/.git/custom-hooks\" &&\n> +\ttest_commit have_custom_hook_abs_path &&\n> +\tgit config core.hooksPath \"$PWD/.git/custom-hooks/\" &&\n> +\ttest_commit have_custom_hook_abs_path_trailing_slash &&\n> +\tprintf \"%s\" \"....\" >.git/PRE-COMMIT-HOOK-WAS-CALLED.expect &&\n\n... and this expectation is wrong.\n\n> +\ttest_cmp .git/PRE-COMMIT-HOOK-WAS-CALLED.expect .git/PRE-COMMIT-HOOK-WAS-CALLED\n> +'\n> +\n> +test_done\n>\n\nI feel a bit uneasy that expected and actual files are not POSIXly \ncorrect text files, i.e., the LF at the end is missing...\n\n-- Hannes\n"},{"id":"284475","messageId":"xmqqlh41junh.fsf@gitster.mtv.corp.google.com","threadId":"42118","inReplyTo":"1461532702-4045-1-git-send-email-avarab@gmail.com","subject":"Re: [PATCH v2] hooks: Add ability to specify where the hook directory is","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2016-04-25T20:33:22Z","receivedAt":"2016-04-25T20:33:22Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:\n\n> +core.hooksPath::\n> +\tBy default Git will look for your hooks in the\n> +\t'$GIT_DIR/hooks' directory. Set this to different path,\n> +\te.g. '/etc/git/hooks', and Git will try to find your hooks in\n> +\tthat directory, e.g. '/etc/git/hooks/pre-receive' instead of\n> +\tin '$GIT_DIR/hooks/pre-receive'.\n> ++\n> +The path can either be absolute or relative. In the latter case see\n> +the discussion in the \"DESCRIPTION\" section of linkgit:githooks[5]\n> +about what the relative path will be relative to.\n\n... which does not seem to appear there, it seems?\n\n>  DESCRIPTION\n>  -----------\n>  \n> -Hooks are programs you can place in the `$GIT_DIR/hooks` directory to\n> -trigger action at certain points. Hooks that don't have the executable\n> -bit set are ignored.\n> +Hooks are programs you can place in a hooks directory to trigger action\n> +at certain points. Hooks that don't have the executable bit set are\n> +ignored.\n> +\n> +By default the hooks directory is `$GIT_DIR/hooks`, but that can be\n> +changed via the `core.hooksPath` configuration variable (see\n> +linkgit:git-config[1]).\n\nThe section talks about what the cwd of the process that runs the\nhook is, but it is not clear at all from these three lines in\ncore.hooksPath description above how the cwd of the process is\nrelated with the directory the relative path will be relative to.\n\nUnless the readers know that the implementation makes sure that the\nprocess chdir'ed to that final directory before calling find_hook(),\nthat is.  And I do not think you want to assume that knowledge on\nthe side of the readers.\n\n> diff --git a/t/t1350-config-hooks-path.sh b/t/t1350-config-hooks-path.sh\n> new file mode 100755\n> index 0000000..31461aa\n> --- /dev/null\n> +++ b/t/t1350-config-hooks-path.sh\n> @@ -0,0 +1,33 @@\n> +#!/bin/sh\n> +\n> +test_description='Test the core.hooksPath configuration variable'\n> +\n> +. ./test-lib.sh\n> +\n> +test_expect_success 'set up a pre-commit hook in core.hooksPath' '\n> +\tmkdir -p .git/custom-hooks .git/hooks &&\n> +\twrite_script .git/custom-hooks/pre-commit <<EOF &&\n> +printf \"%s\" \".\" >>.git/PRE-COMMIT-HOOK-WAS-CALLED\n> +EOF\n\nBecause there is no funny interpolation going on, it would help\nreaders to signal that fact by quoting the end-of-here-text marker.\nAnd it makes the entire test block reads nicer if you indent the\nbody of hte here-text by prefixing the end-of-here-text marker with\na dash, i.e.\n\n\twrite_script .git/custom-hooks/pre-commit <<-\\EOF &&\n\tprintf \"%s\" \".\" >>.git/PRE-COMMIT-HOOK-WAS-CALLED\n\tEOF\n\n> +\tcat >.git/hooks/pre-commit <<EOF &&\n> +\twrite_script .git/hooks/pre-commit &&\n> +printf \"%s\" \"SHOULD NOT BE CALLED\" >>.git/PRE-COMMIT-HOOK-WAS-CALLED\n> +EOF\n> +\tchmod +x .git/custom-hooks/pre-commit\n\nYou didn't want cat and chmod here?\n\n> +'\n> +\n> +test_expect_success 'Check that various forms of specifying core.hooksPath work' '\n> +\ttest_commit no_custom_hook &&\n> +\tgit config core.hooksPath .git/custom-hooks &&\n> +\ttest_commit have_custom_hook &&\n> +\tgit config core.hooksPath .git/custom-hooks/ &&\n> +\ttest_commit have_custom_hook_trailing_slash &&\n> +\tgit config core.hooksPath \"$PWD/.git/custom-hooks\" &&\n> +\ttest_commit have_custom_hook_abs_path &&\n> +\tgit config core.hooksPath \"$PWD/.git/custom-hooks/\" &&\n> +\ttest_commit have_custom_hook_abs_path_trailing_slash &&\n> +\tprintf \"%s\" \"....\" >.git/PRE-COMMIT-HOOK-WAS-CALLED.expect &&\n> +\ttest_cmp .git/PRE-COMMIT-HOOK-WAS-CALLED.expect .git/PRE-COMMIT-HOOK-WAS-CALLED\n> +'\n> +\n> +test_done\n"},{"id":"284536","messageId":"CACBZZX5X_7guR2b+uQFcxzzC6xCv55z=KiMUO6kEmJdQ-U1Gcw@mail.gmail.com","threadId":"42118","inReplyTo":"xmqqlh41junh.fsf@gitster.mtv.corp.google.com","subject":"Re: [PATCH v2] hooks: Add ability to specify where the hook directory is","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2016-04-26T16:31:55Z","receivedAt":"2016-04-26T16:31:55Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"On Mon, Apr 25, 2016 at 10:33 PM, Junio C Hamano <gitster@pobox.com> wrote:\n> Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:\n>\n>> +core.hooksPath::\n>> +     By default Git will look for your hooks in the\n>> +     '$GIT_DIR/hooks' directory. Set this to different path,\n>> +     e.g. '/etc/git/hooks', and Git will try to find your hooks in\n>> +     that directory, e.g. '/etc/git/hooks/pre-receive' instead of\n>> +     in '$GIT_DIR/hooks/pre-receive'.\n>> ++\n>> +The path can either be absolute or relative. In the latter case see\n>> +the discussion in the \"DESCRIPTION\" section of linkgit:githooks[5]\n>> +about what the relative path will be relative to.\n>\n> ... which does not seem to appear there, it seems?\n\nI think it does. Read on...\n\n>>  DESCRIPTION\n>>  -----------\n>>\n>> -Hooks are programs you can place in the `$GIT_DIR/hooks` directory to\n>> -trigger action at certain points. Hooks that don't have the executable\n>> -bit set are ignored.\n>> +Hooks are programs you can place in a hooks directory to trigger action\n>> +at certain points. Hooks that don't have the executable bit set are\n>> +ignored.\n>> +\n>> +By default the hooks directory is `$GIT_DIR/hooks`, but that can be\n>> +changed via the `core.hooksPath` configuration variable (see\n>> +linkgit:git-config[1]).\n>\n> The section talks about what the cwd of the process that runs the\n> hook is, but it is not clear at all from these three lines in\n> core.hooksPath description above how the cwd of the process is\n> related with the directory the relative path will be relative to.\n\nI think the documentation mostly makes sense, but that the context of\nthis patch is confusing.\n\nI.e. when I say:\n\n> The path can either be absolute or relative. In the latter case see\n> the discussion in the \"DESCRIPTION\" section of linkgit:githooks[5]\n> about what the relative path will be relative to.\n\nIn config.txt, I'm not talking about the patch to githooks.txt I'm\nadding in this commit, but the first patch in the githooks.txt series,\ni.e. this section:\n\n> When a hook is called in a non-bare repository the working directory\n> is guaranteed to be the root of the working tree, in a bare repository\n> the working directory will be the path to the repository. I.e. hooks\n> don't need to worry about the user's current working directory.\n\nI.e. I'm not talking about the \"by default the hooks directory [blah\nblah]\" part I'm adding here.\n\n> Unless the readers know that the implementation makes sure that the\n> process chdir'ed to that final directory before calling find_hook(),\n> that is.  And I do not think you want to assume that knowledge on\n> the side of the readers.\n\nThis should not be explicitly covered in githooks.txt in my previous\nseries per the above..\n\n>> diff --git a/t/t1350-config-hooks-path.sh b/t/t1350-config-hooks-path.sh\n>> new file mode 100755\n>> index 0000000..31461aa\n>> --- /dev/null\n>> +++ b/t/t1350-config-hooks-path.sh\n>> @@ -0,0 +1,33 @@\n>> +#!/bin/sh\n>> +\n>> +test_description='Test the core.hooksPath configuration variable'\n>> +\n>> +. ./test-lib.sh\n>> +\n>> +test_expect_success 'set up a pre-commit hook in core.hooksPath' '\n>> +     mkdir -p .git/custom-hooks .git/hooks &&\n>> +     write_script .git/custom-hooks/pre-commit <<EOF &&\n>> +printf \"%s\" \".\" >>.git/PRE-COMMIT-HOOK-WAS-CALLED\n>> +EOF\n>\n> Because there is no funny interpolation going on, it would help\n> readers to signal that fact by quoting the end-of-here-text marker.\n> And it makes the entire test block reads nicer if you indent the\n> body of hte here-text by prefixing the end-of-here-text marker with\n> a dash, i.e.\n\nYes this and all the other stuff you and Johannes mentioned in this\nthread just made no sense and was just some brainfart of mine. I'm\nfixing all these issues up for the next re-send.\n\n>         write_script .git/custom-hooks/pre-commit <<-\\EOF &&\n>         printf \"%s\" \".\" >>.git/PRE-COMMIT-HOOK-WAS-CALLED\n>         EOF\n>\n>> +     cat >.git/hooks/pre-commit <<EOF &&\n>> +     write_script .git/hooks/pre-commit &&\n>> +printf \"%s\" \"SHOULD NOT BE CALLED\" >>.git/PRE-COMMIT-HOOK-WAS-CALLED\n>> +EOF\n>> +     chmod +x .git/custom-hooks/pre-commit\n>\n> You didn't want cat and chmod here?\n>\n>> +'\n>> +\n>> +test_expect_success 'Check that various forms of specifying core.hooksPath work' '\n>> +     test_commit no_custom_hook &&\n>> +     git config core.hooksPath .git/custom-hooks &&\n>> +     test_commit have_custom_hook &&\n>> +     git config core.hooksPath .git/custom-hooks/ &&\n>> +     test_commit have_custom_hook_trailing_slash &&\n>> +     git config core.hooksPath \"$PWD/.git/custom-hooks\" &&\n>> +     test_commit have_custom_hook_abs_path &&\n>> +     git config core.hooksPath \"$PWD/.git/custom-hooks/\" &&\n>> +     test_commit have_custom_hook_abs_path_trailing_slash &&\n>> +     printf \"%s\" \"....\" >.git/PRE-COMMIT-HOOK-WAS-CALLED.expect &&\n>> +     test_cmp .git/PRE-COMMIT-HOOK-WAS-CALLED.expect .git/PRE-COMMIT-HOOK-WAS-CALLED\n>> +'\n>> +\n>> +test_done\n"},{"id":"284573","messageId":"xmqqvb34faed.fsf@gitster.mtv.corp.google.com","threadId":"42118","inReplyTo":"CACBZZX5X_7guR2b+uQFcxzzC6xCv55z=KiMUO6kEmJdQ-U1Gcw@mail.gmail.com","subject":"Re: [PATCH v2] hooks: Add ability to specify where the hook directory is","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2016-04-26T19:16:42Z","receivedAt":"2016-04-26T19:16:42Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:\n\n>>> +The path can either be absolute or relative. In the latter case see\n>>> +the discussion in the \"DESCRIPTION\" section of linkgit:githooks[5]\n>>> +about what the relative path will be relative to.\n>>\n>> ... which does not seem to appear there, it seems?\n>\n> I think it does. Read on...\n\nI actually read the result of applying the patch before sending the\nreview above.\n\n>>>  DESCRIPTION\n>>>  -----------\n>>>\n>>> -Hooks are programs you can place in the `$GIT_DIR/hooks` directory to\n>>> -trigger action at certain points. Hooks that don't have the executable\n>>> -bit set are ignored.\n>>> +Hooks are programs you can place in a hooks directory to trigger action\n>>> +at certain points. Hooks that don't have the executable bit set are\n>>> +ignored.\n>>> +\n>>> +By default the hooks directory is `$GIT_DIR/hooks`, but that can be\n>>> +changed via the `core.hooksPath` configuration variable (see\n>>> +linkgit:git-config[1]).\n>>\n>> The section talks about what the cwd of the process that runs the\n>> hook is, but it is not clear at all from these three lines in\n>> core.hooksPath description above how the cwd of the process is\n>> related with the directory the relative path will be relative to.\n>\n> I think the documentation mostly makes sense, but that the context of\n> this patch is confusing.\n>\n> I.e. when I say:\n>\n>> The path can either be absolute or relative. In the latter case see\n>> the discussion in the \"DESCRIPTION\" section of linkgit:githooks[5]\n>> about what the relative path will be relative to.\n>\n> In config.txt, I'm not talking about the patch to githooks.txt I'm\n> adding in this commit, but the first patch in the githooks.txt series,\n> i.e. this section:\n>\n>> When a hook is called in a non-bare repository the working directory\n>> is guaranteed to be the root of the working tree, in a bare repository\n>> the working directory will be the path to the repository. I.e. hooks\n>> don't need to worry about the user's current working directory.\n>\n> I.e. I'm not talking about the \"by default the hooks directory [blah\n> blah]\" part I'm adding here.\n\nI know.  What it boils down to I think is this.\n\nIf somebody said:\n\n    The path to the hooks directory can be specified relative, and\n    it is relative to something described elsewhere.\n\n    Hooks are run either at the root of the working tree or in\n    GIT_DIR, and they are not affected where the user's current\n    directory is (they cannot even know where it is).\n\nyou interpret, with the knowledge that \"we first determine in which\ndirectory to run a hook with a given name, go there, and then look\nfor the named hook\", the directory hooks are run in is NATURALLY the\ndirectory relative paths the hooks are found are relative to.\n\nMy problem was that it is only natural if you have that knowledge.\n\nA reader who starts with a mindset \"Git first finds the hook to run,\nand then goes to the directory to run it in\", it is not naturally\nclear.  The latter is specified by two rules, one for a bare and the\nother for a non-bare repository, and it is very clear.  The former\nis specified nowhere, unless you give a hint to fix the mindset of\nsuch a reader.\n"},{"id":"284575","messageId":"CACBZZX5EtUU5UPXX=nuL29aV-m2nX1x9vtL07WD2yHkLku576g@mail.gmail.com","threadId":"42118","inReplyTo":"xmqqvb34faed.fsf@gitster.mtv.corp.google.com","subject":"Re: [PATCH v2] hooks: Add ability to specify where the hook directory is","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2016-04-26T19:19:23Z","receivedAt":"2016-04-26T19:19:23Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"On Tue, Apr 26, 2016 at 9:16 PM, Junio C Hamano <gitster@pobox.com> wrote:\n> Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:\n>\n>>>> +The path can either be absolute or relative. In the latter case see\n>>>> +the discussion in the \"DESCRIPTION\" section of linkgit:githooks[5]\n>>>> +about what the relative path will be relative to.\n>>>\n>>> ... which does not seem to appear there, it seems?\n>>\n>> I think it does. Read on...\n>\n> I actually read the result of applying the patch before sending the\n> review above.\n>\n>>>>  DESCRIPTION\n>>>>  -----------\n>>>>\n>>>> -Hooks are programs you can place in the `$GIT_DIR/hooks` directory to\n>>>> -trigger action at certain points. Hooks that don't have the executable\n>>>> -bit set are ignored.\n>>>> +Hooks are programs you can place in a hooks directory to trigger action\n>>>> +at certain points. Hooks that don't have the executable bit set are\n>>>> +ignored.\n>>>> +\n>>>> +By default the hooks directory is `$GIT_DIR/hooks`, but that can be\n>>>> +changed via the `core.hooksPath` configuration variable (see\n>>>> +linkgit:git-config[1]).\n>>>\n>>> The section talks about what the cwd of the process that runs the\n>>> hook is, but it is not clear at all from these three lines in\n>>> core.hooksPath description above how the cwd of the process is\n>>> related with the directory the relative path will be relative to.\n>>\n>> I think the documentation mostly makes sense, but that the context of\n>> this patch is confusing.\n>>\n>> I.e. when I say:\n>>\n>>> The path can either be absolute or relative. In the latter case see\n>>> the discussion in the \"DESCRIPTION\" section of linkgit:githooks[5]\n>>> about what the relative path will be relative to.\n>>\n>> In config.txt, I'm not talking about the patch to githooks.txt I'm\n>> adding in this commit, but the first patch in the githooks.txt series,\n>> i.e. this section:\n>>\n>>> When a hook is called in a non-bare repository the working directory\n>>> is guaranteed to be the root of the working tree, in a bare repository\n>>> the working directory will be the path to the repository. I.e. hooks\n>>> don't need to worry about the user's current working directory.\n>>\n>> I.e. I'm not talking about the \"by default the hooks directory [blah\n>> blah]\" part I'm adding here.\n>\n> I know.  What it boils down to I think is this.\n>\n> If somebody said:\n>\n>     The path to the hooks directory can be specified relative, and\n>     it is relative to something described elsewhere.\n>\n>     Hooks are run either at the root of the working tree or in\n>     GIT_DIR, and they are not affected where the user's current\n>     directory is (they cannot even know where it is).\n>\n> you interpret, with the knowledge that \"we first determine in which\n> directory to run a hook with a given name, go there, and then look\n> for the named hook\", the directory hooks are run in is NATURALLY the\n> directory relative paths the hooks are found are relative to.\n>\n> My problem was that it is only natural if you have that knowledge.\n>\n> A reader who starts with a mindset \"Git first finds the hook to run,\n> and then goes to the directory to run it in\", it is not naturally\n> clear.  The latter is specified by two rules, one for a bare and the\n> other for a non-bare repository, and it is very clear.  The former\n> is specified nowhere, unless you give a hint to fix the mindset of\n> such a reader.\n\nRight. I changed the wording for all of this to hopefully be more\nclear in my v4.\n"}]}