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