Skip to content

Commit e0fceec

Browse files
10ne1gitster
authored andcommitted
t1800: add test to verify hook execution ordering
There is a documented expectation that configured hooks are run before the hook from the hookdir. Add a test for it. While at it, I noticed that `git hook list -h` runs twice in the `git hook usage` test, so remove one invocation. Suggested-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Adrian Ratiu <adrian.ratiu@collabora.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 2e5dbaf commit e0fceec

1 file changed

Lines changed: 28 additions & 1 deletion

File tree

t/t1800-hook.sh

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ test_expect_success 'git hook usage' '
2525
test_expect_code 129 git hook &&
2626
test_expect_code 129 git hook run &&
2727
test_expect_code 129 git hook run -h &&
28-
test_expect_code 129 git hook list -h &&
2928
test_expect_code 129 git hook run --unknown 2>err &&
3029
test_expect_code 129 git hook list &&
3130
test_expect_code 129 git hook list -h &&
@@ -381,6 +380,34 @@ test_expect_success 'globally disabled hook can be re-enabled locally' '
381380
test_cmp expected actual
382381
'
383382

383+
test_expect_success 'configured hooks run before hookdir hook' '
384+
setup_hookdir &&
385+
test_config hook.first.event "pre-commit" &&
386+
test_config hook.first.command "echo first" &&
387+
test_config hook.second.event "pre-commit" &&
388+
test_config hook.second.command "echo second" &&
389+
390+
cat >expected <<-\EOF &&
391+
first
392+
second
393+
hook from hookdir
394+
EOF
395+
396+
git hook list pre-commit >actual &&
397+
test_cmp expected actual &&
398+
399+
# "Legacy Hook" is the output of the hookdir pre-commit script
400+
# written by setup_hookdir() above.
401+
cat >expected <<-\EOF &&
402+
first
403+
second
404+
"Legacy Hook"
405+
EOF
406+
407+
git hook run pre-commit 2>actual &&
408+
test_cmp expected actual
409+
'
410+
384411
test_expect_success 'git hook run a hook with a bad shebang' '
385412
test_when_finished "rm -rf bad-hooks" &&
386413
mkdir bad-hooks &&

0 commit comments

Comments
 (0)