@@ -34,32 +34,14 @@ skip_if_clean() {
3434}
3535
3636format_branch_list_for_text () {
37- case $# in
38- 0)
39- echo " "
40- ;;
41- 1)
42- echo " \` $1 \` "
43- ;;
44- 2)
45- echo " \` $1 \` and \` $2 \` "
46- ;;
47- * )
48- local result=" "
49- local i=1
50- for arg in " $@ " ; do
51- if [ " $i " -eq " $# " ]; then
52- result+=" , and \` $arg \` "
53- elif [ " $i " -eq 1 ]; then
54- result=" \` $arg \` "
55- else
56- result+=" , \` $arg \` "
57- fi
58- (( i++ ))
59- done
60- echo " $result "
61- ;;
62- esac
37+ for (( i= 1 ; i<= $# ; i++ )) ; do
38+ case $i in
39+ 1) format=' `%s`' ;;
40+ $# ) format=' , and `%s`' ;;
41+ * ) format=' , `%s`' ;;
42+ esac
43+ printf " $format " " ${! i} "
44+ done
6345}
6446
6547update_direct_target () {
@@ -78,28 +60,36 @@ update_direct_target() {
7860 log_cmd git update-ref BEFORE_MERGE HEAD
7961 if ! log_cmd git merge --no-edit " origin/$MERGED_BRANCH " ; then
8062 CONFLICTS+=(" origin/$MERGED_BRANCH " )
63+ git merge --abort
8164 fi
8265 if ! log_cmd git merge --no-edit " ${SQUASH_COMMIT} ~" ; then
8366 CONFLICTS+=(" ${SQUASH_COMMIT} ~" )
67+ git merge --abort
8468 fi
8569
8670 if [[ " ${# CONFLICTS[@]} " -gt 0 ]]; then
87- gh pr comment -F - << EOF
88- "### ⚠️ Automatic update blocked by merge conflicts
89- I tried to merge \` $BASE \` into this branch while updating the PR stack and hit conflicts.
90-
91- #### How to resolve
92- \`\`\` bash
93- git fetch origin
94- git switch $CHILD
95- git merge $BASE # reproduce the conflict locally
96- # …fix files, add, commit…
97- git push --force-with-lease
98- \`\`\`
99-
100- Once you push, the bot will automatically resume the PR-stack update.
101- "
102- EOF
71+ {
72+ echo " ### ⚠️ Automatic update blocked by merge conflicts"
73+ echo
74+ echo -n " I tried to merge "
75+ format_branch_list_for_text " ${CONFLICTS[@]} "
76+ echo
77+ echo " into this branch while updating the PR stack and hit conflicts."
78+ echo " #### How to resolve"
79+ echo ' ```bash'
80+ echo " git fetch origin"
81+ echo " git switch $CHILD "
82+ for conflict in " ${CONFLICTS[@]} " ; do
83+ echo " git merge $conflict "
84+ echo " # ..."
85+ echo " # fix conflicts, for instance with ` git mergetool` "
86+ echo " # ..."
87+ echo " git commit"
88+ done
89+ echo " git push"
90+ echo ' ```'
91+ } | gh pr comment -F -
92+ gh pr edit --add-label autorestack-needs-conflict-resolution
10393 else
10494 log_cmd git merge --no-edit -s ours " $SQUASH_COMMIT "
10595 log_cmd git update-ref MERGE_RESULT " HEAD^{tree}"
0 commit comments