Skip to content

Commit 7731b44

Browse files
derrickstoleedscho
authored andcommitted
t0401: test post-command for alias, version, typo
When the top-level Git process is an alias, it doesn't load much config and thus the postCommand.strategy config setting is not loaded properly. This leads to the post-command hook being run more frequently than we want, including an alias for 'git add' running the hook even when the worktree did not change. Similar state is not loaded by 'git version' or 'git typo'. Signed-off-by: Derrick Stolee <stolee@gmail.com>
1 parent 7c92b3b commit 7731b44

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

t/t0401-post-command-hook.sh

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,42 @@ test_expect_success 'with post-index-change config' '
7878
test_cmp expect post-index-change.out &&
7979
test_path_is_missing post-command.out &&
8080
81+
# add keeps the worktree the same, so does not run post-command.
82+
# and this should work through an alias.
83+
git config alias.addalias add &&
84+
rm -f post-command.out post-index-change.out &&
85+
echo more stuff >>file &&
86+
git addalias file &&
87+
test_cmp expect post-index-change.out &&
88+
89+
# TODO: This is the opposite of what we want! We want this to
90+
# be missing, but the current state has this happening in this
91+
# way.
92+
test_path_exists post-command.out &&
93+
8194
echo stuff >>file &&
8295
# reset --hard updates the worktree.
96+
# even through an alias
97+
git config alias.resetalias "reset --hard" &&
8398
rm -f post-command.out post-index-change.out &&
84-
git reset --hard &&
99+
git resetalias &&
85100
test_cmp expect post-index-change.out &&
86-
test_cmp expect post-command.out
101+
test_cmp expect post-command.out &&
102+
103+
# TODO: We want to skip the post-command hook here!
104+
rm -f post-command.out &&
105+
test_must_fail git && # get help text
106+
test_path_exists post-command.out &&
107+
108+
# TODO: We want to skip the post-command hook here!
109+
rm -f post-command.out &&
110+
git version &&
111+
test_path_exists post-command.out &&
112+
113+
# TODO: We want to skip the post-command hook here!
114+
rm -f post-command.out &&
115+
test_must_fail git typo &&
116+
test_path_exists post-command.out
87117
'
88118

89119
test_done

0 commit comments

Comments
 (0)