diff --git a/deploy/nexus/genome-raw-commit.sh b/deploy/nexus/genome-raw-commit.sh index 7d6ac2c..dae028e 100644 --- a/deploy/nexus/genome-raw-commit.sh +++ b/deploy/nexus/genome-raw-commit.sh @@ -87,13 +87,32 @@ for key in "${!G_FILES[@]}"; do summary="${summary}${summary:+; }${G_NAME[$key]}:${short}" done -# Pull in any remote advances (e.g. a merged wiki PR), then push +# Push to origin/. The vault is SCRATCH, so we never do an interactive rebase +# (which can conflict when the same raw file is edited repeatedly). Strategy: +# try a fast-forward push; if origin moved, re-apply our raw changes on top of a +# fresh origin/ and push again. Deterministic, conflict-free. git fetch -q origin -if git show-ref --verify --quiet "refs/remotes/origin/${GENOME_BASE}"; then - git rebase -q "origin/${GENOME_BASE}" \ - || { git rebase --abort 2>/dev/null || true; printf '{"status":"error","reason":"rebase-conflict","genome":"%s"}\n' "$genome"; exit 1; } +if ! git push -q "$clone_url" "HEAD:${GENOME_BASE}" 2>/dev/null; then + # origin advanced: capture our just-made tree for raw/, realign hard, re-apply, retry once. + tmp="$(mktemp -d)" + cp -a raw/. "$tmp"/ 2>/dev/null || true + git reset -q --hard "origin/${GENOME_BASE}" + git clean -q -fd + cp -a "$tmp"/. raw/ 2>/dev/null || true + rm -rf "$tmp" + git add -A -- raw/ + git reset -q -- raw/.stignore raw/.stfolder 2>/dev/null || true + if git diff --cached --quiet; then + # our content already matches origin -> nothing to push, report ok-noop-after-realign + printf '{"status":"ok","genome":"%s","base":"%s","commits":0,"head":"%s","summary":"already in sync after realign","files":[]}\n' \ + "$genome" "$GENOME_BASE" "$(git rev-parse --short HEAD)" + exit 0 + fi + git commit -q --author="${DEFAULT_AUTHOR_NAME} <${DEFAULT_AUTHOR_EMAIL}>" \ + -m "raw(${genome}): re-apply after realign" -- raw/ || true + git push -q "$clone_url" "HEAD:${GENOME_BASE}" \ + || { printf '{"status":"error","reason":"push-failed-after-realign","genome":"%s"}\n' "$genome"; exit 1; } fi -git push -q "$clone_url" "HEAD:${GENOME_BASE}" head="$(git rev-parse --short HEAD)" # `files` array: local (file://) and remote (Forgejo web) link for each committed raw