Blob


1 #!/bin/bash
2 #
3 # Script to sync changes from upstream to -portable
4 #
5 # This script is under the same licence as gameoftrees itself.
7 die()
8 {
9 echo "$@" >&2
10 exit 1
11 }
13 [ -z "$(git status --porcelain)" ] || die "Working tree is not clean"
15 echo "Updating main from origin..."
17 # Update our copy of main
18 git checkout -q main && \
19 git fetch -q -n gh >/dev/null 2>&1
20 git fetch -q -n upstream >/dev/null 2>&1 && \
21 git reset -q --hard upstream/main || {
22 die "Couldn't fetch from main and reset to that branch"
23 }
25 # Gather a list of commits to cherry-pick.
26 # Don't proceed with no commits.
27 commitc="$(git rev-list --count main...origin/main)"
28 [ -z "$commitc" -o "$commitc" -eq 0 ] && {
29 echo "All commits uptodate. Nothing to cherry-pick"
30 exit
31 }
33 # Create a branch from linux (which is where the result of the cherry-picks
34 # will ultimately end up, but we do this work on a topic branch so that we can
35 # perform CI on it, and not break the 'linux' branch.
37 echo "Creating sync branch..."
38 git branch -q -D syncup >/dev/null 2>&1
39 git checkout -q linux && git checkout -q -b syncup || {
40 die "Can't checkout syncup branch"
41 }
43 echo "The following ($commitc) commits will be cherry-picked..."
44 git log --oneline main...origin/main
46 read -p "Proceed? [Y/n]: " resp
48 [ "$resp" = "N" -o "$resp" = "n" ] && exit
50 # Pick the commits in reverse order.
51 git rev-list --reverse --first-parent main...origin/main | \
52 git cherry-pick --stdin --no-rerere-autoupdate -Xtheirs
54 [ $? -eq 0 ] && {
55 # Sanity-check header files which are found portably and remove them.
56 for h in 'sys\/queue.h' 'ssl\.h' 'endian\.h'
57 do
58 # Use git's pathspec notation to exclude matching on files
59 # where we *want* to keep those headers.
60 git grep -Li "$h" -- \
61 ':!maintscripts/**' \
62 ':!configure.ac' \
63 ':!gotweb/parse.y' \
64 ':!include/got_compat.h' | \
65 while read file
66 do
67 sed -i -e "/$h/d" "$file"
68 done
69 done
71 echo "Performing sanity build..."
72 ./autogen.sh >/dev/null 2>&1 && \
73 ./configure >/dev/null 2>&1 && \
74 make -j $(nproc) >/dev/null 2>&1 && {
75 echo " Passed!"
76 echo "Creating commit for portable changes..."
77 git commit -am "portable: remove include files found portably"
78 echo "...Merging branch to linux"
79 git checkout linux && git merge --ff-only - && {
80 echo "Pushing to GH..."
81 git push gh || die "Couldn't push linux to GH"
82 git checkout main && \
83 git push gh || die "Couldn't push main to GH"
84 }
85 } || die "Build failed"
86 }
88 echo "Wait for Cirrus-CI..."
89 echo "Then push main and linux to origin"