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