]> git.ipfire.org Git - thirdparty/git.git/commitdiff
t1800: add test to verify hook execution ordering
authorAdrian Ratiu <adrian.ratiu@collabora.com>
Wed, 25 Mar 2026 19:54:59 +0000 (21:54 +0200)
committerJunio C Hamano <gitster@pobox.com>
Wed, 25 Mar 2026 21:00:47 +0000 (14:00 -0700)
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>
t/t1800-hook.sh

index 952bf97b86477cce8b30504e7836c7afe91b70e7..7eee84fc3956c2f9d73752b1977a8a841b57b107 100755 (executable)
@@ -25,7 +25,6 @@ test_expect_success 'git hook usage' '
        test_expect_code 129 git hook &&
        test_expect_code 129 git hook run &&
        test_expect_code 129 git hook run -h &&
-       test_expect_code 129 git hook list -h &&
        test_expect_code 129 git hook run --unknown 2>err &&
        test_expect_code 129 git hook list &&
        test_expect_code 129 git hook list -h &&
@@ -381,6 +380,34 @@ test_expect_success 'globally disabled hook can be re-enabled locally' '
        test_cmp expected actual
 '
 
+test_expect_success 'configured hooks run before hookdir hook' '
+       setup_hookdir &&
+       test_config hook.first.event "pre-commit" &&
+       test_config hook.first.command "echo first" &&
+       test_config hook.second.event "pre-commit" &&
+       test_config hook.second.command "echo second" &&
+
+       cat >expected <<-\EOF &&
+       first
+       second
+       hook from hookdir
+       EOF
+
+       git hook list pre-commit >actual &&
+       test_cmp expected actual &&
+
+       # "Legacy Hook" is the output of the hookdir pre-commit script
+       # written by setup_hookdir() above.
+       cat >expected <<-\EOF &&
+       first
+       second
+       "Legacy Hook"
+       EOF
+
+       git hook run pre-commit 2>actual &&
+       test_cmp expected actual
+'
+
 test_expect_success 'git hook run a hook with a bad shebang' '
        test_when_finished "rm -rf bad-hooks" &&
        mkdir bad-hooks &&