#!/usr/bin/env bash # Upstream synchronisation helper. # # `report` shows the accepted product commit, the tracked upstream remote and # how far behind it is. `candidate ` creates one `sync/dsh-` # branch by a normal merge and runs the component CI; it never pushes and never # rewrites `main`. set -euo pipefail cd "$(dirname "$0")/.." root="$PWD" command="${1:-report}" case "$command" in report) echo "application: $(git rev-parse HEAD)" echo "origin: $(git remote get-url origin)" echo "upstream: $(git remote get-url upstream)" git fetch --quiet upstream --tags echo "upstream head: $(git rev-parse upstream/master)" echo "behind: $(git rev-list --count HEAD..upstream/master) commit(s)" echo "accepted upstream bases:" git log --merges --grep='upstream' --format=' %h %s' -n 10 || true ;; candidate) target="${2:-}" if [ -z "$target" ]; then echo "usage: scripts/upstream.sh candidate " >&2 exit 2 fi git fetch --quiet upstream --tags resolved="$(git rev-parse "$target^{commit}")" branch="sync/dsh-$(git rev-parse --short "$resolved")" if git show-ref --verify --quiet "refs/heads/$branch"; then echo "branch already exists: $branch" >&2 exit 1 fi git switch -c "$branch" main if ! git merge --no-ff --no-commit "$resolved"; then echo "upstream merge has conflicts; resolve them, run scripts/ci.sh, and record the conflicts in the PR" >&2 exit 1 fi git commit -m "sync: merge DSH upstream $resolved" scripts/ci.sh echo "candidate ready on $branch (not pushed)" ;; *) echo "usage: scripts/upstream.sh [report|candidate ]" >&2 exit 2 ;; esac