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 # first result is to be ignored, but we use it to check status
57 git ls-remote "$1" refs/heads/master >/dev/null 2>&1 || return 1
58 # if we can't time, we only check availability
59 if ! { time -p true; } >/dev/null 2>&1; then
63 # now actually time it
66 { 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
67 # unit: clock ticks (depends on what "time" returns
78 bestmirror_firstrepo()
80 if [ -z "$testrepo" ]; then
84 allrepos bestmirror_firstrepo
87 if [ x"$oldurl" = x"$3" ]; then
92 allmirrors bestmirror_findold
94 if [ -z "$newprotocol" ]; then
95 newprotocol=$oldprotocol
97 if [ -z "$newlocation" ]; then
98 newlocation=$oldlocation
105 bestmirror_benchmark()
108 # empty location is not allowed
111 case " $newprotocol " in
113 # no protocol requested? all match
122 # prefer location match
123 case " $newlocation " in
127 case " $newlocation " in
136 case " $newlocation " in
141 case " $newlocation " in
149 msg "Testing speed of $3..."
151 # only working mirrors
152 if ! thistime=`mirrorspeed "$3$testrepo"`; then
156 thistime=$(($thistime $4))
159 # anything is better than nothing
160 if [ -z "$besttime" ]; then
168 # prefer location match
169 case " $newlocation " in
171 case " $newlocation " in
186 # if newlocation matches bestlocation, then we already discarded it above
190 # if we get here, we must compare mirror speed as we have more than one match
191 if [ $thistime -gt $besttime ]; then
193 elif [ $thistime -lt $besttime ]; then
199 # both location and time match. Random decision.
200 bestcount=$(($bestcount + 1))
201 if [ $((($RANDOM + 0) % $bestcount)) -eq 0 ]; then
205 allmirrors bestmirror_benchmark
211 [ x"$1" = x"$3" ] || return
222 allrepos testrepoflag_ "$1" "$2" | grep ^0 >/dev/null
229 # if we have .no file, skip
230 if [ -f "$d.no" ]; then
231 msg "Repository $d disabled by a .no file, delete $d.no to enable"
234 # if .yes file exists, always keep it
235 if [ -f "$d.yes" ]; then
236 msg "Repository $d enabled by a .yes file"
240 # remove broken clones so they don't mess up stuff
241 if [ x"$d" != x"." ] && [ -d "$d" ] && ! [ -d "$d/.git" ]; then
242 msg "$d exists but has no .git subdir. Probably a broken clone. Deleting."
246 # if we have the dir, always keep it
248 msg "Repository $d enabled because it already exists"
252 # if we have matching pk3, skip
253 if [ x"$p" != x"$d" ] && [ -f "$p" ]; then
254 msg "Repository $d disabled by matching .pk3 file, delete $p or create $d.yes to enable"
257 # if "no" flag is set, skip
258 if matchrepoflag "$f" no; then
259 msg "Repository $d disabled by default, create $d.yes to enable"
263 msg "Repository $d enabled by default"
269 $ECHO `allrepos listrepos_`
276 eval ire_test=\$$(($1 + 3))
284 check_mergeconflict() # overrides the one in ./all
286 if git ls-files -u | grep ' 1 '; then
288 $ECHO "MERGE CONFLICT."
289 $ECHO "change into the \"$1\" project directory, and then:"
290 $ECHO "- edit the files mentioned above with your favorite editor,"
291 $ECHO " and fix the conflicts (marked with <<<<<<< blocks)"
292 $ECHO "- for binary files, you can select the files using"
293 $ECHO " git checkout --ours or git checkout --theirs"
294 $ECHO "- when done with a file, 'git add' the file"
295 $ECHO "- when done, 'git commit'"
305 $ECHO "the root directory"
313 fix_upstream_rebase()
315 if [ -z "$r_me" ] || [ -z "$r_other" ]; then
319 # one of the two sides of the merge should be remote upstream, or all is fine
320 r_r=`git symbolic-ref HEAD`
321 r_r=${r_r#refs/heads/}
322 r_rem=`git config "branch.$r_rem.remote" || $ECHO origin`
323 r_bra=`git config "branch.$r_bra.merge" || $ECHO "$r_r"`
324 r_bra=${r_bra#refs/heads/}
325 if [ x"$r_me" != x"`git rev-parse "$r_rem/$r_bra"`" ]; then
326 if [ x"$r_other" != x"`git rev-parse "$r_rem/$r_bra"`" ]; then
331 r_base=`git merge-base "$r_me" "$r_other"`
333 # no merge-base? upstream did filter-branch
334 if [ -n "$r_base" ]; then
335 # otherwise, check if the two histories are "similar"
336 r_l_me=`git log --pretty="format:%s" "$r_other".."$r_me" | grep -v "^Merge" | sort -u`
337 r_l_other=`git log --pretty="format:%s" "$r_me".."$r_other" | grep -v "^Merge" | sort -u`
339 # heuristics: upstream rebase/filter-branch if more than 50% of the commits of one of the sides are in the other too
340 r_lc_me=`$ECHO "$r_l_me" | wc -l`
341 r_lc_other=`$ECHO "$r_l_other" | wc -l`
342 r_lc_together=`{ $ECHO "$r_l_me"; $ECHO "$r_l_other"; } | sort -u | wc -l`
343 r_lc_same=$(($r_lc_me + $r_lc_other - $r_lc_together))
345 if [ $(( $r_lc_same * 2 )) -gt $(( $r_lc_me )) ] || [ $(( $r_lc_same * 2 )) -gt $(( $r_lc_other )) ]; then
346 if yesno "Probable upstream rebase detected, automatically fix?" 'git log --oneline --graph --date-order --left-right "$r_other"..."$r_me"'; then
347 git reset --hard "$r_me"
357 fix_upstream_rebase_mergeok()
359 r_me=`git rev-parse --revs-only HEAD^1 2>/dev/null || true`
360 r_other=`git rev-parse --revs-only HEAD^2 2>/dev/null || true`
364 fix_upstream_rebase_mergefail()
366 r_me=`git rev-parse --revs-only HEAD 2>/dev/null || true`
367 r_other=`git rev-parse --revs-only MERGE_HEAD 2>/dev/null || true`
373 if ! [ -f ".git/config" ]; then
374 $ECHO "Not a git repository. Bailing out to not cause damage."
377 verbose git config remote.origin.url "$1"
379 verbose git config remote.origin.pushurl "$2"
381 verbose git config --unset remote.origin.pushurl || true
383 verbose git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
384 if testrepoflag "$d" noautocrlf; then
385 verbose git config --unset core.autocrlf || true
387 verbose git config core.autocrlf input
389 if [ -z "`git config push.default || true`" ]; then
390 verbose git config push.default current # or is tracking better?
392 verbose git config filter.mapclean.clean "tr -d '\r' | grep '^[^/]'"
393 verbose git config filter.mapclean.smudge "cat"
398 while [ $# -gt 4 ]; do
403 if [ -n "$pushbase" ]; then
404 pushurl="$pushbase$2"
415 fix_upstream_rebase_()
418 enter "$d0/$d" verbose
419 verbose fix_upstream_rebase_mergefail && verbose fix_upstream_rebase_mergeok
421 allrepos ifrepoenabled 0 fix_upstream_rebase_
427 if [ -f "$d0/$d/.git/config" ]; then
429 fix_git_config "$url" "$pushurl"
433 allrepos ifrepoenabled 0 fix_config_
436 if [ -f ~/.ssh/id_rsa.pub ]; then
438 msg "A key already exists and no new one will be generated. If you"
439 msg "already have done the procedure for getting your key approved, you"
440 msg "can skip the following paragraph and already use the repository."
442 msg "To get access, your key has to be approved first. For that, visit"
443 msg "$devsite_url, then log in, create a \"New Issue\" on"
444 msg "the \"Support\" tracker in the \"Repository\" category where you"
445 msg "apply for access and paste the following output into the issue:"
447 msg "`cat ~/.ssh/id_rsa.pub`"
448 elif [ -f ~/.ssh/id_dsa.pub ]; then
450 msg "A key already exists and no new one will be generated. If you"
451 msg "already have done the procedure for getting your key approved, you"
452 msg "can skip the following paragraph and already use the repository."
454 msg "To get access, your key has to be approved first. For that, visit"
455 msg "$devsite_url, then log in, create a \"New Issue\" on"
456 msg "the \"Support\" tracker in the \"Repository\" category where you"
457 msg "apply for access and paste the following output into the issue:"
459 msg "`cat ~/.ssh/id_dsa.pub`"
462 msg "No key has been generated yet. One will be generated now."
463 msg "If other people are using your computer, it is recommended"
464 msg "to specify a passphrase. Otherwise you can simply hit ENTER"
465 msg "when asked for a passphrase."
467 ssh-keygen -t rsa -b 4096 -f ~/.ssh/id_rsa
469 msg "To get access, your key has to be approved first. For that, visit"
470 msg "$devsite_url, then log in, create a \"New Issue\" on"
471 msg "the \"Support\" tracker in the \"Repository\" category where you"
472 msg "apply for access and paste the following output into the issue:"
474 msg "`cat ~/.ssh/id_rsa.pub`"
477 msg "Note that you will only have write access to branches that start"
478 msg "with your user name."
480 msg "Once you have gotten access, run ./all update -p"
484 need_bestmirror=false
490 case "`git config xonotic.all.mirrorselection 2>/dev/null || true`" in
497 newprotocol="git http"
502 newprotocol= # same protocol
508 if $need_bestmirror; then
512 if [ x"$base" = x"$3" ]; then
516 allmirrors identifymirror_
519 msg "Current mirror not found = $base"
520 msg "but the last pull attempt failed."
522 msg "Use ./all update -l any to switch to the best mirror."
524 need_bestmirror=false
529 if [ x"$1" = x"-N" ]; then
531 elif [ x"$1" = x"-p" ]; then
534 elif [ x"$1" = x"-s" ]; then
537 elif [ x"$1" = x"-g" ]; then
540 elif [ x"$1" = x"-h" ]; then
543 elif [ x"$1" = x"-l" ]; then
553 if $need_bestmirror; then
554 newbase=`bestmirror "$base" "$newprotocol" "$newlocation"`
555 if [ -z "$newbase" ]; then
556 msg "Could not find any good mirror. Maybe try again later."
557 git config xonotic.all.mirrorselection try_all
560 if [ -n "$newpushprotocol" ]; then
561 if [ -n "$pushbase" ]; then
562 newpushbase=`bestmirror "$pushbase" "$newpushprotocol" "$newlocation"`
564 newpushbase=`bestmirror "$base" "$newpushprotocol" "$newlocation"`
567 newpushbase=$pushbase
570 if [ x"$base" != x"$newbase" ] || [ x"$pushbase" != x"$newpushbase" ]; then
572 pushbase=$newpushbase
576 if [ x"$d" = x"." ]; then
577 fix_git_config "$url" "$pushurl"
580 allrepos ifrepoenabled 0 seturl_
582 git config xonotic.all.mirrorselection done
590 if [ -f "$d0/$d/.git/config" ]; then
591 # if we have .no file, skip
592 if [ -f "$d0/$d.no" ]; then
593 msg "Repository $d disabled by a .no file, delete $d.no to enable; thus, not updated"
597 enter "$d0/$d" verbose
598 r=`git symbolic-ref HEAD`
600 if git config branch.$r.remote >/dev/null 2>&1; then
601 o=`( cd "$d0" && git config xonotic.all.mirrorselection 2>/dev/null || true )`
602 ( cd "$d0" && git config xonotic.all.mirrorselection try_same )
603 if ! verbose git pull; then
604 fix_upstream_rebase_mergefail || true
605 check_mergeconflict "$d"
606 $ECHO "Pulling failed. Press ENTER to continue, or Ctrl-C to abort."
609 ( cd "$d0" && git config xonotic.all.mirrorselection "$o" )
610 fix_upstream_rebase_mergeok || true
615 checkself "$cmd" "$@"
617 verbose git remote prune origin
621 if [ -d "$d0/$d" ]; then
622 if yesno "$d0/$d is in the way, get rid of it and reclone?"; then
623 verbose rm -rf "$d0/$d"
625 echo "Note: $d0/$d will stay broken."
629 o=`git config xonotic.all.mirrorselection 2>/dev/null || true`
630 git config xonotic.all.mirrorselection try_same
631 verbose git clone "$url" "$d0/$d"
632 git config xonotic.all.mirrorselection "$o"
633 enter "$d0/$d" verbose
634 fix_git_config "$url" "$pushurl"
635 if [ "$branch" != "master" ]; then
636 verbose git checkout --track -b "$branch" origin/"$branch"
641 allrepos ifrepoenabled 0 pull_
645 if [ x"$1" = x"-f" ]; then
651 if [ -z "$branch" ]; then
654 askbranch=${remote#origin/}
663 if [ -n "$checkoutflags" ]; then
664 set -- -f "$@" # to make checkself work again
670 enter "$d0/$d" verbose
672 if [ -n "$b" ] && git rev-parse "refs/heads/$b" >/dev/null 2>&1; then
674 verbose git checkout $checkoutflags "$b"
675 elif [ -n "$b" ] && git rev-parse "refs/remotes/$remote/$b" >/dev/null 2>&1; then
677 verbose git checkout $checkoutflags --track -b "$b" "$remote/$b"
680 if git rev-parse "refs/heads/$b" >/dev/null 2>&1; then
681 verbose git checkout $checkoutflags "$b"
682 elif git rev-parse "refs/remotes/$remote/$b" >/dev/null 2>&1; then
683 verbose git checkout $checkoutflags --track -b "$b" "$remote/$b"
685 $ECHO "WTF? Not even branch $b doesn't exist in $d"
690 checkself "$cmd" "$@"
693 allrepos ifrepoenabled 0 checkout_
695 $ECHO "The requested branch was not found in any repository."
703 if [ -z "$askbranch" ]; then
711 r=`git symbolic-ref HEAD`
713 dv=`visible_repo_name "$d"`
717 if [ -n "$askbranch" ]; then
721 dv=`visible_repo_name "$d"`
722 enter "$d0/$d" verbose
723 if git rev-parse "refs/heads/$askbranch" >/dev/null 2>&1; then
724 $ECHO "Already having this branch in $dv."
726 if yesno "Branch in $dv?"; then
727 if [ -n "$srcbranch" ]; then
731 verbose git fetch origin || true
733 verbose git checkout -b "$askbranch" "$b"
734 verbose git config "branch.$askbranch.remote" "$remote"
735 verbose git config "branch.$askbranch.merge" "refs/heads/$askbranch"
740 allrepos ifrepoenabled 0 branch_
742 allrepos ifrepoenabled 0 branch_show_
749 dv=`visible_repo_name "$d"`
750 enter "$d0/$d" verbose
751 r=`git symbolic-ref HEAD`
753 diffdata=`git diff --color HEAD`
754 if [ -n "$diffdata" ]; then
755 # we have uncommitted changes
756 if yesno "Uncommitted changes in \"$r\" in $dv. Commit?" '$ECHO "$diffdata" | less -r'; then
757 verbose git commit -a
760 rem=`git config "branch.$r.remote" || $ECHO origin`
761 bra=`git config "branch.$r.merge" || $ECHO "$r"`
762 upstream="$rem/${bra#refs/heads/}"
763 if ! git rev-parse "$upstream" >/dev/null 2>&1; then
764 upstream="origin/$branch"
766 logdata=`git log --color "$upstream".."$r"`
767 if [ -n "$logdata" ]; then
768 if yesno "Push \"$r\" in $dv?" '$ECHO "$logdata" | less -r'; then
769 verbose git push "$rem" HEAD
772 if [ x"$submit" = x"-s" ]; then
775 verbose git push "$rem" HEAD:"${bra%%/*}/finished/${bra#*/}"
781 allrepos ifrepoenabled 0 push_
785 if [ x"$1" = x"-k" ]; then
790 if verbose cd "$d0/$d"; then
810 # ./all clean [-m] [-f | -fu | -fU] [-r] [-D]
811 # ./all clean --reclone
814 if [ x"$X" = x"--reclone" ]; then
821 elif [ x"$X" = x"-f" ]; then
823 elif [ x"$X" = x"-u" ]; then
825 elif [ x"$X" = x"-U" ]; then
828 elif [ x"$X" = x"-fu" ]; then
831 elif [ x"$X" = x"-fU" ]; then
835 elif [ x"$X" = x"-m" ]; then
837 elif [ x"$X" = x"-r" ]; then
839 elif [ x"$X" = x"-D" ]; then
841 elif $ECHO "$X" | grep '^-FFFF*UUUU*$' >/dev/null; then
844 msg " ,--'-\\P/\`\\ FFFFFFF"
845 msg " __/_ B/,-.\\ FFFFFFF"
846 msg " / _\\ (// O\\\\ FFFFFF"
847 msg "| (O \`) _\\._ _)\\ FFFUU"
848 msg "| |___/.^d0~~\"\\ \\ UUUU"
849 msg "| |\`~' \\ | UUUU"
850 msg "| | __,C>|| UUUU"
851 msg "\\ /_ ,-/,-' | UUUU"
852 msg " \\\\_ \\_>~' / UUUU-"
855 msg "Unknown arg: $X"
866 if $gotoupstream; then
868 msg "Must also use -f (delete local changes) when using -u"
872 if $fetchupstream; then
873 verbose git fetch origin
874 verbose git remote prune origin
876 verbose git checkout -f "$branch"
877 verbose git reset --hard origin/"$branch"
879 r=`git symbolic-ref HEAD`
881 rem=`git config "branch.$r.remote" || $ECHO origin`
882 bra=`git config "branch.$r.merge" || $ECHO "$r"`
883 upstream="$rem/${bra#refs/heads/}"
884 if $fetchupstream; then
885 for t in `git tag -l "xonotic-v"*`; do
886 verbose git tag -d "$t"
888 verbose git fetch "$rem"
889 verbose git remote prune "$rem"
891 if ! git rev-parse "$upstream" >/dev/null 2>&1; then
892 upstream="origin/$branch"
894 verbose git reset --hard "$upstream"
896 elif $gotomaster; then
898 verbose git checkout -f "$branch"
899 verbose git reset --hard
901 verbose git checkout "$branch"
904 verbose git reset --hard
906 if $rmuntracked; then
909 verbose git clean -df || true
912 verbose git clean -xdf || true
916 if $killbranches; then
917 git for-each-ref --format='%(refname)' refs/heads/ | while IFS= read -r B; do
918 if [ x"$B" != x"`git symbolic-ref HEAD`" ]; then
919 verbose git branch -D "${B#refs/heads/}"
922 git rev-parse refs/heads/master >/dev/null 2>&1 || verbose git branch --track master origin/master || true
923 git rev-parse "refs/heads/$branch" >/dev/null 2>&1 || verbose git branch --track "$branch" origin/"$branch" || true
925 checkself "$cmd" "$@"
927 allrepos ifrepoenabled 0 clean_
930 $ECHO " $SELF branch <branch>"
931 $ECHO " $SELF branch <remote> <branch> [<srcbranch>]"
932 $ECHO " $SELF checkout|switch <branch>"
933 $ECHO " $SELF checkout|switch <remote>/<branch>"
934 $ECHO " $SELF clean [-m] [-f | -fu | -fU] [-r] [-D]"
935 $ECHO " $SELF clean --reclone"
936 $ECHO " $SELF each|foreach [-k] command..."
937 $ECHO " $SELF fix_upstream_rebase"
938 $ECHO " $SELF keygen"
939 $ECHO " $SELF push|commit [-s]"
940 $ECHO " $SELF update|pull [-N] [-s | -h [-p] | -g [-p]] [-l de|nl|default]"