]> git.xonotic.org Git - xonotic/xonotic.git/blob - all
9d48c58ba6d5c38c948aeac26b577f08678146d9
[xonotic/xonotic.git] / all
1 #!/bin/sh
2 # vim: filetype=zsh
3
4 set -e
5
6 # I use this in EVERY shell script ;)
7 LF="
8 "
9
10 d00=`pwd`
11 while ! [ -f ./all ]; do
12         if [ x"`pwd`" = x"/" ]; then
13                 echo "Cannot find myself."
14                 echo "Please run this script with the working directory inside a Xonotic checkout."
15                 exit 1
16         fi
17         cd ..
18 done
19 d0=`pwd`
20 SELF="$d0/all"
21
22 # If we are on WINDOWS:
23 case "$0" in
24         all|*/all)
25                 case "`uname`" in
26                         MINGW*|Win*)
27                                 # Windows hates users. So this script has to copy itself elsewhere first...
28                                 tname=
29                                 cp "$SELF" ../all.xonotic.sh
30                                 export WE_HATE_OUR_USERS=1
31                                 exec ../all.xonotic.sh "$@"
32                                 ;;
33                 esac
34                 ;;
35 esac
36
37 msg()
38 {
39         echo "\e[1m$*\e[m"
40 }
41
42 checksum()
43 {
44         if [ -x /usr/bin/md5sum ]; then
45                 /usr/bin/md5sum "$@"
46         elif [ -x /bin/md5sum ]; then
47                 /bin/md5sum "$@"
48         elif [ -x /usr/bin/cksum ]; then
49                 /usr/bin/cksum "$@"
50         else
51                 echo "NOCHECKSUM"
52         fi
53 }
54
55 self=`checksum "$SELF"`
56 checkself()
57 {
58         self_new=`checksum "$SELF"`
59         if [ x"$self" != x"$self_new" ]; then
60                 msg "./all has changed."
61                 if [ -z "$XONOTIC_FORBID_RERUN_ALL" ]; then
62                         msg "Rerunning the requested operation to make sure."
63                         export XONOTIC_FORBID_RERUN_ALL=1
64                         exec "$SELF" "$@"
65                 else
66                         msg "Please try $SELF update, and then retry your requested operation."
67                         exit 1
68                 fi
69         fi
70         return 0
71 }
72
73 verbose()
74 {
75         msg "+ $*"
76         "$@"
77 }
78
79 visible_repo_name()
80 {
81         case "$1" in
82                 .)
83                         echo "the root directory"
84                         ;;
85                 *)
86                         echo "\"$1\""
87                         ;;
88         esac
89 }
90
91 check_mergeconflict()
92 {
93         if git ls-files -u | grep ' 1   '; then
94                 echo
95                 echo "MERGE CONFLICT."
96                 echo "change into the \"$1\" project directory, and then:"
97                 echo "- edit the files mentioned above with your favorite editor,"
98                 echo "  and fix the conflicts (marked with <<<<<<< blocks)"
99                 echo "- for binary files, you can select the files using"
100                 echo "  git checkout --ours or git checkout --theirs"
101                 echo "- when done with a file, 'git add' the file"
102                 echo "- when done, 'git commit'"
103                 echo
104                 exit 1
105         fi
106 }
107
108 yesno()
109 {
110         yesno=
111         while [ x"$yesno" != x"y" -a x"$yesno" != x"n" ]; do
112                 eval "$2"
113                 echo "$1"
114                 IFS= read -r yesno
115         done
116         [ x"$yesno" = x"y" ]
117 }
118
119 enter()
120 {
121         $2 cd "$1"
122         check_mergeconflict "$1"
123 }
124
125 repos_urls="
126 .                             |                                                   | master      |
127 data/xonotic-data.pk3dir      |                                                   | master      |
128 data/xonotic-maps.pk3dir      |                                                   | master      |
129 data/xonotic-music.pk3dir     |                                                   | master      |
130 data/xonotic-nexcompat.pk3dir |                                                   | master      |
131 mediasource                   |                                                   | master      |
132 darkplaces                    |                                                   | div0-stable | svn
133 fteqcc                        | git://github.com/Blub/qclib.git                   | master      |
134 div0-gittools                 | git://git.icculus.org/divverent/div0-gittools.git | master      |
135 netradiant                    |                                                   | master      |
136 "
137 # todo: in darkplaces, change repobranch to div0-stable
138
139 repos=`echo "$repos_urls" | grep . | cut -d '|' -f 1 | tr -d ' '`
140
141 base=`git config remote.origin.url`
142 case "$base" in
143         */xonotic.git)
144                 base=${base%xonotic.git}
145                 ;;
146         *)
147                 echo "The main repo is not xonotic.git, what have you done?"
148                 exit 1
149                 ;;
150 esac
151
152 repourl()
153 {
154         t=`echo "$repos_urls" | grep "^$1 " | cut -d '|' -f 2 | tr -d ' '`
155         if [ -n "$t" ]; then
156                 case "$t" in
157                         *://*)
158                                 echo "$t"
159                                 ;;
160                         *)
161                                 echo "$base$t"
162                                 ;;
163                 esac
164         else
165                 if [ x"$1" = x"." ]; then
166                         echo "$base""xonotic.git"
167                 else
168                         echo "$base${1##*/}.git"
169                 fi
170         fi
171 }
172
173 repobranch()
174 {
175         t=`echo "$repos_urls" | grep "^$1 " | cut -d '|' -f 3 | tr -d ' '`
176         if [ -n "$t" ]; then
177                 echo "$t"
178         else
179                 echo "master"
180         fi
181 }
182
183 repoflags()
184 {
185         echo "$repos_urls" | grep "^$1 " | cut -d '|' -f 4 | tr -d ' '
186         echo "$t"
187 }
188
189 repos=`for d in $repos; do
190         p="${d%dir}"
191         if [ x"$p" = x"$d" ] || [ -d "$d" ] || ! [ -f "$p" ]; then
192                 echo "$d"
193         fi
194 done`
195
196 if [ "$#" = 0 ]; then
197         set -- help
198 fi
199 cmd=$1
200 shift
201
202 case "$cmd" in
203         update|pull)
204                 allow_pull=true
205                 if [ x"$1" = x"-N" ]; then
206                         allow_pull=false
207                 fi
208                 for d in $repos; do
209                         url=`repourl "$d"`
210                         branch=`repobranch "$d"`
211                         if [ -d "$d0/$d" ]; then
212                                 if $allow_pull; then
213                                         enter "$d0/$d" verbose
214                                         verbose git config remote.origin.url "$url"
215                                         verbose git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
216
217                                         r=`git symbolic-ref HEAD`
218                                         r=${r#refs/heads/}
219                                         if git config branch.$r.remote >/dev/null 2>&1; then
220                                                 if ! verbose git pull; then
221                                                         check_mergeconflict "$d"
222                                                         echo "Pulling failed. Press ENTER to continue, or Ctrl-C to abort."
223                                                         read -r DUMMY
224                                                 fi
225                                         fi
226
227                                         cd "$d00"
228                                         checkself "$cmd" "$@"
229                                         cd "$d0/$d"
230                                         verbose git remote prune origin
231                                         cd "$d0"
232                                 fi
233                         else
234                                 verbose git clone "$url" "$d0/$d"
235                                 enter "$d0/$d" verbose
236                                 if [ "$branch" != "master" ]; then
237                                         verbose git checkout --track -b "$branch" origin/"$branch"
238                                 fi
239                                 cd "$d0"
240                         fi
241                 done
242                 ;;
243         update-maps)
244                 misc/tools/xonotic-map-compiler-autobuild download
245                 ;;
246         checkout|switch)
247                 remote=$1
248                 branch=$2
249                 if [ -z "$branch" ]; then
250                         branch=$remote
251                         remote=origin
252                 fi
253                 exists=false
254                 for d in $repos; do
255                         enter "$d0/$d" verbose
256                         b=$branch
257                         if [ -n "$b" ] && git rev-parse "refs/heads/$b" >/dev/null 2>&1; then
258                                 exists=true
259                                 verbose git checkout "$b"
260                         elif [ -n "$b" ] && git rev-parse "refs/remotes/$remote/$b" >/dev/null 2>&1; then
261                                 exists=true
262                                 verbose git checkout --track -b "$b" "$remote/$b"
263                         else
264                                 b=`repobranch "$d"`
265                                 if git rev-parse "refs/heads/$b" >/dev/null 2>&1; then
266                                         exists=true
267                                         verbose git checkout "$b"
268                                 elif git rev-parse "refs/remotes/$remote/$b" >/dev/null 2>&1; then
269                                         exists=true
270                                         verbose git checkout --track -b "$b" "$remote/$b"
271                                 else
272                                         echo "WTF? Not even branch $b doesn't exist in $d"
273                                         exit 1
274                                 fi
275                         fi
276                         cd "$d00"
277                         checkself "$cmd" "$@"
278                         cd "$d0"
279                 done
280                 if ! $exists; then
281                         echo "The requested branch was not found in any repository."
282                 fi
283                 exec "$SELF" branch
284                 ;;
285         branch)
286                 remote=$1
287                 branch=$2
288                 srcbranch=$3
289                 if [ -z "$branch" ]; then
290                         branch=$remote
291                         remote=origin
292                 fi
293                 if [ -z "$branch" ]; then
294                         for d in $repos; do
295                                 enter "$d0/$d"
296                                 r=`git symbolic-ref HEAD`
297                                 r=${r#refs/heads/}
298                                 echo "$d is at $r"
299                                 cd "$d0"
300                         done
301                 else
302                         for d in $repos; do
303                                 dv=`visible_repo_name "$d"`
304                                 enter "$d0/$d" verbose
305                                 if git rev-parse "refs/heads/$branch" >/dev/null 2>&1; then
306                                         echo "Already having this branch in $dv."
307                                 else
308                                         if yesno "Branch in $dv?"; then
309                                                 if [ -n "$srcbranch" ]; then
310                                                         b=$srcbranch
311                                                 else
312                                                         b=origin/"`repobranch "$d"`"
313                                                         verbose git fetch origin || true
314                                                 fi
315                                                 # TODO do this without pushing
316                                                 verbose git checkout -b "$branch" "$b"
317                                                 verbose git config "branch.$branch.remote" "$remote"
318                                                 verbose git config "branch.$branch.merge" "refs/heads/$branch"
319                                         fi
320                                 fi
321                                 cd "$d0"
322                         done
323                         "$SELF" branch
324                 fi
325                 ;;
326         branches)
327                 for d in $repos; do
328                         enter "$d0/$d"
329                         echo "In $d:"
330                         git branch -a -v -v | cut -c 3- | while read -r BRANCH REV UPSTREAM TEXT; do
331                                 case "$UPSTREAM" in
332                                         \[*)
333                                                 UPSTREAM=${UPSTREAM#\[}
334                                                 UPSTREAM=${UPSTREAM%\]}
335                                                 UPSTREAM=${UPSTREAM%:*}
336                                                 ;;
337                                         *)
338                                                 TEXT="$UPSTREAM $TEXT"
339                                                 UPSTREAM=
340                                                 ;;
341                                 esac
342                                 if [ x"$REV" = x"->" ]; then
343                                         continue
344                                 fi
345                                 BRANCH=${BRANCH#remotes/}
346                                 echo -n "  $BRANCH"
347                                 if [ -n "$UPSTREAM" ]; then
348                                         echo -n " (tracking $UPSTREAM)"
349                                 fi
350                                 #echo " $TEXT"
351                                 echo
352                         done
353                 done
354                 ;;
355         branches_short)
356                 for d in $repos; do
357                         cd "$d0/$d" # am in a pipe, shouldn't use enter
358                         git branch -a -v -v | cut -c 3- | sed "s,^,$d ,"
359                         cd "$d0"
360                 done | {
361                         branches_list=
362                         # branches_repos_*=
363                         while read -r d BRANCH REV UPSTREAM TEXT; do
364                                 case "$UPSTREAM" in
365                                         \[*)
366                                                 UPSTREAM=${UPSTREAM#\[}
367                                                 UPSTREAM=${UPSTREAM%\]}
368                                                 UPSTREAM=${UPSTREAM%:*}
369                                                 ;;
370                                         *)
371                                                 TEXT="$UPSTREAM $TEXT"
372                                                 UPSTREAM=
373                                                 ;;
374                                 esac
375                                 if [ x"$REV" = x"->" ]; then
376                                         continue
377                                 fi
378                                 BRANCH=${BRANCH#remotes/}
379                                 ID=`echo "$BRANCH" | tr -c "A-Za-z0-9." "_"`
380                                 branches_list="$branches_list $BRANCH" # TEH SORT MAKEZ IT UNIEQ
381                                 eval "r=\$branches_repos_$ID"
382                                 r="$r $d:$UPSTREAM"
383                                 eval "branches_repos_$ID=\$r"
384                         done
385                         echo -n "$branches_list" | xargs -n 1 echo | sort -u | while IFS= read -r BRANCH; do
386                                 ID=`echo "$BRANCH" | tr -c "A-Za-z0-9." "_"`
387                                 eval "r=\$branches_repos_$ID"
388                                 echo "$BRANCH: $r"
389                         done
390                 }
391                 ;;
392         merge)
393                 for d in $repos; do
394                         dv=`visible_repo_name "$d"`
395                         enter "$d0/$d" verbose
396                         r=`git symbolic-ref HEAD`
397                         r=${r#refs/heads/}
398                         if git log HEAD..origin/"`repobranch "$d"`" | grep .; then
399                                 # we have uncommitted changes
400                                 if yesno "Could merge from \"`repobranch "$d"`\" into \"$r\" in $dv. Do it?"; then
401                                         if ! verbose git merge origin/"`repobranch "$d"`"; then
402                                                 check_mergeconflict "$d"
403                                                 exit 1 # this should ALWAYS be fatal
404                                         fi
405                                 fi
406                         fi
407                         cd "$d0"
408                 done
409                 ;;
410         push|commit)
411                 submit=$1
412                 for d in $repos; do
413                         dv=`visible_repo_name "$d"`
414                         enter "$d0/$d" verbose
415                         r=`git symbolic-ref HEAD`
416                         r=${r#refs/heads/}
417                         if git diff HEAD | grep .; then
418                                 # we have uncommitted changes
419                                 if yesno "Uncommitted changes in \"$r\" in $dv. Commit?"; then
420                                         verbose git commit -a
421                                 fi
422                         fi
423                         rem=`git config "branch.$r.remote" || echo origin`
424                         bra=`git config "branch.$r.merge" || echo "$r"`
425                         upstream="$rem/$bra"
426                         if ! [ git rev-parse "$upstream" ]; then
427                                 upstream="`repobranch "$d"`"
428                         fi
429                         if git log "$upstream".."$r" | grep .; then
430                                 if yesno "Push \"$r\" in $dv?"; then
431                                         verbose git push "$rem" HEAD
432                                 fi
433                         fi
434                         if [ x"$submit" = x"-s" ]; then
435                                 case "$r" in
436                                         */*)
437                                                 verbose git push "$rem" HEAD:"${bra%%/*}/finished/${bra#*/}"
438                                                 ;;
439                                 esac
440                         fi
441                         cd "$d0"
442                 done
443                 ;;
444         compile)
445                 if [ -n "$WE_HATE_OUR_USERS" ]; then
446                         TARGETS="sv-debug cl-debug"
447                         if [ -z "$CC" ]; then
448                                 export CC=gcc
449                         fi
450                 elif [ x"`uname`" = x"Darwin" ] && ( [ -d /Library/Frameworks/SDL.framework ] || [ -d $(HOME)/Library/Frameworks/SDL.framework ] ); then
451                         # AGL is broken in Snow Leopard, so let's default to SDL if it is available.
452                         TARGETS="sv-debug sdl-debug"
453                 else
454                         TARGETS="sv-debug cl-debug sdl-debug"
455                 fi
456                 case "$1" in
457                         -c)
458                                 clean=true
459                                 shift
460                                 ;;
461                         *)
462                                 clean=false
463                                 ;;
464                 esac
465                 case "$1" in
466                         sdl)
467                                 TARGETS="sdl-debug"
468                                 shift
469                                 ;;
470                         glx|agl|wgl)
471                                 TARGETS="cl-debug"
472                                 shift
473                                 ;;
474                         dedicated)
475                                 TARGETS="sv-debug"
476                                 shift
477                                 ;;
478                 esac
479                 if [ -z "$MAKEFLAGS" ]; then
480                         if [ -f /proc/cpuinfo ]; then
481                                 ncpus=$((`grep -c '^processor   :' /proc/cpuinfo`+0))
482                                 if [ $ncpus -gt 1 ]; then
483                                         MAKEFLAGS=-j$ncpus
484                                 fi
485                         fi
486                         case "`uname`" in
487                                 Linux|*BSD)
488                                         MAKEFLAGS="$MAKEFLAGS DP_LINK_TO_LIBJPEG=1"
489                                         ;;
490                         esac
491                         if [ -n "$WE_HATE_OUR_USERS" ]; then
492                                 MAKEFLAGS="$MAKEFLAGS DP_MAKE_TARGET=mingw"
493                         fi
494                 fi
495                 enter "$d0/fteqcc" verbose
496                 if $clean; then
497                         verbose make $MAKEFLAGS clean
498                 fi
499                 verbose make $MAKEFLAGS
500                 enter "$d0/data/xonotic-data.pk3dir" verbose
501                 if $clean; then
502                         verbose make $MAKEFLAGS clean
503                 fi
504                 verbose make FTEQCC="$d0/fteqcc/fteqcc.bin" "$@" $MAKEFLAGS clean
505                 verbose make FTEQCC="$d0/fteqcc/fteqcc.bin" "$@" $MAKEFLAGS
506                 enter "$d0/darkplaces" verbose
507                 if $clean; then
508                         verbose make $MAKEFLAGS clean
509                 fi
510                 for T in $TARGETS; do
511                         verbose make $MAKEFLAGS "$@" "$T"
512                 done
513                 verbose "$SELF" update-maps
514                 ;;
515         run)
516                 if [ -n "$WE_HATE_OUR_USERS" ]; then
517                         client=
518                         export PATH="$d0/misc/buildfiles/w32:$PATH"
519                 elif [ x"`uname`" = x"Darwin" ]; then
520                         export DYLD_LIBRARY_PATH="$d0/misc/buildfiles/osx/Xonotic-SDL.app/Contents/MacOS"
521                         client=-sdl
522                 else
523                         client=-sdl
524                 fi
525                 case "$1" in
526                         sdl|glx|agl|dedicated)
527                                 client=-$1
528                                 shift
529                                 ;;
530                         wgl)
531                                 client=
532                                 shift
533                                 ;;
534                 esac
535                 if ! [ -x "darkplaces/darkplaces$client" ]; then
536                         if [ -x "darkplaces/darkplaces$client.exe" ]; then
537                                 client=$client.exe
538                         else
539                                 echo "Client darkplaces/darkplaces$client not found, aborting"
540                                 exit 1
541                         fi
542                 fi
543                 set -- "darkplaces/darkplaces$client" -nexuiz -customgamename Xonotic -customgamedirname1 data -customgamedirname2 "" -customgamescreenshotname xonotic -customgameuserdirname xonotic "$@"
544
545                 # if pulseaudio is running: USE IT
546                 if [ -z "$SDL_AUDIODRIVER" ] && ! [ -n "$WE_HATE_OUR_USERS" ] && ! [ x"`uname`" = x"Darwin" ]; then
547                         if ps -C pulseaudio >/dev/null; then
548                                 if ldd /usr/lib/libSDL.so 2>/dev/null | grep pulse >/dev/null; then
549                                         export SDL_AUDIODRIVER=pulse
550                                 fi
551                         fi
552                 fi
553
554                 if [ -n "$USE_GDB" ]; then
555                         set -- gdb --args "$@"
556                 fi
557                 "$@"
558                 ;;
559         each|foreach)
560                 for d in $repos; do
561                         if verbose cd "$d0/$d"; then
562                                 verbose "$@"
563                                 cd "$d0"
564                         fi
565                 done
566                 ;;
567         save-patches)
568                 outfile=$1
569                 patchdir=`mktemp -d -t save-patches.XXXXXX`
570                 for d in $repos; do
571                         enter "$d0/$d" verbose
572                         git branch -v -v | cut -c 3- | {
573                                 i=0
574                                 while read -r BRANCH REV UPSTREAM TEXT; do
575                                         case "$UPSTREAM" in
576                                                 \[*)
577                                                         UPSTREAM=${UPSTREAM#\[}
578                                                         UPSTREAM=${UPSTREAM%\]}
579                                                         UPSTREAM=${UPSTREAM%:*}
580                                                         TRACK=true
581                                                         ;;
582                                                 *)
583                                                         UPSTREAM=origin/"`repobranch "$d"`"
584                                                         TRACK=false
585                                                         ;;
586                                         esac
587                                         if [ x"$REV" = x"->" ]; then
588                                                 continue
589                                         fi
590                                         if git format-patch -o "$patchdir/$i" "$UPSTREAM".."$BRANCH"; then
591                                                 echo "$d" > "$patchdir/$i/info.txt"
592                                                 echo "$BRANCH" >> "$patchdir/$i/info.txt"
593                                                 echo "$UPSTREAM" >> "$patchdir/$i/info.txt"
594                                                 echo "$TRACK" >> "$patchdir/$i/info.txt"
595                                                 i=$(($i+1))
596                                         else
597                                                 rm -rf "$patchdir/$i"
598                                         fi
599                                 done
600                         }
601                 done
602                 ( cd "$patchdir" && tar cvzf - . ) > "$outfile"
603                 rm -rf "$patchdir"
604                 ;;
605         restore-patches)
606                 infile=$1
607                 patchdir=`mktemp -d -t restore-patches.XXXXXX`
608                 ( cd "$patchdir" && tar xvzf - ) < "$infile"
609                 # detach the head
610                 for P in "$patchdir"/*/info.txt; do
611                         D=${P%/info.txt}
612                         exec 3<"$P"
613                         read -r d <&3
614                         read -r BRANCH <&3
615                         read -r UPSTREAM <&3
616                         read -r TRACK <&3
617                         verbose git checkout HEAD^0
618                         verbose git branch -D "$BRANCH"
619                         if [ x"$TRACK" = x"true" ]; then
620                                 verbose git checkout --track -b "$BRANCH" "$UPSTREAM"
621                         else
622                                 verbose git branch -b "$BRANCH" "$UPSTREAM"
623                         fi
624                         verbose git am "$D"
625                 done
626                 rm -rf "$patchdir"
627                 ;;
628         admin-merge)
629                 if [ "$#" = 1 ]; then
630                         set -- "${1%%/*}" "${1#*/}"
631                 fi
632                 for d in $repos; do
633                         enter "$d0/$d" verbose
634                         git rev-parse "$1/$2" || continue
635                         # 1. review
636                         {
637                                 git log HEAD.."$1/$2"
638                                 git diff HEAD..."$1/$2"
639                         } | less
640                         if yesno "Merge \"$1/$2\" into `git symbolic-ref HEAD` of $d?"; then
641                                 git merge "$1/$2"
642                                 if "$SELF" compile && yesno "Still merge \"$1/$2\" into `git symbolic-ref HEAD` of $d? Maybe you want to test first."; then
643                                         git push origin HEAD
644                                         git push "$1" :"$2"
645                                 else
646                                         git reset --hard HEAD@{1}
647                                 fi
648                         fi
649                 done
650                 ;;
651         admin-merge-2)
652                 t=`mktemp`
653                 report=""
654                 reportecho()
655                 {
656                         report=$report"$*$LF"
657                         echo "$*"
658                 }
659                 reportecho4()
660                 {
661                         report=$report"    $*$LF"
662                         echo "    $*"
663                 }
664                 reportdo4()
665                 {
666                         o=`"$@" | sed 's/^/    /' || true`
667                         reportecho "$o"
668                 }
669                 for d in $repos; do
670                         enter "$d0/$d" verbose
671                         base="`repobranch "$d"`"
672                         reportecho "In $d:"
673                         for ref in `git for-each-ref --format='%(refname)' refs/remotes/origin/`; do
674                                 case "${ref#refs/remotes/origin/}" in
675                                         "$base")
676                                                 continue
677                                                 ;;
678                                         HEAD|master)
679                                                 continue
680                                                 ;;
681                                 esac
682                                 reportecho "  Branch $ref:"
683                                 note=`GIT_NOTES_REF=refs/notes/admin-merge git notes show "$ref" 2>/dev/null || true`
684                                 logdata=`git log --color "$base".."$ref"`
685                                 diffdata=`git diff --color --find-copies-harder --ignore-space-change "$base"..."$ref"`
686                                 if [ -z "$logdata" ]; then
687                                         reportecho4 "--> not merging, no changes vs master"
688                                 elif [ -z "$diffdata" ]; then
689                                         reportecho4 "--> not merging, no changes vs master, branch contains redundant history"
690                                         if yesno "Branch \"$ref\" probably should get deleted. Do it?" '{ echo "$logdata"; } | less -r'; then
691                                                 git push origin :"${ref#refs/remotes/origin/}"
692                                                 reportecho4 "--> branch deleted"
693                                         fi
694                                 elif [ -n "$note" ]; then
695                                         reportdo4 echo "$note"
696                                         reportecho4 "--> not merging, already had this one rejected before"
697                                 elif yesno "Branch \"$ref\" may want to get merged. Do it?" '{ echo "$logdata"; echo "$diffdata"; } | less -r'; then
698                                         git checkout "$base"
699                                         org=`git rev-parse HEAD`
700                                         if ! git merge "$ref" 2>&1 | tee "$t"; then
701                                                 git reset --hard "$org"
702                                                 GIT_NOTES_REF=refs/notes/admin-merge git notes edit -m "Merge failed:$LF`cat "$t"`" "$ref"
703                                                 reportdo4 cat "$t"
704                                                 reportecho4 "--> merge failed"
705                                         elif ! "$SELF" compile 2>&1 | tee "$t"; then
706                                                 git reset --hard "$org"
707                                                 GIT_NOTES_REF=refs/notes/admin-merge git notes edit -m "Compile failed:$LF`cat "$t"`" "$ref"
708                                                 reportdo4 cat "$t"
709                                                 reportecho4 "--> compile failed"
710                                         elif ! yesno "Still merge \"$ref\" into `git symbolic-ref HEAD` of $d? Maybe you want to test first."; then
711                                                 git reset --hard "$org"
712                                                 git notes edit "$ref"
713                                                 note=`GIT_NOTES_REF=refs/notes/admin-merge git notes show "$ref" 2>/dev/null || true`
714                                                 reportdo4 echo "$note"
715                                                 reportecho4 "--> test failed"
716                                         else
717                                                 case ",`repoflags "$d"`," in
718                                                         *,svn,*)
719                                                                 # we do quite a mess here... luckily we know $org
720                                                                 git pull # svn needs to be current
721                                                                 git rebase -i --onto master "$org"
722                                                                 git svn dcommit --add-author-from
723                                                                 git reset --hard "$org"
724                                                                 ;;
725                                                         *)
726                                                                 git push origin HEAD
727                                                                 ;;
728                                                 esac
729                                                 reportecho4 "--> MERGED"
730                                                 if yesno "Delete original branch \"$ref\"?"; then
731                                                         git push origin :"${ref#refs/remotes/origin/}"
732                                                         reportecho4 "--> branch deleted"
733                                                 fi
734                                         fi
735                                 else
736                                         GIT_NOTES_REF=refs/notes/admin-merge git notes edit "$ref"
737                                         note=`GIT_NOTES_REF=refs/notes/admin-merge git notes show "$ref" 2>/dev/null || true`
738                                         if [ -n "$note" ]; then
739                                                 reportdo4 echo "$note"
740                                                 reportecho4 "--> rejected"
741                                         else
742                                                 reportecho4 "--> postponed"
743                                         fi
744                                 fi
745                                 reportecho ""
746                         done
747                         reportecho ""
748                 done
749                 rm -f "$t"
750                 echo "$report" | ssh nexuiz@rm.endoftheinternet.org cat '>>' public_html/xonotic-merge-notes.txt
751                 ;;
752         *)
753                 echo "Usage:"
754                 echo "  $SELF pull"
755                 echo "  $SELF merge"
756                 echo "  $SELF push [-s]"
757                 echo "  $SELF branches"
758                 echo "  $SELF branch [<remote>] <branchname>"
759                 echo "  $SELF branch <remote> <branchname> <srcbranchname>"
760                 echo "  $SELF checkout [<remote>] <branchname>"
761                 echo "  $SELF compile [-c] [<client>] <options>"
762                 echo "  $SELF run [<client>] <options>"
763                 echo "  $SELF each <command>"
764                 ;;
765 esac