fix(recipe-upgrade): extend open upgrade PRs by commit-on-top, no force-push
Instead of force-pushing HEAD onto the existing PR branch (history rewrite), add a commit ON TOP of the branch tip (fast-forward) when it already exists, so the PR's history is preserved and it re-tests. Fresh branches still push normally. The only remaining force-push is the mirror-main->upstream sync (intentional mirroring), never a PR branch. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@ -19,9 +19,11 @@
|
||||
# never reflected it.
|
||||
#
|
||||
# Default mode (open a PR — preconditions: HEAD has the upgrade commit(s)):
|
||||
# - If an open UPGRADE PR already exists for this recipe (branch 'upgrade-*'), the new work is
|
||||
# pushed onto THAT PR's branch and the PR is updated + re-tested — ONE evolving upgrade PR per
|
||||
# recipe, NOT a second parallel PR. Otherwise a fresh 'upgrade-<version>' branch + PR is opened.
|
||||
# - If an open UPGRADE PR already exists for this recipe (branch 'upgrade-*'), the new work is added
|
||||
# as a commit ON TOP of THAT PR's branch (a fast-forward — NO force-push) and the PR is updated +
|
||||
# re-tested — ONE evolving upgrade PR per recipe, NOT a second parallel PR. Otherwise a fresh
|
||||
# 'upgrade-<version>' branch + PR is opened. (The only force-push here is the mirror-main sync
|
||||
# above, which intentionally mirrors upstream main; PR branches are never force-pushed.)
|
||||
# - Unrelated open PRs (e.g. a backup fix) are NEVER closed or touched — left for the operator.
|
||||
# - Only PRs already merged into upstream main are closed (no-op merges) — see above.
|
||||
#
|
||||
@ -140,8 +142,24 @@ else
|
||||
BRANCH="upgrade-$(git rev-parse --short HEAD)"
|
||||
fi
|
||||
|
||||
echo "→ Pushing branch '${BRANCH}'..."
|
||||
git push --force gitea "HEAD:refs/heads/${BRANCH}"
|
||||
# Land the work on the PR branch WITHOUT force-pushing. If the branch already exists (extend case, or
|
||||
# a stale same-named branch), add a commit ON TOP of its tip — a fast-forward, so the PR's history is
|
||||
# preserved and it re-tests. Otherwise push a fresh branch.
|
||||
if git rev-parse --verify --quiet "refs/remotes/gitea/${BRANCH}" >/dev/null; then
|
||||
EXIST_TIP=$(git rev-parse "refs/remotes/gitea/${BRANCH}")
|
||||
if [ "$(git rev-parse 'HEAD^{tree}')" = "$(git rev-parse "${EXIST_TIP}^{tree}")" ]; then
|
||||
echo "→ '${BRANCH}' already has this exact tree — nothing new to push (will still re-test)."
|
||||
else
|
||||
ONTOP=$(GIT_AUTHOR_NAME="${GITEA_USERNAME}" GIT_AUTHOR_EMAIL="${GITEA_USERNAME}@git.autonomic.zone" \
|
||||
GIT_COMMITTER_NAME="${GITEA_USERNAME}" GIT_COMMITTER_EMAIL="${GITEA_USERNAME}@git.autonomic.zone" \
|
||||
git commit-tree "$(git rev-parse 'HEAD^{tree}')" -p "${EXIST_TIP}" -m "${LATEST_MSG}")
|
||||
echo "→ Adding the new work on top of '${BRANCH}' (fast-forward, no force-push)..."
|
||||
git push gitea "${ONTOP}:refs/heads/${BRANCH}"
|
||||
fi
|
||||
else
|
||||
echo "→ Pushing new branch '${BRANCH}'..."
|
||||
git push gitea "HEAD:refs/heads/${BRANCH}"
|
||||
fi
|
||||
|
||||
PR_BODY="${RECIPE_PR_BODY:-$(printf 'Recipe upgrade.\n\nCommits on top of upstream main:\n\n%s\n' "$(git log origin/main..HEAD --pretty='- %h %s')")}"
|
||||
PR_BODY="${PR_BODY}
|
||||
|
||||
Reference in New Issue
Block a user