#!/usr/bin/env bash # Carry bitbaum/kits `main` to GitLab, where CI publishes every package whose # version the push raised (kits#14). Replaces a Gitea push mirror: this Gitea # refuses SSH push mirrors and an HTTPS one needs a GitLab token George would # have to mint by hand. The laptop's ~/.ssh/gitlab_ed25519 already pushes, and # kits merges only happen through the laptop's heavy-tier bridge anyway. # # Fast-forward only. If GitLab main has diverged it refuses and exits 1 rather # than force — a human looks. # # Installed as ~/.config/systemd/user/kits-gitlab-sync.{service,timer} # (every 10 min). Run by hand: scripts/kits-gitlab-sync.sh set -euo pipefail SRC=https://github.com/bitbaum/kits.git DST=git@gitlab.com:bitbaum/kits.git CACHE="${XDG_CACHE_HOME:-$HOME/.cache}/kits-gitlab-sync.git" [ -d "$CACHE" ] || git init -q --bare "$CACHE" g() { timeout 120 git -C "$CACHE" -c http.version=HTTP/1.1 "$@"; } src=$(g ls-remote "$SRC" refs/heads/main | cut -f1) dst=$(g ls-remote "$DST" refs/heads/main | cut -f1) [ -n "$src" ] || { echo "kits-gitlab-sync: cannot read $SRC main" >&2; exit 1; } [ "$src" = "$dst" ] && exit 0 g fetch -q "$SRC" "+refs/heads/main:refs/heads/src" g fetch -q "$DST" "+refs/heads/main:refs/heads/dst" if ! g merge-base --is-ancestor "$dst" "$src"; then echo "kits-gitlab-sync: GitLab main $dst is not an ancestor of $src — refusing to force" >&2 exit 1 fi g push -q "$DST" "$src:refs/heads/main" echo "kits-gitlab-sync: GitLab main ${dst:0:9} -> ${src:0:9}"