Skip to content

Commit d1b7eb8

Browse files
committed
Subtree update automation: do not use git subtree merge --squash
`git subtree merge --squash` will always reset the subtree to the state of the tree that is being merged from, which effectively eradicates all our local changes. This was just masked by merge conflicts arising as we were always attempted to merge from some long-ago version as we hadn't consistently kept "git-subtree-split" markers. This PR now amends the pull request descriptions to make sure we retain the necessary information and uses `git merge` instead of the subtree command.
1 parent 0269891 commit d1b7eb8

File tree

1 file changed

+34
-11
lines changed

1 file changed

+34
-11
lines changed

.github/workflows/update-subtree.yml

+34-11
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,14 @@ jobs:
137137
uses: peter-evans/create-pull-request@v7
138138
with:
139139
title: 'Update subtree/library to ${{ env.NEXT_TOOLCHAIN_DATE }}'
140-
body: |
140+
body: >
141141
This is an automated PR to update the subtree/library branch to the changes
142-
from ${{ env.CURRENT_TOOLCHAIN_DATE }} (${{ env.CURRENT_COMMIT_HASH }})
143-
to ${{ env.NEXT_TOOLCHAIN_DATE }} (${{ env.NEXT_COMMIT_HASH }}), inclusive.
144-
**Do not merge this PR using the merge queue. Instead, use the rebase strategy.**
142+
from ${{ env.CURRENT_TOOLCHAIN_DATE }} (rust-lang/rust@${{ env.CURRENT_COMMIT_HASH }})
143+
to ${{ env.NEXT_TOOLCHAIN_DATE }} (rust-lang/rust@${{ env.NEXT_COMMIT_HASH }}), inclusive.
144+
145+
**Review this PR as usual, but do not merge this PR using the GitHub web interface.
146+
Instead, once it is approved, use `git push` to literally push the changes to `subtree/library`
147+
without any rebase or merge.**
145148
branch: update-subtree/library
146149
delete-branch: true
147150
base: subtree/library
@@ -156,15 +159,25 @@ jobs:
156159
fi
157160
git checkout main
158161
162+
# Tell git about the correct merge base to use, which is the subtree
163+
# head that we last merged from.
164+
PREV_SUBTREE_HEAD=$(git log --grep="^git-subtree-split:" | egrep '^[[:space:]]+git-subtree-split:' | awk '{print $2;exit}')
165+
git replace --graft subtree/library ${PREV_SUBTREE_HEAD}
166+
git replace --graft main ${PREV_SUBTREE_HEAD}
167+
159168
# This command may fail, which will require human intervention.
160169
if ! git \
161170
-c user.name=gitbot -c user.email=git@bot \
162-
subtree merge --prefix=library subtree/library --squash; then
171+
merge -Xsubtree=library subtree/library; then
163172
echo "MERGE_CONFLICTS=yes" >> $GITHUB_ENV
164173
git -c user.name=gitbot -c user.email=git@bot commit -a -m "Merge from $NEXT_COMMIT_HASH with conflicts"
165174
else
166175
echo "MERGE_CONFLICTS=no" >> $GITHUB_ENV
167176
fi
177+
git replace -d subtree/library
178+
git replace -d main~1
179+
NEW_SUBTREE_HEAD=$(git rev-parse subtree/library)
180+
echo "NEW_SUBTREE_HEAD=${NEW_SUBTREE_HEAD}" >> $GITHUB_ENV
168181
169182
sed -i "s/^channel = \"nightly-.*\"/channel = \"nightly-${NEXT_TOOLCHAIN_DATE}\"/" rust-toolchain.toml
170183
git -c user.name=gitbot -c user.email=git@bot \
@@ -178,11 +191,16 @@ jobs:
178191
uses: peter-evans/create-pull-request@v7
179192
with:
180193
title: 'Merge subtree update for toolchain nightly-${{ env.NEXT_TOOLCHAIN_DATE }}'
181-
body: |
194+
body: >
182195
This is an automated PR to merge library subtree updates
183-
from ${{ env.CURRENT_TOOLCHAIN_DATE }} (${{ env.CURRENT_COMMIT_HASH }})
184-
to ${{ env.NEXT_TOOLCHAIN_DATE }} (${{ env.NEXT_COMMIT_HASH }}), inclusive.
196+
from ${{ env.CURRENT_TOOLCHAIN_DATE }} (rust-lang/rust@${{ env.CURRENT_COMMIT_HASH }})
197+
to ${{ env.NEXT_TOOLCHAIN_DATE }} (rust-lang/rust@${{ env.NEXT_COMMIT_HASH }}), inclusive.
185198
This is a clean merge, no conflicts were detected.
199+
**Do not remove or edit the following annotations:**
200+
201+
git-subtree-dir: library
202+
203+
git-subtree-split: ${{ env.NEW_SUBTREE_HEAD }}
186204
branch: sync-${{ env.NEXT_TOOLCHAIN_DATE }}
187205
delete-branch: true
188206
base: main
@@ -193,12 +211,17 @@ jobs:
193211
uses: peter-evans/create-pull-request@v7
194212
with:
195213
title: 'Merge subtree update for toolchain nightly-${{ env.NEXT_TOOLCHAIN_DATE }}'
196-
body: |
214+
body: >
197215
This is an automated PR to merge library subtree updates
198-
from ${{ env.CURRENT_TOOLCHAIN_DATE }} (${{ env.CURRENT_COMMIT_HASH }})
199-
to ${{ env.NEXT_TOOLCHAIN_DATE }} (${{ env.NEXT_COMMIT_HASH }}) (inclusive)
216+
from ${{ env.CURRENT_TOOLCHAIN_DATE }} (rust-lang/rust@${{ env.CURRENT_COMMIT_HASH }})
217+
to ${{ env.NEXT_TOOLCHAIN_DATE }} (rust-lang/rust@${{ env.NEXT_COMMIT_HASH }}) (inclusive)
200218
into main. `git merge` resulted in conflicts, which require manual resolution.
201219
Files were commited with merge conflict markers.
220+
**Do not remove or edit the following annotations:**
221+
222+
git-subtree-dir: library
223+
224+
git-subtree-split: ${{ env.NEW_SUBTREE_HEAD }}
202225
branch: sync-${{ env.NEXT_TOOLCHAIN_DATE }}
203226
delete-branch: true
204227
base: main

0 commit comments

Comments
 (0)