diff options
| author | Leitwolf11 | 2026-11-13 01:57:15 +0300 |
|---|---|---|
| committer | Leitwolf11 | 2026-11-13 01:57:15 +0300 |
| commit | 05d42b1a4ca923ee7726c35c261bfc75d32ddea3 (patch) | |
| tree | b7f2ddce7130aca707d9b9a5d9844078230812e5 /ops/git/git-mirror.sh | |
| parent | 83e0ad4586d90bf02c3a5bfeb1ab92fd90e51703 (diff) | |
| download | progmaweb-ops/git-mirrors.tar.gz | |
Serve only listed mirrors and report a failed default-branch lookupops/git-mirrors
- git-http-backend no longer exports every directory under the mirror
root: GIT_HTTP_EXPORT_ALL is gone, git-mirror marks each listed mirror
with git-daemon-export-ok, and a mirror taken off the list loses the
mark and is deleted on the next run. Tried live: an unlisted bare
repository answered 404 and was removed by the next run.
- git-mirror checks git ls-remote before it reads the default branch
and fails the run when the lookup fails.
- The README explains the /usr/bin spelling of the fcgiwrap label (an
equivalence of /usr/sbin), the stock label of /srv/*/www, and where
the DNS record is kept.
Diffstat (limited to 'ops/git/git-mirror.sh')
| -rw-r--r-- | ops/git/git-mirror.sh | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/ops/git/git-mirror.sh b/ops/git/git-mirror.sh index 25bed02..a36f978 100644 --- a/ops/git/git-mirror.sh +++ b/ops/git/git-mirror.sh @@ -40,9 +40,16 @@ for name in $names; do git -C "$repository" repack -a -d -b -q touch "$repository/info/web/repacked" fi - # HEAD follows the default branch of GitHub. - head=$(git -C "$repository" ls-remote --symref origin HEAD | sed -n 's|^ref: refs/heads/\([^[:space:]]*\)[[:space:]]*HEAD$|\1|p') - [ -n "$head" ] && git -C "$repository" symbolic-ref HEAD "refs/heads/$head" + # HEAD follows the default branch of GitHub; a failed lookup fails the run. + if advertised=$(git -C "$repository" ls-remote --symref origin HEAD); then + head=$(printf '%s\n' "$advertised" | sed -n 's|^ref: refs/heads/\([^[:space:]]*\)[[:space:]]*HEAD$|\1|p') + [ -n "$head" ] && git -C "$repository" symbolic-ref HEAD "refs/heads/$head" + else + echo "git-mirror: the default branch of $name could not be read" >&2 + status=1 + fi + # git-http-backend serves only repositories with this file. + touch "$repository/git-daemon-export-ok" # cgit shows the age of the last change of a repository from this file. git -C "$repository" for-each-ref --sort=-committerdate --count=1 \ --format='%(committerdate:iso8601)' refs/heads > "$repository/info/web/last-modified" @@ -51,4 +58,17 @@ for name in $names; do status=1 fi done +# A repository no longer listed stops being served at once and is removed. +for repository in "$root"/*.git; do + [ -d "$repository" ] || continue + name=$(basename "$repository" .git) + case " $(printf '%s ' $names)" in + *" $name "*) ;; + *) + rm -f "$repository/git-daemon-export-ok" + rm -rf -- "$repository" + echo "git-mirror: removed $name, which is no longer listed" >&2 + ;; + esac +done exit "$status" |