autodownload compiled maps on "compile"
[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                         if [ -z "$branch" ]; then
257                                 b=`repobranch "$d"`
258                         else
259                                 b=$branch
260                         fi
261                         if git rev-parse "refs/heads/$b" >/dev/null 2>&1; then
262                                 exists=true
263                                 verbose git checkout "$b"
264                         elif git rev-parse "refs/remotes/$remote/$b" >/dev/null 2>&1; then
265                                 exists=true
266                                 verbose git checkout --track -b "$b" "$remote/$b"
267                         else
268                                 verbose git checkout "`repobranch "$d"`"
269                         fi
270                         cd "$d00"
271                         checkself "$cmd" "$@"
272                         cd "$d0"
273                 done
274                 if ! $exists; then
275                         echo "The requested branch was not found in any repository."
276                 fi
277                 exec "$SELF" branch
278                 ;;
279         branch)
280                 remote=$1
281                 branch=$2
282                 srcbranch=$3
283                 if [ -z "$branch" ]; then
284                         branch=$remote
285                         remote=origin
286                 fi
287                 if [ -z "$branch" ]; then
288                         for d in $repos; do
289                                 enter "$d0/$d"
290                                 r=`git symbolic-ref HEAD`
291                                 r=${r#refs/heads/}
292                                 echo "$d is at $r"
293                                 cd "$d0"
294                         done
295                 else
296                         for d in $repos; do
297                                 dv=`visible_repo_name "$d"`
298                                 enter "$d0/$d" verbose
299                                 if git rev-parse "refs/heads/$branch" >/dev/null 2>&1; then
300                                         echo "Already having this branch in $dv."
301                                 else
302                                         if yesno "Branch in $dv?"; then
303                                                 if [ -n "$srcbranch" ]; then
304                                                         b=$srcbranch
305                                                 else
306                                                         b=origin/"`repobranch "$d"`"
307                                                         verbose git fetch origin || true
308                                                 fi
309                                                 # TODO do this without pushing
310                                                 verbose git checkout -b "$branch" "$b"
311                                                 verbose git config "branch.$branch.remote" "$remote"
312                                                 verbose git config "branch.$branch.merge" "refs/heads/$branch"
313                                         fi
314                                 fi
315                                 cd "$d0"
316                         done
317                         "$SELF" branch
318                 fi
319                 ;;
320         branches)
321                 for d in $repos; do
322                         enter "$d0/$d"
323                         echo "In $d:"
324                         git branch -a -v -v | cut -c 3- | while read -r BRANCH REV UPSTREAM TEXT; do
325                                 case "$UPSTREAM" in
326                                         \[*)
327                                                 UPSTREAM=${UPSTREAM#\[}
328                                                 UPSTREAM=${UPSTREAM%\]}
329                                                 UPSTREAM=${UPSTREAM%:*}
330                                                 ;;
331                                         *)
332                                                 TEXT="$UPSTREAM $TEXT"
333                                                 UPSTREAM=
334                                                 ;;
335                                 esac
336                                 if [ x"$REV" = x"->" ]; then
337                                         continue
338                                 fi
339                                 BRANCH=${BRANCH#remotes/}
340                                 echo -n "  $BRANCH"
341                                 if [ -n "$UPSTREAM" ]; then
342                                         echo -n " (tracking $UPSTREAM)"
343                                 fi
344                                 #echo " $TEXT"
345                                 echo
346                         done
347                 done
348                 ;;
349         branches_short)
350                 for d in $repos; do
351                         cd "$d0/$d" # am in a pipe, shouldn't use enter
352                         git branch -a -v -v | cut -c 3- | sed "s,^,$d ,"
353                         cd "$d0"
354                 done | {
355                         branches_list=
356                         # branches_repos_*=
357                         while read -r d BRANCH REV UPSTREAM TEXT; do
358                                 case "$UPSTREAM" in
359                                         \[*)
360                                                 UPSTREAM=${UPSTREAM#\[}
361                                                 UPSTREAM=${UPSTREAM%\]}
362                                                 UPSTREAM=${UPSTREAM%:*}
363                                                 ;;
364                                         *)
365                                                 TEXT="$UPSTREAM $TEXT"
366                                                 UPSTREAM=
367                                                 ;;
368                                 esac
369                                 if [ x"$REV" = x"->" ]; then
370                                         continue
371                                 fi
372                                 BRANCH=${BRANCH#remotes/}
373                                 ID=`echo "$BRANCH" | tr -c "A-Za-z0-9." "_"`
374                                 branches_list="$branches_list $BRANCH" # TEH SORT MAKEZ IT UNIEQ
375                                 eval "r=\$branches_repos_$ID"
376                                 r="$r $d:$UPSTREAM"
377                                 eval "branches_repos_$ID=\$r"
378                         done
379                         echo -n "$branches_list" | xargs -n 1 echo | sort -u | while IFS= read -r BRANCH; do
380                                 ID=`echo "$BRANCH" | tr -c "A-Za-z0-9." "_"`
381                                 eval "r=\$branches_repos_$ID"
382                                 echo "$BRANCH: $r"
383                         done
384                 }
385                 ;;
386         merge)
387                 for d in $repos; do
388                         dv=`visible_repo_name "$d"`
389                         enter "$d0/$d" verbose
390                         r=`git symbolic-ref HEAD`
391                         r=${r#refs/heads/}
392                         if git log HEAD..origin/"`repobranch "$d"`" | grep .; then
393                                 # we have uncommitted changes
394                                 if yesno "Could merge from \"`repobranch "$d"`\" into \"$r\" in $dv. Do it?"; then
395                                         if ! verbose git merge origin/"`repobranch "$d"`"; then
396                                                 check_mergeconflict "$d"
397                                                 exit 1 # this should ALWAYS be fatal
398                                         fi
399                                 fi
400                         fi
401                         cd "$d0"
402                 done
403                 ;;
404         push|commit)
405                 submit=$1
406                 for d in $repos; do
407                         dv=`visible_repo_name "$d"`
408                         enter "$d0/$d" verbose
409                         r=`git symbolic-ref HEAD`
410                         r=${r#refs/heads/}
411                         if git diff HEAD | grep .; then
412                                 # we have uncommitted changes
413                                 if yesno "Uncommitted changes in \"$r\" in $dv. Commit?"; then
414                                         verbose git commit -a
415                                 fi
416                         fi
417                         rem=`git config "branch.$r.remote" || echo origin`
418                         bra=`git config "branch.$r.merge" || echo "$r"`
419                         upstream="$rem/$bra"
420                         if ! [ git rev-parse "$upstream" ]; then
421                                 upstream="`repobranch "$d"`"
422                         fi
423                         if git log "$upstream".."$r" | grep .; then
424                                 if yesno "Push \"$r\" in $dv?"; then
425                                         verbose git push "$rem" HEAD
426                                 fi
427                         fi
428                         if [ x"$submit" = x"-s" ]; then
429                                 case "$r" in
430                                         */*)
431                                                 verbose git push "$rem" HEAD:"${bra%%/*}/finished/${bra#*/}"
432                                                 ;;
433                                 esac
434                         fi
435                         cd "$d0"
436                 done
437                 ;;
438         compile)
439                 if [ -n "$WE_HATE_OUR_USERS" ]; then
440                         TARGETS="sv-debug cl-debug"
441                         if [ -z "$CC" ]; then
442                                 export CC=gcc
443                         fi
444                 elif [ x"`uname`" = x"Darwin" ] && ( [ -d /Library/Frameworks/SDL.framework ] || [ -d $(HOME)/Library/Frameworks/SDL.framework ] ); then
445                         # AGL is broken in Snow Leopard, so let's default to SDL if it is available.
446                         TARGETS="sv-debug sdl-debug"
447                 else
448                         TARGETS="sv-debug cl-debug sdl-debug"
449                 fi
450                 case "$1" in
451                         -c)
452                                 clean=true
453                                 shift
454                                 ;;
455                         *)
456                                 clean=false
457                                 ;;
458                 esac
459                 case "$1" in
460                         sdl)
461                                 TARGETS="sdl-debug"
462                                 shift
463                                 ;;
464                         glx|agl|wgl)
465                                 TARGETS="cl-debug"
466                                 shift
467                                 ;;
468                         dedicated)
469                                 TARGETS="sv-debug"
470                                 shift
471                                 ;;
472                 esac
473                 if [ -z "$MAKEFLAGS" ]; then
474                         if [ -f /proc/cpuinfo ]; then
475                                 ncpus=$((`grep -c '^processor   :' /proc/cpuinfo`+0))
476                                 if [ $ncpus -gt 1 ]; then
477                                         MAKEFLAGS=-j$ncpus
478                                 fi
479                         fi
480                         case "`uname`" in
481                                 Linux|*BSD)
482                                         MAKEFLAGS="$MAKEFLAGS DP_LINK_TO_LIBJPEG=1"
483                                         ;;
484                         esac
485                         if [ -n "$WE_HATE_OUR_USERS" ]; then
486                                 MAKEFLAGS="$MAKEFLAGS DP_MAKE_TARGET=mingw"
487                         fi
488                 fi
489                 enter "$d0/fteqcc" verbose
490                 if $clean; then
491                         verbose make $MAKEFLAGS clean
492                 fi
493                 verbose make $MAKEFLAGS
494                 enter "$d0/data/xonotic-data.pk3dir" verbose
495                 if $clean; then
496                         verbose make $MAKEFLAGS clean
497                 fi
498                 verbose make FTEQCC="$d0/fteqcc/fteqcc.bin" "$@" $MAKEFLAGS clean
499                 verbose make FTEQCC="$d0/fteqcc/fteqcc.bin" "$@" $MAKEFLAGS
500                 enter "$d0/darkplaces" verbose
501                 if $clean; then
502                         verbose make $MAKEFLAGS clean
503                 fi
504                 for T in $TARGETS; do
505                         verbose make $MAKEFLAGS "$@" "$T"
506                 done
507                 verbose "$SELF" update-maps
508                 ;;
509         run)
510                 if [ -n "$WE_HATE_OUR_USERS" ]; then
511                         client=
512                         export PATH="$d0/misc/buildfiles/w32:$PATH"
513                 elif [ x"`uname`" = x"Darwin" ]; then
514                         export DYLD_LIBRARY_PATH="$d0/misc/buildfiles/osx/Xonotic-SDL.app/Contents/MacOS"
515                         client=-sdl
516                 else
517                         client=-sdl
518                 fi
519                 case "$1" in
520                         sdl|glx|agl|dedicated)
521                                 client=-$1
522                                 shift
523                                 ;;
524                         wgl)
525                                 client=
526                                 shift
527                                 ;;
528                 esac
529                 if ! [ -x "darkplaces/darkplaces$client" ]; then
530                         if [ -x "darkplaces/darkplaces$client.exe" ]; then
531                                 client=$client.exe
532                         else
533                                 echo "Client darkplaces/darkplaces$client not found, aborting"
534                                 exit 1
535                         fi
536                 fi
537                 set -- "darkplaces/darkplaces$client" -nexuiz -customgamename Xonotic -customgamedirname1 data -customgamedirname2 "" -customgamescreenshotname xonotic -customgameuserdirname xonotic "$@"
538
539                 # if pulseaudio is running: USE IT
540                 if [ -z "$SDL_AUDIODRIVER" ] && ! [ -n "$WE_HATE_OUR_USERS" ] && ! [ x"`uname`" = x"Darwin" ]; then
541                         if ps -C pulseaudio >/dev/null; then
542                                 if ldd /usr/lib/libSDL.so 2>/dev/null | grep pulse >/dev/null; then
543                                         export SDL_AUDIODRIVER=pulse
544                                 fi
545                         fi
546                 fi
547
548                 if [ -n "$USE_GDB" ]; then
549                         set -- gdb --args "$@"
550                 fi
551                 "$@"
552                 ;;
553         each|foreach)
554                 for d in $repos; do
555                         if verbose cd "$d0/$d"; then
556                                 verbose "$@"
557                                 cd "$d0"
558                         fi
559                 done
560                 ;;
561         save-patches)
562                 outfile=$1
563                 patchdir=`mktemp -d -t save-patches.XXXXXX`
564                 for d in $repos; do
565                         enter "$d0/$d" verbose
566                         git branch -v -v | cut -c 3- | {
567                                 i=0
568                                 while read -r BRANCH REV UPSTREAM TEXT; do
569                                         case "$UPSTREAM" in
570                                                 \[*)
571                                                         UPSTREAM=${UPSTREAM#\[}
572                                                         UPSTREAM=${UPSTREAM%\]}
573                                                         UPSTREAM=${UPSTREAM%:*}
574                                                         TRACK=true
575                                                         ;;
576                                                 *)
577                                                         UPSTREAM=origin/"`repobranch "$d"`"
578                                                         TRACK=false
579                                                         ;;
580                                         esac
581                                         if [ x"$REV" = x"->" ]; then
582                                                 continue
583                                         fi
584                                         if git format-patch -o "$patchdir/$i" "$UPSTREAM".."$BRANCH"; then
585                                                 echo "$d" > "$patchdir/$i/info.txt"
586                                                 echo "$BRANCH" >> "$patchdir/$i/info.txt"
587                                                 echo "$UPSTREAM" >> "$patchdir/$i/info.txt"
588                                                 echo "$TRACK" >> "$patchdir/$i/info.txt"
589                                                 i=$(($i+1))
590                                         else
591                                                 rm -rf "$patchdir/$i"
592                                         fi
593                                 done
594                         }
595                 done
596                 ( cd "$patchdir" && tar cvzf - . ) > "$outfile"
597                 rm -rf "$patchdir"
598                 ;;
599         restore-patches)
600                 infile=$1
601                 patchdir=`mktemp -d -t restore-patches.XXXXXX`
602                 ( cd "$patchdir" && tar xvzf - ) < "$infile"
603                 # detach the head
604                 for P in "$patchdir"/*/info.txt; do
605                         D=${P%/info.txt}
606                         exec 3<"$P"
607                         read -r d <&3
608                         read -r BRANCH <&3
609                         read -r UPSTREAM <&3
610                         read -r TRACK <&3
611                         verbose git checkout HEAD^0
612                         verbose git branch -D "$BRANCH"
613                         if [ x"$TRACK" = x"true" ]; then
614                                 verbose git checkout --track -b "$BRANCH" "$UPSTREAM"
615                         else
616                                 verbose git branch -b "$BRANCH" "$UPSTREAM"
617                         fi
618                         verbose git am "$D"
619                 done
620                 rm -rf "$patchdir"
621                 ;;
622         admin-merge)
623                 if [ "$#" = 1 ]; then
624                         set -- "${1%%/*}" "${1#*/}"
625                 fi
626                 for d in $repos; do
627                         enter "$d0/$d" verbose
628                         git rev-parse "$1/$2" || continue
629                         # 1. review
630                         {
631                                 git log HEAD.."$1/$2"
632                                 git diff HEAD..."$1/$2"
633                         } | less
634                         if yesno "Merge \"$1/$2\" into `git symbolic-ref HEAD` of $d?"; then
635                                 git merge "$1/$2"
636                                 if "$SELF" compile && yesno "Still merge \"$1/$2\" into `git symbolic-ref HEAD` of $d? Maybe you want to test first."; then
637                                         git push origin HEAD
638                                         git push "$1" :"$2"
639                                 else
640                                         git reset --hard HEAD@{1}
641                                 fi
642                         fi
643                 done
644                 ;;
645         admin-merge-2)
646                 t=`mktemp`
647                 report=""
648                 reportecho()
649                 {
650                         report=$report"$*$LF"
651                         echo "$*"
652                 }
653                 reportecho4()
654                 {
655                         report=$report"    $*$LF"
656                         echo "    $*"
657                 }
658                 reportdo4()
659                 {
660                         o=`"$@" | sed 's/^/    /' || true`
661                         reportecho "$o"
662                 }
663                 for d in $repos; do
664                         enter "$d0/$d" verbose
665                         base="`repobranch "$d"`"
666                         reportecho "In $d:"
667                         for ref in `git for-each-ref --format='%(refname)' refs/remotes/origin/`; do
668                                 case "${ref#refs/remotes/origin/}" in
669                                         "$base")
670                                                 continue
671                                                 ;;
672                                         HEAD|master)
673                                                 continue
674                                                 ;;
675                                 esac
676                                 reportecho "  Branch $ref:"
677                                 note=`GIT_NOTES_REF=refs/notes/admin-merge git notes show "$ref" 2>/dev/null || true`
678                                 logdata=`git log --color "$base".."$ref"`
679                                 diffdata=`git diff --color --find-copies-harder --ignore-space-change "$base"..."$ref"`
680                                 if [ -z "$logdata" ]; then
681                                         reportecho4 "--> not merging, no changes vs master"
682                                 elif [ -z "$diffdata" ]; then
683                                         reportecho4 "--> not merging, no changes vs master, branch contains redundant history"
684                                         if yesno "Branch \"$ref\" probably should get deleted. Do it?" '{ echo "$logdata"; } | less -r'; then
685                                                 git push origin :"${ref#refs/remotes/origin/}"
686                                                 reportecho4 "--> branch deleted"
687                                         fi
688                                 elif [ -n "$note" ]; then
689                                         reportdo4 echo "$note"
690                                         reportecho4 "--> not merging, already had this one rejected before"
691                                 elif yesno "Branch \"$ref\" may want to get merged. Do it?" '{ echo "$logdata"; echo "$diffdata"; } | less -r'; then
692                                         git checkout "$base"
693                                         org=`git rev-parse HEAD`
694                                         if ! git merge "$ref" 2>&1 | tee "$t"; then
695                                                 git reset --hard "$org"
696                                                 GIT_NOTES_REF=refs/notes/admin-merge git notes edit -m "Merge failed:$LF`cat "$t"`" "$ref"
697                                                 reportdo4 cat "$t"
698                                                 reportecho4 "--> merge failed"
699                                         elif ! "$SELF" compile 2>&1 | tee "$t"; then
700                                                 git reset --hard "$org"
701                                                 GIT_NOTES_REF=refs/notes/admin-merge git notes edit -m "Compile failed:$LF`cat "$t"`" "$ref"
702                                                 reportdo4 cat "$t"
703                                                 reportecho4 "--> compile failed"
704                                         elif ! yesno "Still merge \"$ref\" into `git symbolic-ref HEAD` of $d? Maybe you want to test first."; then
705                                                 git reset --hard "$org"
706                                                 git notes edit "$ref"
707                                                 note=`GIT_NOTES_REF=refs/notes/admin-merge git notes show "$ref" 2>/dev/null || true`
708                                                 reportdo4 echo "$note"
709                                                 reportecho4 "--> test failed"
710                                         else
711                                                 case ",`repoflags "$d"`," in
712                                                         *,svn,*)
713                                                                 # we do quite a mess here... luckily we know $org
714                                                                 git pull # svn needs to be current
715                                                                 git rebase -i --onto master "$org"
716                                                                 git svn dcommit --add-author-from
717                                                                 git reset --hard "$org"
718                                                                 ;;
719                                                         *)
720                                                                 git push origin HEAD
721                                                                 ;;
722                                                 esac
723                                                 reportecho4 "--> MERGED"
724                                                 if yesno "Delete original branch \"$ref\"?"; then
725                                                         git push origin :"${ref#refs/remotes/origin/}"
726                                                         reportecho4 "--> branch deleted"
727                                                 fi
728                                         fi
729                                 else
730                                         GIT_NOTES_REF=refs/notes/admin-merge git notes edit "$ref"
731                                         note=`GIT_NOTES_REF=refs/notes/admin-merge git notes show "$ref" 2>/dev/null || true`
732                                         if [ -n "$note" ]; then
733                                                 reportdo4 echo "$note"
734                                                 reportecho4 "--> rejected"
735                                         else
736                                                 reportecho4 "--> postponed"
737                                         fi
738                                 fi
739                                 reportecho ""
740                         done
741                         reportecho ""
742                 done
743                 rm -f "$t"
744                 echo "$report" | ssh nexuiz@rm.endoftheinternet.org cat '>>' public_html/xonotic-merge-notes.txt
745                 ;;
746         *)
747                 echo "Usage:"
748                 echo "  $SELF pull"
749                 echo "  $SELF merge"
750                 echo "  $SELF push [-s]"
751                 echo "  $SELF branches"
752                 echo "  $SELF branch [<remote>] <branchname>"
753                 echo "  $SELF branch <remote> <branchname> <srcbranchname>"
754                 echo "  $SELF checkout [<remote>] <branchname>"
755                 echo "  $SELF compile [-c] [<client>] <options>"
756                 echo "  $SELF run [<client>] <options>"
757                 echo "  $SELF each <command>"
758                 ;;
759 esac