Skip to content

Commit e1cfb52

Browse files
committed
hooks: change postCommand.strategy config value
The previously-named 'post-index-change' value for 'postCommand.strategy' did the following two things: 1. Avoid running the post-command hook unless the post-index-change hook _would_ run with a signal that the worktree changed. 2. Avoid running any installed post-index-change hooks. The additional restriction of the worktree change in (1) makes this name less appropriate. Also, item (2) seems to be a side-effect that we should avoid. We would like to allow both behaviors to exist. Update the value and behavior, including the tests. Signed-off-by: Derrick Stolee <[email protected]>
1 parent 8c178e8 commit e1cfb52

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

Documentation/config/postcommand.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ postCommand.strategy::
77
`always`;;
88
run the `post-command` hook on every process (default).
99

10-
`post-index-change`;;
10+
`worktree-change`;;
1111
run the `post-command` hook only if the current process wrote to
1212
the index and updated the worktree.
1313
----

hook.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ static int handle_hook_replacement(struct repository *r,
246246
{
247247
const char *strval;
248248
if (repo_config_get_string_tmp(r, "postcommand.strategy", &strval) ||
249-
strcasecmp(strval, "post-index-change"))
249+
strcasecmp(strval, "worktree-change"))
250250
return 0;
251251

252252
if (!strcmp(hook_name, "post-index-change")) {
@@ -255,10 +255,13 @@ static int handle_hook_replacement(struct repository *r,
255255
*result = write_post_index_change_sentinel(r);
256256
else
257257
*result = 0;
258-
return 1;
258+
259+
/* We don't skip post-index-change hooks that exist. */
260+
return 0;
259261
}
260262
if (!strcmp(hook_name, "post-command") &&
261263
!post_index_change_sentinel_exists(r)) {
264+
/* We skip the post-command hook in this case. */
262265
*result = 0;
263266
return 1;
264267
}

t/t0401-post-command-hook.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,24 +63,26 @@ test_expect_success 'with post-index-change config' '
6363
test_cmp expect post-command.out &&
6464
6565
# Now, show configured behavior
66-
git config postCommand.strategy post-index-change &&
67-
rm -f post-command.out post-index-change.out &&
66+
git config postCommand.strategy worktree-change &&
6867
6968
# rev-parse leaves index intact and thus skips post-command.
69+
rm -f post-command.out post-index-change.out &&
7070
git rev-parse HEAD &&
7171
test_path_is_missing post-index-change.out &&
7272
test_path_is_missing post-command.out &&
7373
7474
echo stuff >>file &&
7575
# add keeps the worktree the same, so does not run post-command.
76+
rm -f post-command.out post-index-change.out &&
7677
git add file &&
77-
test_path_is_missing post-index-change.out &&
78+
test_cmp expect post-index-change.out &&
7879
test_path_is_missing post-command.out &&
7980
8081
echo stuff >>file &&
8182
# reset --hard updates the worktree.
83+
rm -f post-command.out post-index-change.out &&
8284
git reset --hard &&
83-
test_path_is_missing post-index-change.out &&
85+
test_cmp expect post-index-change.out &&
8486
test_cmp expect post-command.out
8587
'
8688

0 commit comments

Comments
 (0)