Skip to content

Commit

Permalink
pre-command: always respect core.hooksPath
Browse files Browse the repository at this point in the history
We need to respect that config setting even if we already know that we
have a repository, but have not yet read the config.

The regression test was written by Alejandro Pauly.

Signed-off-by: Johannes Schindelin <johasc@microsoft.com>
  • Loading branch information
dscho committed Aug 10, 2017
1 parent d073d04 commit e5b6881
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
13 changes: 11 additions & 2 deletions run-command.c
Original file line number Diff line number Diff line change
Expand Up @@ -1212,9 +1212,18 @@ const char *find_hook(const char *name)
static struct strbuf path = STRBUF_INIT;

strbuf_reset(&path);
if (have_git_dir())
if (have_git_dir()) {
static int forced_config;

if (!forced_config) {
if (!git_hooks_path)
git_config_get_pathname("core.hookspath",
&git_hooks_path);
forced_config = 1;
}

strbuf_git_path(&path, "hooks/%s", name);
else if (!hook_path_early(name, &path))
} else if (!hook_path_early(name, &path))
return NULL;

if (access(path.buf, X_OK) < 0) {
Expand Down
11 changes: 11 additions & 0 deletions t/t0400-pre-command-hook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,15 @@ test_expect_success 'in a subdirectory, using an alias' '
test_line_count = 2 sub/log
'

test_expect_success 'with core.hooksPath' '
mkdir -p .git/alternateHooks &&
write_script .git/alternateHooks/pre-command <<-EOF &&
echo "alternate" >\$(git rev-parse --git-dir)/pre-command.out
EOF
write_script .git/hooks/pre-command <<-EOF &&
echo "original" >\$(git rev-parse --git-dir)/pre-command.out
EOF
git -c core.hooksPath=.git/alternateHooks status &&
test "alternate" = "$(cat .git/pre-command.out)"
'
test_done

0 comments on commit e5b6881

Please sign in to comment.