diff options
Diffstat (limited to 'roles/jails/22_forge/files/git-mirrors.sh')
| -rw-r--r-- | roles/jails/22_forge/files/git-mirrors.sh | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/roles/jails/22_forge/files/git-mirrors.sh b/roles/jails/22_forge/files/git-mirrors.sh index 6de665a..df78129 100644 --- a/roles/jails/22_forge/files/git-mirrors.sh +++ b/roles/jails/22_forge/files/git-mirrors.sh @@ -1,5 +1,6 @@ #!/bin/sh -# Run hourly via cron. Mirrors all repos that have a 'mirror' remote configured. +# Run hourly via cron. +# Handles mirror-to (push) and mirror-from (fetch) remotes for all repos. REPOS_DIR="/var/db/repos" LOG="/var/log/git-mirrors.log" @@ -9,17 +10,30 @@ export GIT_CONFIG_GLOBAL="$CONFIG_DIR/.gitconfig" echo "$(date) Starting mirror run" >> "$LOG" -for repo in "$REPOS_DIR"/*.git; do +for repo in "$REPOS_DIR"/*.git "$REPOS_DIR"/.*.git; do [ -d "$repo" ] || continue name="$(basename "$repo" .git)" - remote=$(git -C "$repo" remote get-url mirror-to 2>/dev/null) || continue + # mirror-to: push all refs to remote + if git -C "$repo" remote get-url mirror-to >/dev/null 2>&1; then + remote=$(git -C "$repo" remote get-url mirror-to) + echo "$(date) [push] $name -> $remote" >> "$LOG" + if git -C "$repo" push --mirror mirror-to >> "$LOG" 2>&1; then + echo "$(date) [push] OK $name" >> "$LOG" + else + echo "$(date) [push] FAILED $name" >> "$LOG" + fi + fi - echo "$(date) Mirroring $name -> $remote" >> "$LOG" - if git -C "$repo" push --mirror mirror-to >> "$LOG" 2>&1; then - echo "$(date) OK $name" >> "$LOG" - else - echo "$(date) FAILED $name" >> "$LOG" + # mirror-from: fetch all refs from remote + if git -C "$repo" remote get-url mirror-from >/dev/null 2>&1; then + remote=$(git -C "$repo" remote get-url mirror-from) + echo "$(date) [fetch] $name <- $remote" >> "$LOG" + if git -C "$repo" fetch --prune mirror-from '+refs/*:refs/*' >> "$LOG" 2>&1; then + echo "$(date) [fetch] OK $name" >> "$LOG" + else + echo "$(date) [fetch] FAILED $name" >> "$LOG" + fi fi done |
