2 ### automerge - automatically merge the Emacs release branch to master
4 ## Copyright (C) 2018 Free Software Foundation, Inc.
6 ## Author: Glenn Morris <rgm@gnu.org>
8 ## This file is part of GNU Emacs.
10 ## GNU Emacs is free software: you can redistribute it and/or modify
11 ## it under the terms of the GNU General Public License as published by
12 ## the Free Software Foundation, either version 3 of the License, or
13 ## (at your option) any later version.
15 ## GNU Emacs is distributed in the hope that it will be useful,
16 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ## GNU General Public License for more details.
20 ## You should have received a copy of the GNU General Public License
21 ## along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
25 ## Automatically merge the Emacs release branch to master.
26 ## If the merge succeeds, optionally build and test the results,
29 ## Have a dedicated git directory just for this.
30 ## Have a cron job that calls this script with -r -p.
32 ## Modifying a running shell script can have unpredictable results,
33 ## so the paranoid will first make a copy of this script, and then run
34 ## it with the -d option in the repository directory, in case a pull
35 ## updates this script while it is working.
37 die
() # write error to stderr and exit
39 [ $# -gt 0 ] && echo "$PN: $@" >&2
43 PN
=${0##*/} # basename of script
46 [ "$PD" = "$0" ] && PD
=.
# if PATH includes PWD
51 Usage: ${PN} [-b] [-d] [-e emacs] [-n nmin] [-p] [-r] [-t] [-- mflags]
52 Merge the Emacs release branch to master.
53 Passes any non-option args to make (eg -- -j2).
55 -d: no initial cd to parent of script directory
56 -e: Emacs executable to use for the initial merge (default $emacs)
57 -n: minimum number of commits to try merging (default $nmin)
58 -b: try to build after merging
59 -t: try to check after building
60 -p: if merge, build, check all succeed, push when finished (caution!)
61 -r: start by doing a hard reset (caution!) and pull
78 while getopts ":hbde:n:pqrt" option
; do
98 (\?) die
"Bad option -$OPTARG" ;;
100 (:) die
"Option -$OPTARG requires an argument" ;;
102 (*) die
"getopts error" ;;
105 shift $
(( --OPTIND ))
110 cd $PD # this should be the admin directory
114 [ -d admin
] || die
"Could not locate admin directory"
116 [ -e .git
] || die
"No .git"
119 ## Does not work 100% because a lot of Emacs batch output comes on
121 [ "$quiet" ] && exec 1> /dev
/null
124 [ "$push" ] && test=1
125 [ "$test" ] && build
=1
130 trap "rm -f $tempfile 2> /dev/null" EXIT
133 [ -e Makefile
] && [ "$build" ] && {
135 make maintainer-clean
>& /dev
/null
141 git
reset -q --hard origin
/master || die
"reset error"
144 git pull
-q --ff-only || die
"pull error"
148 rev=$
(git rev-parse HEAD
)
150 [ $
(git rev-parse @
{u
}) = $rev ] || die
"Local state does not match origin"
157 if $emacs --batch -Q -l .
/admin
/gitmerge.el \
158 --eval "(setq gitmerge-minimum-missing $nmin)" -f gitmerge \
159 >|
$tempfile 2>&1; then
164 grep -E "Nothing to merge|Number of missing commits" $tempfile && \
177 [ "$build" ] ||
exit 0
180 echo "Running autoreconf..."
182 autoreconf
-i -I m4 2>|
$tempfile
186 ## Annoyingly, autoreconf puts the "installing `./foo' messages on stderr.
187 if [ "$quiet" ]; then
188 grep -v 'installing `\.' $tempfile 1>&2
193 [ $retval -ne 0 ] && die
"autoreconf error"
196 echo "Running ./configure..."
198 ## Minimize required packages.
199 .
/configure
--without-x || die
"configure error"
204 make "$@" || die
"make error"
206 echo "Build finished ok"
209 [ "$test" ] ||
exit 0
214 ## We just want a fast pass/fail, we don't want to debug.
215 make "$@" check TEST_LOAD_EL
=no || die
"check error"
217 echo "Tests finished ok"
220 [ "$push" ] ||
exit 0
223 ## In case someone else pushed while we were working.
224 echo "Checking for remote changes..."
225 git fetch || die
"fetch error"
227 [ $
(git rev-parse @
{u
}) = $rev ] ||
{
229 echo "Upstream has changed"
231 ## Rebasing would be incorrect, since it would rewrite the
232 ## (already published) release branch commits.
233 ## Ref eg http://lists.gnu.org/r/emacs-devel/2014-12/msg01435.html
234 ## Instead, we throw away what we just did, and do the merge again.
236 git
reset --hard $rev
239 git pull
--ff-only || die
"pull error"
243 ## If the merge finished ok again, we don't bother doing a second
248 git push || die
"push error"
253 ### automerge ends here