diff options
-rwxr-xr-xcustom/hooks/post-receive.cgit-age13
-rwxr-xr-xtests/t0507-hooks.sh20
2 files changed, 31 insertions, 2 deletions
diff --git a/custom/hooks/post-receive.cgit-age b/custom/hooks/post-receive.cgit-age
index 0567e08..a87e325 100755
--- a/custom/hooks/post-receive.cgit-age
+++ b/custom/hooks/post-receive.cgit-age
@@ -8,8 +8,17 @@
set -eu
# The pushing user's umask decides the mode of a freshly written agefile, so
-# force one that leaves the file readable by the web server.
-umask 022
+# force one that leaves the file readable by the web server. A repository
+# shared with a group, which git keeps group writable, keeps the directory
+# that way too, or the next member to push could not replace the file.
+case "$(git config --get core.sharedRepository | tr '[:upper:]' '[:lower:]')" in
+""|umask|0|false|no|off)
+ umask 022
+ ;;
+*)
+ umask 002
+ ;;
+esac
agefile="$(git rev-parse --git-dir)"/info/web/last-modified
diff --git a/tests/t0507-hooks.sh b/tests/t0507-hooks.sh
index ff42468..977931b 100755
--- a/tests/t0507-hooks.sh
+++ b/tests/t0507-hooks.sh
@@ -31,4 +31,24 @@ test_expect_success SANITY 'the cache hook shows a pusher no error' '
test_must_be_empty err
'
+test_expect_success 'the age hook writes the newest branch date' '
+ test_create_repo work &&
+ test_commit -C work first &&
+ git init -q --bare plain.git &&
+ git -C work push -q ../plain.git HEAD:refs/heads/main &&
+ (cd plain.git && sh "$HOOK_DIRECTORY/post-receive.cgit-age") &&
+ git -C plain.git for-each-ref --format="%(committerdate:iso8601)" refs/heads/main >expect &&
+ test_cmp expect plain.git/info/web/last-modified
+'
+
+# 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_done