3 if [ x"$3" != x"." ]; then
21 allrepos initrepo_ "`git config remote.origin.url`" "`git config remote.origin.pushurl`"
22 if [ -z "$base" ]; then
23 msg "The main repo is not xonotic.git, what have you done?"
26 msg "Found main repo = $base"
27 if [ -n "$pushbase" ]; then
28 msg "Found push repo = $pushbase"
44 [ x"$1" = x"$3" ] || return
45 if matchrepoflag "$6" "$2"; then
51 allrepos testrepoflag_ "$1" "$2" | grep ^0 >/dev/null
56 if ! { time -p true; } >/dev/null 2>&1; then
60 # first result is to be ignored, but we use it to check status
61 git ls-remote "$1" refs/heads/master >/dev/null 2>&1 || return 1
62 # now actually time it
65 { time -p git ls-remote "$1" refs/heads/master; } 2>&1 >/dev/null | head -n 1 | cut -d ' ' -f 2 | tr -d . | sed 's,^0*,,' | grep . || echo 0
66 # unit: clock ticks (depends on what "time" returns
77 bestmirror_firstrepo()
79 if [ -z "$testrepo" ]; then
83 allrepos bestmirror_firstrepo
86 if [ x"$oldurl" = x"$3" ]; then
91 allmirrors bestmirror_findold
93 if [ -z "$newprotocol" ]; then
94 newprotocol=$oldprotocol
96 if [ -z "$newlocation" ]; then
97 newlocation=$oldlocation
104 bestmirror_benchmark()
107 # empty location is not allowed
110 case " $newprotocol " in
112 # no protocol requested? all match
121 # prefer location match
122 case " $newlocation " in
126 case " $newlocation " in
135 case " $newlocation " in
140 case " $newlocation " in
148 msg "Testing speed of $3..."
150 # only working mirrors
151 if ! thistime=`mirrorspeed "$3$testrepo"`; then
155 thistime=$(($thistime $4))
158 # anything is better than nothing
159 if [ -z "$besttime" ]; then
167 # prefer location match
168 case " $newlocation " in
170 case " $newlocation " in
185 # if newlocation matches bestlocation, then we already discarded it above
189 # if we get here, we must compare mirror speed as we have more than one match
190 if [ $thistime -gt $besttime ]; then
192 elif [ $thistime -lt $besttime ]; then
198 # both location and time match. Random decision.
199 bestcount=$(($bestcount + 1))
200 if [ $((($RANDOM + 0) % $bestcount)) -eq 0 ]; then
204 allmirrors bestmirror_benchmark
210 [ x"$1" = x"$3" ] || return
221 allrepos testrepoflag_ "$1" "$2" | grep ^0 >/dev/null
228 # if we have .no file, skip
229 if [ -f "$d.no" ]; then
230 msg "Repository $d disabled by a .no file, delete $d.no to enable"
233 # if .yes file exists, always keep it
234 if [ -f "$d.yes" ]; then
235 msg "Repository $d enabled by a .yes file"
239 # remove broken clones so they don't mess up stuff
240 if [ x"$d" != x"." ] && [ -d "$d" ] && ! [ -d "$d/.git" ]; then
241 msg "$d exists but has no .git subdir. Probably a broken clone. Deleting."
245 # if we have the dir, always keep it
247 msg "Repository $d enabled because it already exists"
251 # if we have matching pk3, skip
252 if [ x"$p" != x"$d" ] && [ -f "$p" ]; then
253 msg "Repository $d disabled by matching .pk3 file, delete $p or create $d.yes to enable"
256 # if "no" flag is set, skip
257 if matchrepoflag "$f" no; then
258 msg "Repository $d disabled by default, create $d.yes to enable"
262 msg "Repository $d enabled by default"
268 $ECHO `allrepos listrepos_`
275 eval ire_test=\$$(($1 + 3))
283 check_mergeconflict() # overrides the one in ./all
285 if git ls-files -u | grep ' 1 '; then
287 $ECHO "MERGE CONFLICT."
288 $ECHO "change into the \"$1\" project directory, and then:"
289 $ECHO "- edit the files mentioned above with your favorite editor,"
290 $ECHO " and fix the conflicts (marked with <<<<<<< blocks)"
291 $ECHO "- for binary files, you can select the files using"
292 $ECHO " git checkout --ours or git checkout --theirs"
293 $ECHO "- when done with a file, 'git add' the file"
294 $ECHO "- when done, 'git commit'"
304 $ECHO "the root directory"
312 fix_upstream_rebase()
314 if [ -z "$r_me" ] || [ -z "$r_other" ]; then
318 # one of the two sides of the merge should be remote upstream, or all is fine
319 r_r=`git symbolic-ref HEAD`
320 r_r=${r_r#refs/heads/}
321 r_rem=`git config "branch.$r_rem.remote" || $ECHO origin`
322 r_bra=`git config "branch.$r_bra.merge" || $ECHO "$r_r"`
323 r_bra=${r_bra#refs/heads/}
324 if [ x"$r_me" != x"`git rev-parse "$r_rem/$r_bra"`" ]; then
325 if [ x"$r_other" != x"`git rev-parse "$r_rem/$r_bra"`" ]; then
330 r_base=`git merge-base "$r_me" "$r_other"`
332 # no merge-base? upstream did filter-branch
333 if [ -n "$r_base" ]; then
334 # otherwise, check if the two histories are "similar"
335 r_l_me=`git log --pretty="format:%s" "$r_other".."$r_me" | grep -v "^Merge" | sort -u`
336 r_l_other=`git log --pretty="format:%s" "$r_me".."$r_other" | grep -v "^Merge" | sort -u`
338 # heuristics: upstream rebase/filter-branch if more than 50% of the commits of one of the sides are in the other too
339 r_lc_me=`$ECHO "$r_l_me" | wc -l`
340 r_lc_other=`$ECHO "$r_l_other" | wc -l`
341 r_lc_together=`{ $ECHO "$r_l_me"; $ECHO "$r_l_other"; } | sort -u | wc -l`
342 r_lc_same=$(($r_lc_me + $r_lc_other - $r_lc_together))
344 if [ $(( $r_lc_same * 2 )) -gt $(( $r_lc_me )) ] || [ $(( $r_lc_same * 2 )) -gt $(( $r_lc_other )) ]; then
345 if yesno "Probable upstream rebase detected, automatically fix?" 'git log --oneline --graph --date-order --left-right "$r_other"..."$r_me"'; then
346 git reset --hard "$r_me"
356 fix_upstream_rebase_mergeok()
358 r_me=`git rev-parse --revs-only HEAD^1 2>/dev/null || true`
359 r_other=`git rev-parse --revs-only HEAD^2 2>/dev/null || true`
363 fix_upstream_rebase_mergefail()
365 r_me=`git rev-parse --revs-only HEAD 2>/dev/null || true`
366 r_other=`git rev-parse --revs-only MERGE_HEAD 2>/dev/null || true`
372 if ! [ -f ".git/config" ]; then
373 $ECHO "Not a git repository. Bailing out to not cause damage."
376 verbose git config remote.origin.url "$1"
378 verbose git config remote.origin.pushurl "$2"
380 verbose git config --unset remote.origin.pushurl || true
382 verbose git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
383 if testrepoflag "$d" noautocrlf; then
384 verbose git config --unset core.autocrlf || true
386 verbose git config core.autocrlf input
388 if [ -z "`git config push.default || true`" ]; then
389 verbose git config push.default current # or is tracking better?
391 verbose git config filter.mapclean.clean "tr -d '\r' | grep '^[^/]'"
392 verbose git config filter.mapclean.smudge "cat"
397 while [ $# -gt 4 ]; do
402 if [ -n "$pushbase" ]; then
403 pushurl="$pushbase$2"
414 fix_upstream_rebase_()
417 enter "$d0/$d" verbose
418 verbose fix_upstream_rebase_mergefail && verbose fix_upstream_rebase_mergeok
420 allrepos ifrepoenabled 0 fix_upstream_rebase_
426 if [ -f "$d0/$d/.git/config" ]; then
428 fix_git_config "$url" "$pushurl"
432 allrepos ifrepoenabled 0 fix_config_
435 if [ -f ~/.ssh/id_rsa.pub ]; then
437 msg "A key already exists and no new one will be generated. If you"
438 msg "already have done the procedure for getting your key approved, you"
439 msg "can skip the following paragraph and already use the repository."
441 msg "To get access, your key has to be approved first. For that, visit"
442 msg "$devsite_url, then log in, create a \"New Issue\" on"
443 msg "the \"Support\" tracker in the \"Repository\" category where you"
444 msg "apply for access and paste the following output into the issue:"
446 msg "`cat ~/.ssh/id_rsa.pub`"
447 elif [ -f ~/.ssh/id_dsa.pub ]; then
449 msg "A key already exists and no new one will be generated. If you"
450 msg "already have done the procedure for getting your key approved, you"
451 msg "can skip the following paragraph and already use the repository."
453 msg "To get access, your key has to be approved first. For that, visit"
454 msg "$devsite_url, then log in, create a \"New Issue\" on"
455 msg "the \"Support\" tracker in the \"Repository\" category where you"
456 msg "apply for access and paste the following output into the issue:"
458 msg "`cat ~/.ssh/id_dsa.pub`"
461 msg "No key has been generated yet. One will be generated now."
462 msg "If other people are using your computer, it is recommended"
463 msg "to specify a passphrase. Otherwise you can simply hit ENTER"
464 msg "when asked for a passphrase."
466 ssh-keygen -t rsa -b 4096 -f ~/.ssh/id_rsa
468 msg "To get access, your key has to be approved first. For that, visit"
469 msg "$devsite_url, then log in, create a \"New Issue\" on"
470 msg "the \"Support\" tracker in the \"Repository\" category where you"
471 msg "apply for access and paste the following output into the issue:"
473 msg "`cat ~/.ssh/id_rsa.pub`"
476 msg "Note that you will only have write access to branches that start"
477 msg "with your user name."
479 msg "Once you have gotten access, run ./all update -p"
483 need_bestmirror=false
489 case "`git config xonotic.all.mirrorselection 2>/dev/null || true`" in
496 newprotocol="git http"
501 newprotocol= # same protocol
507 if $need_bestmirror; then
511 if [ x"$base" = x"$3" ]; then
515 allmirrors identifymirror_
518 msg "Current mirror not found = $base"
519 msg "but the last pull attempt failed."
521 msg "Use ./all update -l any to switch to the best mirror."
523 need_bestmirror=false
528 if [ x"$1" = x"-N" ]; then
530 elif [ x"$1" = x"-p" ]; then
533 elif [ x"$1" = x"-s" ]; then
536 elif [ x"$1" = x"-g" ]; then
539 elif [ x"$1" = x"-h" ]; then
542 elif [ x"$1" = x"-l" ]; then
552 if $need_bestmirror; then
553 newbase=`bestmirror "$base" "$newprotocol" "$newlocation"`
554 if [ -z "$newbase" ]; then
555 msg "Could not find any good mirror. Maybe try again later."
556 git config xonotic.all.mirrorselection try_all
559 if [ -n "$newpushprotocol" ]; then
560 if [ -n "$pushbase" ]; then
561 newpushbase=`bestmirror "$pushbase" "$newpushprotocol" "$newlocation"`
563 newpushbase=`bestmirror "$base" "$newpushprotocol" "$newlocation"`
566 newpushbase=$pushbase
569 if [ x"$base" != x"$newbase" ] || [ x"$pushbase" != x"$newpushbase" ]; then
571 pushbase=$newpushbase
575 if [ x"$d" = x"." ]; then
576 fix_git_config "$url" "$pushurl"
579 allrepos ifrepoenabled 0 seturl_
581 git config xonotic.all.mirrorselection done
589 if [ -f "$d0/$d/.git/config" ]; then
590 # if we have .no file, skip
591 if [ -f "$d0/$d.no" ]; then
592 msg "Repository $d disabled by a .no file, delete $d.no to enable; thus, not updated"
596 enter "$d0/$d" verbose
597 r=`git symbolic-ref HEAD`
599 if git config branch.$r.remote >/dev/null 2>&1; then
600 o=`( cd "$d0" && git config xonotic.all.mirrorselection 2>/dev/null || true )`
601 ( cd "$d0" && git config xonotic.all.mirrorselection try_same )
602 if ! verbose git pull; then
603 fix_upstream_rebase_mergefail || true
604 check_mergeconflict "$d"
605 $ECHO "Pulling failed. Press ENTER to continue, or Ctrl-C to abort."
608 ( cd "$d0" && git config xonotic.all.mirrorselection "$o" )
609 fix_upstream_rebase_mergeok || true
614 checkself "$cmd" "$@"
616 verbose git remote prune origin
620 if [ -d "$d0/$d" ]; then
621 if yesno "$d0/$d is in the way, get rid of it and reclone?"; then
622 verbose rm -rf "$d0/$d"
624 echo "Note: $d0/$d will stay broken."
628 o=`git config xonotic.all.mirrorselection 2>/dev/null || true`
629 git config xonotic.all.mirrorselection try_same
630 verbose git clone "$url" "$d0/$d"
631 git config xonotic.all.mirrorselection "$o"
632 enter "$d0/$d" verbose
633 fix_git_config "$url" "$pushurl"
634 if [ "$branch" != "master" ]; then
635 verbose git checkout --track -b "$branch" origin/"$branch"
640 allrepos ifrepoenabled 0 pull_
644 if [ x"$1" = x"-f" ]; then
650 if [ -z "$branch" ]; then
653 askbranch=${remote#origin/}
662 if [ -n "$checkoutflags" ]; then
663 set -- -f "$@" # to make checkself work again
669 enter "$d0/$d" verbose
671 if [ -n "$b" ] && git rev-parse "refs/heads/$b" >/dev/null 2>&1; then
673 verbose git checkout $checkoutflags "$b"
674 elif [ -n "$b" ] && git rev-parse "refs/remotes/$remote/$b" >/dev/null 2>&1; then
676 verbose git checkout $checkoutflags --track -b "$b" "$remote/$b"
679 if git rev-parse "refs/heads/$b" >/dev/null 2>&1; then
680 verbose git checkout $checkoutflags "$b"
681 elif git rev-parse "refs/remotes/$remote/$b" >/dev/null 2>&1; then
682 verbose git checkout $checkoutflags --track -b "$b" "$remote/$b"
684 $ECHO "WTF? Not even branch $b doesn't exist in $d"
689 checkself "$cmd" "$@"
692 allrepos ifrepoenabled 0 checkout_
694 $ECHO "The requested branch was not found in any repository."
702 if [ -z "$askbranch" ]; then
710 r=`git symbolic-ref HEAD`
712 dv=`visible_repo_name "$d"`
716 if [ -n "$askbranch" ]; then
720 dv=`visible_repo_name "$d"`
721 enter "$d0/$d" verbose
722 if git rev-parse "refs/heads/$askbranch" >/dev/null 2>&1; then
723 $ECHO "Already having this branch in $dv."
725 if yesno "Branch in $dv?"; then
726 if [ -n "$srcbranch" ]; then
730 verbose git fetch origin || true
732 verbose git checkout -b "$askbranch" "$b"
733 verbose git config "branch.$askbranch.remote" "$remote"
734 verbose git config "branch.$askbranch.merge" "refs/heads/$askbranch"
739 allrepos ifrepoenabled 0 branch_
741 allrepos ifrepoenabled 0 branch_show_
748 dv=`visible_repo_name "$d"`
749 enter "$d0/$d" verbose
750 r=`git symbolic-ref HEAD`
752 diffdata=`git diff --color HEAD`
753 if [ -n "$diffdata" ]; then
754 # we have uncommitted changes
755 if yesno "Uncommitted changes in \"$r\" in $dv. Commit?" '$ECHO "$diffdata" | less -r'; then
756 verbose git commit -a
759 rem=`git config "branch.$r.remote" || $ECHO origin`
760 bra=`git config "branch.$r.merge" || $ECHO "$r"`
761 upstream="$rem/${bra#refs/heads/}"
762 if ! git rev-parse "$upstream" >/dev/null 2>&1; then
763 upstream="origin/$branch"
765 logdata=`git log --color "$upstream".."$r"`
766 if [ -n "$logdata" ]; then
767 if yesno "Push \"$r\" in $dv?" '$ECHO "$logdata" | less -r'; then
768 verbose git push "$rem" HEAD
771 if [ x"$submit" = x"-s" ]; then
774 verbose git push "$rem" HEAD:"${bra%%/*}/finished/${bra#*/}"
780 allrepos ifrepoenabled 0 push_
784 if [ x"$1" = x"-k" ]; then
789 if verbose cd "$d0/$d"; then
809 # ./all clean [-m] [-f | -fu | -fU] [-r] [-D]
810 # ./all clean --reclone
813 if [ x"$X" = x"--reclone" ]; then
820 elif [ x"$X" = x"-f" ]; then
822 elif [ x"$X" = x"-u" ]; then
824 elif [ x"$X" = x"-U" ]; then
827 elif [ x"$X" = x"-fu" ]; then
830 elif [ x"$X" = x"-fU" ]; then
834 elif [ x"$X" = x"-m" ]; then
836 elif [ x"$X" = x"-r" ]; then
838 elif [ x"$X" = x"-D" ]; then
840 elif $ECHO "$X" | grep '^-FFFF*UUUU*$' >/dev/null; then
843 msg " ,--'-\\P/\`\\ FFFFFFF"
844 msg " __/_ B/,-.\\ FFFFFFF"
845 msg " / _\\ (// O\\\\ FFFFFF"
846 msg "| (O \`) _\\._ _)\\ FFFUU"
847 msg "| |___/.^d0~~\"\\ \\ UUUU"
848 msg "| |\`~' \\ | UUUU"
849 msg "| | __,C>|| UUUU"
850 msg "\\ /_ ,-/,-' | UUUU"
851 msg " \\\\_ \\_>~' / UUUU-"
854 msg "Unknown arg: $X"
865 if $gotoupstream; then
867 msg "Must also use -f (delete local changes) when using -u"
871 if $fetchupstream; then
872 verbose git fetch origin
873 verbose git remote prune origin
875 verbose git checkout -f "$branch"
876 verbose git reset --hard origin/"$branch"
878 r=`git symbolic-ref HEAD`
880 rem=`git config "branch.$r.remote" || $ECHO origin`
881 bra=`git config "branch.$r.merge" || $ECHO "$r"`
882 upstream="$rem/${bra#refs/heads/}"
883 if $fetchupstream; then
884 for t in `git tag -l "xonotic-v"*`; do
885 verbose git tag -d "$t"
887 verbose git fetch "$rem"
888 verbose git remote prune "$rem"
890 if ! git rev-parse "$upstream" >/dev/null 2>&1; then
891 upstream="origin/$branch"
893 verbose git reset --hard "$upstream"
895 elif $gotomaster; then
897 verbose git checkout -f "$branch"
898 verbose git reset --hard
900 verbose git checkout "$branch"
903 verbose git reset --hard
905 if $rmuntracked; then
908 verbose git clean -df || true
911 verbose git clean -xdf || true
915 if $killbranches; then
916 git for-each-ref --format='%(refname)' refs/heads/ | while IFS= read -r B; do
917 if [ x"$B" != x"`git symbolic-ref HEAD`" ]; then
918 verbose git branch -D "${B#refs/heads/}"
921 git rev-parse refs/heads/master >/dev/null 2>&1 || verbose git branch --track master origin/master || true
922 git rev-parse "refs/heads/$branch" >/dev/null 2>&1 || verbose git branch --track "$branch" origin/"$branch" || true
924 checkself "$cmd" "$@"
926 allrepos ifrepoenabled 0 clean_
929 $ECHO " $SELF branch <branch>"
930 $ECHO " $SELF branch <remote> <branch> [<srcbranch>]"
931 $ECHO " $SELF checkout|switch <branch>"
932 $ECHO " $SELF checkout|switch <remote>/<branch>"
933 $ECHO " $SELF clean [-m] [-f | -fu | -fU] [-r] [-D]"
934 $ECHO " $SELF clean --reclone"
935 $ECHO " $SELF each|foreach [-k] command..."
936 $ECHO " $SELF fix_upstream_rebase"
937 $ECHO " $SELF keygen"
938 $ECHO " $SELF push|commit [-s]"
939 $ECHO " $SELF update|pull [-N] [-s | -h [-p] | -g [-p]] [-l de|nl|default]"