deploy/nexus: Refactor raw commit push strategy for robustness
This commit is contained in:
parent
d26fdc857a
commit
a3de9f673f
1 changed files with 24 additions and 5 deletions
|
|
@ -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/<base>. 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/<base> 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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue