From 3febceef4a4d22e194f72706e917d9d05b8186c0 Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Sat, 7 Nov 2026 14:40:39 -1000 Subject: Run every hook case under every shell The cache hook's named url, no url and no access cases, the age hook's missing directory and shared group, and the first commit-graph write ran under sh alone, though the comment said every shell. The runs that did loop over the shells ignored what the hook printed, which reaches the pusher, so a hook that wrote to stderr or broke on a bashism under dash alone could pass. --- tests/t0507-hooks.sh | 171 ++++++++++++++++++++++++++------------------------- 1 file changed, 87 insertions(+), 84 deletions(-) diff --git a/tests/t0507-hooks.sh b/tests/t0507-hooks.sh index 9e5dfce..9f55547 100755 --- a/tests/t0507-hooks.sh +++ b/tests/t0507-hooks.sh @@ -81,7 +81,9 @@ test_expect_success 'set up a cache of two repositories and the index' ' grep -Fx "scan_path='\''$PWD/scan'\''" cache-hook ' -# The hooks are POSIX sh, so each runs under every such shell that is here. +# The hooks are POSIX sh, so every case runs under each such shell that is +# here. Whatever a hook prints reaches the pusher, so each has to stay +# silent. shells= for shell in sh dash ksh bash do @@ -90,45 +92,49 @@ done for shell in $shells do - test_expect_success "a push drops its own pages and the index under $shell" " + test_expect_success "a push drops its own pages and the index under $shell" ' fresh_slots && - (cd scan/a.git && $shell ../../cache-hook) && + (cd scan/a.git && $shell ../../cache-hook 2>../../err) && + test_must_be_empty err && cached_requests slots >left && - grep '|/b.git/log/' left && - grep 'url=b.git/refs/' left && - ! grep 'a.git' left && - ! grep '1|/0|' left && + test_grep "|/b.git/log/" left && + test_grep "url=b.git/refs/" left && + test_grep ! "a.git" left && + test_grep ! "1|/0|" left && test_path_is_file slots/0123abcd.lock && - ! ls slots | grep '^rc-' - " -done + ls slots >left-slots && + test_grep ! "^rc-" left-slots + ' -test_expect_success 'a repository named in cgitrc gives the hook its url' ' - fresh_slots && - git -C scan/b.git config hooks.cgiturl b.git && - sed "s|^scan_path=.*|scan_path=/nonexistent|" cache-hook >named-hook && - grep -Fx "scan_path=/nonexistent" named-hook && - (cd scan/b.git && sh ../../named-hook) && - cached_requests slots >left && - grep "|/a.git/log/" left && - ! grep "b.git" left -' + test_expect_success "a repository named in cgitrc gives the hook its url under $shell" ' + fresh_slots && + git -C scan/b.git config hooks.cgiturl b.git && + sed "s|^scan_path=.*|scan_path=/nonexistent|" cache-hook >named-hook && + grep -Fx "scan_path=/nonexistent" named-hook && + (cd scan/b.git && $shell ../../named-hook 2>../../err) && + test_must_be_empty err && + cached_requests slots >left && + test_grep "|/a.git/log/" left && + test_grep ! "b.git" left + ' -test_expect_success 'with no url to go on the whole cache goes' ' - fresh_slots && - (cd scan/a.git && sh ../../named-hook) && - test "$(ls slots)" = 0123abcd.lock -' + test_expect_success "with no url to go on the whole cache goes under $shell" ' + fresh_slots && + (cd scan/a.git && $shell ../../named-hook 2>../../err) && + test_must_be_empty err && + test "$(ls slots)" = 0123abcd.lock + ' -test_expect_success SANITY 'the cache hook shows a pusher no error' ' - fresh_slots && - test_when_finished "chmod 755 slots" && - chmod 555 slots && - (cd scan/a.git && sh ../../cache-hook 2>../../err) && - ls slots >left && - test_cmp pristine-slots left && - test_must_be_empty err -' + test_expect_success SANITY "the cache hook shows a pusher no error under $shell" ' + fresh_slots && + test_when_finished "chmod 755 slots" && + chmod 555 slots && + (cd scan/a.git && $shell ../../cache-hook 2>../../err) && + test_must_be_empty err && + ls slots >left && + test_cmp pristine-slots left + ' +done # The newest branch tip by committer date is main. The other branch has the # newer author date, a tag outside refs/heads points at a newer commit @@ -159,66 +165,63 @@ test_expect_success 'set up a repository whose dates disagree' ' for shell in $shells do - test_expect_success "the age hook writes the newest branch commit date under $shell" " + test_expect_success "the age hook writes the newest branch commit date under $shell" ' rm -f plain.git/info/web/last-modified && - (cd plain.git && $shell \"\$HOOK_DIRECTORY/post-receive.cgit-age\") && + (cd plain.git && $shell "$HOOK_DIRECTORY/post-receive.cgit-age" 2>../err) && + test_must_be_empty err && test_cmp expect plain.git/info/web/last-modified - " -done + ' -for shell in $shells -do - test_expect_success SANITY "the age hook shows a pusher no error under $shell" " + test_expect_success SANITY "the age hook shows a pusher no error under $shell" ' echo kept >kept && cp kept plain.git/info/web/last-modified && - test_when_finished 'chmod 755 plain.git/info/web' && + test_when_finished "chmod 755 plain.git/info/web" && chmod 555 plain.git/info/web && - (cd plain.git && $shell \"\$HOOK_DIRECTORY/post-receive.cgit-age\" 2>../err) && + (cd plain.git && $shell "$HOOK_DIRECTORY/post-receive.cgit-age" 2>../err) && test_must_be_empty err && test_cmp kept plain.git/info/web/last-modified - " -done - -test_expect_success SANITY 'the age hook shows no error when it cannot make its directory' ' - git init -q --bare closed.git && - git -C work push -q ../closed.git HEAD:refs/heads/main && - test_when_finished "chmod 755 closed.git/info" && - chmod 555 closed.git/info && - (cd closed.git && sh "$HOOK_DIRECTORY/post-receive.cgit-age" 2>../err) && - test_must_be_empty err && - test_path_is_missing closed.git/info/web -' - -# git keeps a shared repository group writable whatever the pusher's umask, -# and the next member to push has to be able to replace the file. -test_expect_success SANITY 'the age hook keeps a shared directory group writable' ' - git init -q --bare --shared=group shared.git && - git -C work push -q ../shared.git HEAD:refs/heads/main && - (cd shared.git && umask 022 && sh "$HOOK_DIRECTORY/post-receive.cgit-age") && - ls -ld shared.git/info/web >mode && - grep "^drwxrw[xs]" mode -' - -test_expect_success 'the commit-graph hook writes a graph with path filters' ' - git init -q --bare graph.git && - git -C work push -q ../graph.git HEAD:refs/heads/main && - (cd graph.git && sh "$HOOK_DIRECTORY/post-receive.commit-graph" 2>../graph-err) && - test_must_be_empty graph-err && - test_path_is_file graph.git/objects/info/commit-graphs/commit-graph-chain && - grep -q BDAT graph.git/objects/info/commit-graphs/*.graph && - git -C graph.git commit-graph verify -' + ' + + test_expect_success SANITY "the age hook shows no error when it cannot make its directory under $shell" ' + git init -q --bare closed-$shell.git && + git -C work push -q ../closed-$shell.git main && + test_when_finished "chmod 755 closed-$shell.git/info" && + chmod 555 closed-$shell.git/info && + (cd closed-$shell.git && $shell "$HOOK_DIRECTORY/post-receive.cgit-age" 2>../err) && + test_must_be_empty err && + test_path_is_missing closed-$shell.git/info/web + ' + + # git keeps a shared repository group writable whatever the pusher's + # umask, and the next member to push has to be able to replace the file. + test_expect_success SANITY "the age hook keeps a shared directory group writable under $shell" ' + git init -q --bare --shared=group shared-$shell.git && + git -C work push -q ../shared-$shell.git main && + (cd shared-$shell.git && umask 022 && $shell "$HOOK_DIRECTORY/post-receive.cgit-age" 2>../err) && + test_must_be_empty err && + ls -ld shared-$shell.git/info/web >mode && + test_grep "^drwxrw[xs]" mode + ' + + test_expect_success "the commit-graph hook writes a graph with path filters under $shell" ' + git init -q --bare graph-$shell.git && + git -C work push -q ../graph-$shell.git main && + (cd graph-$shell.git && $shell "$HOOK_DIRECTORY/post-receive.commit-graph" 2>../err) && + test_must_be_empty err && + test_path_is_file graph-$shell.git/objects/info/commit-graphs/commit-graph-chain && + grep -q BDAT graph-$shell.git/objects/info/commit-graphs/*.graph && + git -C graph-$shell.git commit-graph verify + ' -for shell in $shells -do - test_expect_success "a later push moves the graph on under $shell" " - cat graph.git/objects/info/commit-graphs/commit-graph-chain >chain-$shell && + test_expect_success "a later push moves the graph on under $shell" ' + cat graph-$shell.git/objects/info/commit-graphs/commit-graph-chain >chain-$shell && test_commit -C work graph-$shell && - git -C work push -q ../graph.git HEAD:refs/heads/main && - (cd graph.git && $shell \"\$HOOK_DIRECTORY/post-receive.commit-graph\") && - ! test_cmp chain-$shell graph.git/objects/info/commit-graphs/commit-graph-chain && - git -C graph.git commit-graph verify - " + git -C work push -q ../graph-$shell.git HEAD:main && + (cd graph-$shell.git && $shell "$HOOK_DIRECTORY/post-receive.commit-graph" 2>../err) && + test_must_be_empty err && + ! test_cmp chain-$shell graph-$shell.git/objects/info/commit-graphs/commit-graph-chain && + git -C graph-$shell.git commit-graph verify + ' done test_done -- cgit 2.12.1