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 git cherry-pick --no-rerere-autoupdate -Xtheirs \
50 $(git rev-list --first-parent main...origin/main)
52 [ $? -eq 0 ] && {
53 # Sanity-check header files which are found portably and remove them.
54 for h in 'sys\/queue.h' 'ssl\.h' 'endian\.h'
55 do
56 # Use git's pathspec notation to exclude matching on files
57 # where we *want* to keep those headers.
58 git grep -Li "$h" -- \
59 ':!maintscripts/**' \
60 ':!configure.ac' \
61 ':!gotweb/parse.y' \
62 ':!include/got_compat.h' | \
63 while read file
64 do
65 sed -i -e "/$h/d" "$file"
66 done
67 done
69 echo "Performing sanity build..."
70 ./autogen.sh >/dev/null 2>&1 && \
71 ./configure >/dev/null 2>&1 && \
72 make -j $(nproc) >/dev/null 2>&1 && {
73 echo " Passed!"
74 echo "Creating commit for portable changes..."
75 git commit -am "portable: remove include files found portably"
76 echo "...Merging branch to linux"
77 git checkout linux && git merge --ff-only - && {
78 echo "Pushing to GH..."
79 git push gh || die "Couldn't push linux to GH"
80 git checkout main && \
81 git push gh || die "Couldn't push main to GH"
82 }
83 } || die "Build failed"
84 }
86 echo "Wait for Cirrus-CI..."
87 echo "Then push main and linux to origin"