diff options
| author | Bryce Kwon <bryce@brycekwon.com> | |
|---|---|---|
| committer | Bryce Kwon <bryce@brycekwon.com> | |
| commit | ||
| parent | ||
| tree | ||
| download | ||
Keep the cache hook's rm errors from pushers
Only the exit status was hidden, so a pusher without write access to
the cache root saw a permission error per cached page, against what
the hook's own comment promised.
| -rwxr-xr-x | custom/hooks/post-receive.cgit-cache | 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| -rwxr-xr-x | tests/t0507-hooks.sh | 34 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2 files changed, 38 insertions, 4 deletions
diff --git a/custom/hooks/post-receive.cgit-cache b/custom/hooks/post-receive.cgit-cache index 148a3f3..b1d5c13 100755 --- a/custom/hooks/post-receive.cgit-cache +++ b/custom/hooks/post-receive.cgit-cache @@ -12,9 +12,9 @@ # # The path below is the default cache-root, so a cgitrc that changes the # setting needs the same change here. The web server owns the cache root, so -# the pushing user needs write access to it. Nothing here exits nonzero when -# that access is missing, so the pusher is not shown an error over a stale -# page. +# the pushing user needs write access to it. Nothing here complains or exits +# nonzero when that access is missing, so the pusher is not shown an error +# over a stale page. # # To install the hook, copy or link it to hooks/post-receive in each # repository. Git runs one post-receive per repository, so fold this together @@ -30,4 +30,4 @@ test -d "$cache_root" || exit 0 # worth keeping is the lock files, which belong to writers still working. # The "! -name . -prune" pair is how POSIX find stays out of subdirectories. find "$cache_root"/. ! -name . -prune ! -name '*.lock' -type f \ - -exec rm -f {} + || exit 0 + -exec rm -f {} + 2>/dev/null || exit 0 diff --git a/tests/t0507-hooks.sh b/tests/t0507-hooks.sh new file mode 100755 index 0000000..ff42468 --- /dev/null +++ b/tests/t0507-hooks.sh @@ -0,0 +1,34 @@ +#!/bin/sh + +# Checks the post-receive hooks under custom/hooks. The cache hook runs from a +# copy pointed at a cache in the trash directory, since the shipped one names +# the system's cache root, and the age hook runs inside bare repositories the +# way git runs it after a push. + +test_description='Check the shipped post-receive hooks' +CGIT_TEST_NO_CREATE_REPOS=YesPlease +. ./setup.sh + +HOOK_DIRECTORY="$TEST_OUTPUT_DIRECTORY/../custom/hooks" + +test_expect_success 'the cache hook clears the slots and keeps the locks' ' + mkdir cache && + echo page >cache/0123abcd && + echo writer >cache/0123abcd.lock && + sed "s|^cache_root=.*|cache_root='\''$PWD/cache'\''|" \ + "$HOOK_DIRECTORY/post-receive.cgit-cache" >cache-hook && + sh cache-hook && + test_path_is_missing cache/0123abcd && + test_path_is_file cache/0123abcd.lock +' + +test_expect_success SANITY 'the cache hook shows a pusher no error' ' + echo page >cache/89abcdef && + test_when_finished "chmod 755 cache" && + chmod 555 cache && + sh cache-hook 2>err && + test_path_is_file cache/89abcdef && + test_must_be_empty err +' + +test_done |
