Skip to content

Commit 2d9d9fc

Browse files
authored
Subtree update automation: do not use git subtree merge --squash (#292)
`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. By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.
1 parent 0269891 commit 2d9d9fc

File tree

1 file changed

+42
-12
lines changed

1 file changed

+42
-12
lines changed

Diff for: .github/workflows/update-subtree.yml

+42-12
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
@@ -151,20 +154,36 @@ jobs:
151154
if: ${{ env.MERGE_CONFLICTS != 'noop' && env.MERGE_PR_EXISTS == 'no' }}
152155
run: |
153156
cd verify-rust-std
154-
if ! git rev-parse --verify subtree/library; then
157+
# create-pull-request resets branches locally, implying that
158+
# `subtree/library` no longer is what the above instructions created.
159+
if [ "${SUBTREE_PR_EXISTS}" = "yes" ]; then
155160
git checkout -t -b subtree/library origin/update-subtree/library
161+
else
162+
git checkout subtree/library
163+
git reset --hard origin/update-subtree/library
156164
fi
157165
git checkout main
158166
167+
# Tell git about the correct merge base to use, which is the subtree
168+
# head that we last merged from.
169+
PREV_SUBTREE_HEAD=$(git log --grep="^git-subtree-split:" | egrep '^[[:space:]]+git-subtree-split:' | awk '{print $2;exit}')
170+
echo "Previous subtree head: ${PREV_SUBTREE_HEAD}"
171+
git replace --graft subtree/library ${PREV_SUBTREE_HEAD}
172+
git replace --graft main ${PREV_SUBTREE_HEAD}
173+
159174
# This command may fail, which will require human intervention.
160175
if ! git \
161176
-c user.name=gitbot -c user.email=git@bot \
162-
subtree merge --prefix=library subtree/library --squash; then
177+
merge -Xsubtree=library subtree/library; then
163178
echo "MERGE_CONFLICTS=yes" >> $GITHUB_ENV
164179
git -c user.name=gitbot -c user.email=git@bot commit -a -m "Merge from $NEXT_COMMIT_HASH with conflicts"
165180
else
166181
echo "MERGE_CONFLICTS=no" >> $GITHUB_ENV
167182
fi
183+
git replace -d subtree/library
184+
git replace -d main~1
185+
NEW_SUBTREE_HEAD=$(git rev-parse subtree/library)
186+
echo "NEW_SUBTREE_HEAD=${NEW_SUBTREE_HEAD}" >> $GITHUB_ENV
168187
169188
sed -i "s/^channel = \"nightly-.*\"/channel = \"nightly-${NEXT_TOOLCHAIN_DATE}\"/" rust-toolchain.toml
170189
git -c user.name=gitbot -c user.email=git@bot \
@@ -173,16 +192,22 @@ jobs:
173192
sed -i "s/commit = .*/commit = \"${KANI_COMMIT_HASH}\"/" tool_config/kani-version.toml
174193
git -c user.name=gitbot -c user.email=git@bot \
175194
commit -m "Update Kani version to ${KANI_COMMIT_HASH}" tool_config/kani-version.toml
195+
176196
- name: Create Pull Request without conflicts
177197
if: ${{ env.MERGE_CONFLICTS == 'no' && env.MERGE_PR_EXISTS == 'no' }}
178198
uses: peter-evans/create-pull-request@v7
179199
with:
180200
title: 'Merge subtree update for toolchain nightly-${{ env.NEXT_TOOLCHAIN_DATE }}'
181-
body: |
201+
body: >
182202
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.
203+
from ${{ env.CURRENT_TOOLCHAIN_DATE }} (rust-lang/rust@${{ env.CURRENT_COMMIT_HASH }})
204+
to ${{ env.NEXT_TOOLCHAIN_DATE }} (rust-lang/rust@${{ env.NEXT_COMMIT_HASH }}), inclusive.
185205
This is a clean merge, no conflicts were detected.
206+
**Do not remove or edit the following annotations:**
207+
208+
git-subtree-dir: library
209+
210+
git-subtree-split: ${{ env.NEW_SUBTREE_HEAD }}
186211
branch: sync-${{ env.NEXT_TOOLCHAIN_DATE }}
187212
delete-branch: true
188213
base: main
@@ -193,12 +218,17 @@ jobs:
193218
uses: peter-evans/create-pull-request@v7
194219
with:
195220
title: 'Merge subtree update for toolchain nightly-${{ env.NEXT_TOOLCHAIN_DATE }}'
196-
body: |
221+
body: >
197222
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)
223+
from ${{ env.CURRENT_TOOLCHAIN_DATE }} (rust-lang/rust@${{ env.CURRENT_COMMIT_HASH }})
224+
to ${{ env.NEXT_TOOLCHAIN_DATE }} (rust-lang/rust@${{ env.NEXT_COMMIT_HASH }}) (inclusive)
200225
into main. `git merge` resulted in conflicts, which require manual resolution.
201226
Files were commited with merge conflict markers.
227+
**Do not remove or edit the following annotations:**
228+
229+
git-subtree-dir: library
230+
231+
git-subtree-split: ${{ env.NEW_SUBTREE_HEAD }}
202232
branch: sync-${{ env.NEXT_TOOLCHAIN_DATE }}
203233
delete-branch: true
204234
base: main

0 commit comments

Comments
 (0)