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>
Adrian Ratiu committed
Mar 25, 2026 at 21:54 UTC
e0fceec06ba10222c4b66e8fdf83b139c4233d31
1 file changed
+28
-1
t/t1800-hook.sh
+28
-1
@@ -25,7 +25,6 @@ test_expect_success 'git hook usage' '
25
test_expect_code 129 git hook &&
26
test_expect_code 129 git hook run &&
27
test_expect_code 129 git hook run -h &&
28
- test_expect_code 129 git hook list -h &&
28
test_expect_code 129 git hook run --unknown 2>err &&
29
test_expect_code 129 git hook list &&
30
test_expect_code 129 git hook list -h &&
@@ -381,6 +380,34 @@ test_expect_success 'globally disabled hook can be re-enabled locally' '
380
test_cmp expected actual
381
'
382
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
+
411
test_expect_success 'git hook run a hook with a bad shebang' '
412
test_when_finished "rm -rf bad-hooks" &&
413
mkdir bad-hooks &&