Skip to content

Commit 6a6a846

Browse files
committed
chore: rework backport for failures
1 parent 831f884 commit 6a6a846

File tree

1 file changed

+62
-9
lines changed

1 file changed

+62
-9
lines changed

tasks/backport.yaml

Lines changed: 62 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2024 Defense Unicorns
1+
# Copyright 2025 Defense Unicorns
22
# SPDX-License-Identifier: AGPL-3.0-or-later OR LicenseRef-Defense-Unicorns-Commercial
33

44
tasks:
@@ -57,22 +57,75 @@ tasks:
5757
git switch -c "${BRANCH}" "origin/${RB}"
5858
5959
C="$(echo "$COMMIT" | xargs)"
60-
echo "Cherry-picking ${C}"
61-
git cherry-pick -x "$C"
60+
echo "Cherry-picking ${C} into ${BRANCH}..."
6261
63-
git push -u origin "${BRANCH}"
64-
echo "Backport branch created: ${BRANCH}"
65-
66-
if [[ "${AUTO_PR}" == "true" ]] && command -v gh >/dev/null 2>&1; then
62+
# Suppress git output; on failure, show clear next steps instead.
63+
if ! git cherry-pick -x "$C" >/dev/null 2>&1; then
64+
echo
65+
echo "======================================================================"
66+
echo "Backport to ${RB} hit conflicts while cherry-picking ${C}."
67+
echo "You are now on branch: ${BRANCH}"
68+
echo
69+
echo "To resolve the conflicts and finish this backport, run (copy/paste):"
70+
echo
71+
echo " git status"
72+
echo " # edit files to resolve conflicts"
73+
echo " git add <files-you-resolved>"
74+
echo " git cherry-pick --continue"
75+
echo " git push -u origin ${BRANCH}"
76+
echo
6777
DEFAULT_TITLE="$(git log -1 --pretty=%s "$COMMIT" 2>/dev/null || echo "")"
6878
if [[ -z "${DEFAULT_TITLE}" ]]; then
6979
DEFAULT_TITLE="chore: backport of ${COMMIT}"
7080
fi
7181
TITLE="${DEFAULT_TITLE} (backport-${MINOR})"
7282
BODY="Backport of commit: ${COMMIT}"
73-
gh pr create --title "${TITLE}" --body "${BODY}" --base "${RB}" --head "${BRANCH}"
83+
84+
if command -v gh >/dev/null 2>&1; then
85+
cat <<EOF
86+
gh pr create \
87+
--title "${TITLE}" \
88+
--body "${BODY}" \
89+
--base "${RB}" \
90+
--head "${BRANCH}"
91+
EOF
92+
else
93+
echo " # After pushing, open a PR with base=${RB} and compare=${BRANCH}"
94+
fi
95+
96+
if [[ -n "${CURR_BRANCH}" ]]; then
97+
echo
98+
echo "After finishing the backport and pushing, you can return to your original branch with:"
99+
echo
100+
echo " git switch ${CURR_BRANCH}"
101+
fi
102+
echo "======================================================================"
103+
exit 1
104+
fi
105+
106+
git push -u origin "${BRANCH}" >/dev/null 2>&1
107+
108+
DEFAULT_TITLE="$(git log -1 --pretty=%s "$COMMIT" 2>/dev/null || echo "")"
109+
if [[ -z "${DEFAULT_TITLE}" ]]; then
110+
DEFAULT_TITLE="chore: backport of ${COMMIT}"
111+
fi
112+
TITLE="${DEFAULT_TITLE} (backport-${MINOR})"
113+
BODY="Backport of commit: ${COMMIT}"
114+
115+
echo "✅ Backport branch created and pushed: ${BRANCH} (base: ${RB})"
116+
117+
if [[ "${AUTO_PR}" == "true" ]] && command -v gh >/dev/null 2>&1; then
118+
gh pr create --title "${TITLE}" --body "${BODY}" --base "${RB}" --head "${BRANCH}" >/dev/null 2>&1 || true
119+
echo " PR opened via: gh pr create --title \"${TITLE}\" --body \"${BODY}\" --base \"${RB}\" --head \"${BRANCH}\""
74120
else
75-
echo "Open a PR with base=${RB} and compare=${BRANCH}"
121+
echo "To open a PR, run (copy/paste):"
122+
cat <<EOF
123+
gh pr create \
124+
--title "${TITLE}" \
125+
--body "${BODY}" \
126+
--base "${RB}" \
127+
--head "${BRANCH}"
128+
EOF
76129
fi
77130
done
78131

0 commit comments

Comments
 (0)