aboutsummaryrefslogtreecommitdiffstats
path: root/gitolite-cgit/auto-default-branch.sh
diff options
context:
space:
mode:
authorJesus E <heckyel@riseup.net>2023-07-03 16:23:00 -0400
committerJesus E <heckyel@riseup.net>2023-07-03 16:23:00 -0400
commit1e6f82e10d587b4778ca0bc603e260213078b09b (patch)
tree2e8568f903c00b8d3867575507738ae6546b509b /gitolite-cgit/auto-default-branch.sh
parent0dab6b6f05330588c346894528a60d41a2b7e676 (diff)
downloadgitolite-cgit-docker-1e6f82e10d587b4778ca0bc603e260213078b09b.tar.lz
gitolite-cgit-docker-1e6f82e10d587b4778ca0bc603e260213078b09b.tar.xz
gitolite-cgit-docker-1e6f82e10d587b4778ca0bc603e260213078b09b.zip
Add auto-default-branch
Diffstat (limited to 'gitolite-cgit/auto-default-branch.sh')
-rw-r--r--gitolite-cgit/auto-default-branch.sh29
1 files changed, 29 insertions, 0 deletions
diff --git a/gitolite-cgit/auto-default-branch.sh b/gitolite-cgit/auto-default-branch.sh
new file mode 100644
index 0000000..d9c60a0
--- /dev/null
+++ b/gitolite-cgit/auto-default-branch.sh
@@ -0,0 +1,29 @@
+#!/bin/sh
+
+info() { printf >&2 %s\\n "$*" ; }
+
+die() { info "$*" ; exit 1 ; }
+
+ensure_HEAD() {
+ [ "$1" = 'POST_GIT' ] || die "unsupported trigger '$1'"
+
+ cd "$GL_REPO_BASE/$2.git"
+
+ # everything OK if the default in HEAD points to a real branch
+ git show-ref --quiet --verify "$(git symbolic-ref HEAD)" && return 0
+
+ # there *might* be a mismatch, so let's find out a real branch
+ local head
+ head="$(git show-ref --heads | head -1 | sed -e 's/^.* //')"
+
+ # the repo might still be empty
+ [ -n "$head" ] || return 0
+
+ # we have a default branch that we can set here
+ info "setting HEAD to <$head>"
+ git symbolic-ref HEAD "$head" -m "Default HEAD to branch <$head>"
+}
+
+set -eu
+
+ensure_HEAD "$@"