Skip to content

Commit 978f30b

Browse files
authored
chore: copy merge-lean-testing-pr script from Mathlib (#1192)
1 parent 4f7258c commit 978f30b

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

scripts/merge-lean-testing-pr.sh

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/usr/bin/env bash
2+
set -eu
3+
4+
# This scripts merges a `lean-pr-testing-NNNN` branch into `nightly-testing`.
5+
# This script is a copy of the same script in mathlib4, and should be kept in sync.
6+
# Note that Mathlib uses `lakefile.lean`, while Batteries uses `lakefile.toml`
7+
8+
if [ "$#" -ne 1 ]; then
9+
echo "Usage: $0 <PR number>"
10+
exit 1
11+
fi
12+
13+
PR_NUMBER=$1
14+
BRANCH_NAME="lean-pr-testing-$PR_NUMBER"
15+
16+
git checkout nightly-testing
17+
git pull --ff-only
18+
19+
if ! git merge origin/$BRANCH_NAME; then
20+
echo "Merge conflicts detected. Resolving conflicts in favor of current version..."
21+
git checkout --ours lean-toolchain lakefile.toml lake-manifest.json
22+
git add lean-toolchain lakefile.toml lake-manifest.json
23+
fi
24+
25+
sed "s/$BRANCH_NAME/nightly-testing/g" < lakefile.toml > lakefile.toml.new
26+
mv lakefile.toml.new lakefile.toml
27+
git add lakefile.toml
28+
29+
# Check for merge conflicts
30+
if git ls-files -u | grep -q '^'; then
31+
echo "Merge conflicts detected. Please resolve conflicts manually."
32+
git status
33+
exit 1
34+
fi
35+
36+
if ! lake update; then
37+
echo "Lake update failed. Please resolve conflicts manually."
38+
git status
39+
exit 1
40+
fi
41+
42+
# Add files touched by lake update
43+
git add lakefile.toml lake-manifest.json
44+
45+
# Attempt to commit. This will fail if there are conflicts.
46+
if git commit -m "merge $BRANCH_NAME"; then
47+
echo "Merge successful."
48+
git push
49+
echo "Pushed to github."
50+
exit 0
51+
else
52+
echo "Merge failed. Please resolve conflicts manually and push to github."
53+
git status
54+
exit 1
55+
fi

0 commit comments

Comments
 (0)