The idea of the --git-path option is not only to avoid having to
prefix paths with the output of --git-dir all the time, but also to
respect overrides for specific common paths inside the .git directory
(e.g. `git rev-parse --git-path objects` will report the value of
the environment variable GIT_OBJECT_DIRECTORY, if set).

When introducing the core.hooksPath setting, we forgot to adjust
git_path() accordingly. This patch fixes that.

Signed-off-by: Johannes Schindelin <>
Fetch-It-Via: git fetch git-path-hooks-v1

 path.c                       | 2 ++
 t/ | 6 ++++++
 2 files changed, 8 insertions(+)

diff --git a/path.c b/path.c
index 17551c4..fe3c4d9 100644
--- a/path.c
+++ b/path.c
@@ -380,6 +380,8 @@ static void adjust_git_path(struct strbuf *buf, int 
                              get_index_file(), strlen(get_index_file()));
        else if (git_db_env && dir_prefix(base, "objects"))
                replace_dir(buf, git_dir_len + 7, get_object_directory());
+       else if (git_hooks_path && dir_prefix(base, "hooks"))
+               replace_dir(buf, git_dir_len + 5, git_hooks_path);
        else if (git_common_dir_env)
                update_common_dir(buf, git_dir_len, NULL);
diff --git a/t/ b/t/
index 5e3fb3a..f1f9aee 100755
--- a/t/
+++ b/t/
@@ -34,4 +34,10 @@ test_expect_success 'Check that various forms of specifying 
core.hooksPath work'
        test_cmp expect actual
+test_expect_success 'git rev-parse --git-path hooks' '
+       git config core.hooksPath .git/custom-hooks &&
+       git rev-parse --git-path hooks/abc >actual &&
+       test .git/custom-hooks/abc = "$(cat actual)"

base-commit: 726cc2ba12c4573ab2e623077479c51019e1f3cd
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to
More majordomo info at

Reply via email to