]> git.xonotic.org Git - xonotic/xonotic.git/blobdiff - misc/tools/all/git.subr
Allow the repo's default branch to differ from master.
[xonotic/xonotic.git] / misc / tools / all / git.subr
index 073c5dbacedef5cea4376ebbb67dc8097b1af3a9..26b768c30478cd87988797ddb6ae8383dd7c3dad 100644 (file)
@@ -56,7 +56,7 @@ mirrorspeed()
        # first result is to be ignored, but we use it to check status
        git ls-remote "$1" refs/heads/master >/dev/null 2>&1 || return 1
        # if we can't time, we only check availability
-       if ! { time -p sh -c 'true'; } >/dev/null 2>&1; then
+       if ! $have_time; then
                echo 0
                return
        fi
@@ -64,7 +64,7 @@ mirrorspeed()
        (
                set +x
                export REPO=$1 # so that the sh -c subshell can use it
-               { time -p sh -c 'git ls-remote "$REPO" refs/heads/master >/dev/null 2>&1'; } 2>&1 >/dev/null | head -n 1 | cut -d ' ' -f 2 | tr -d . | sed 's,^0*,,' | grep . || echo 0
+               { measure_time sh -c 'git ls-remote "$REPO" refs/heads/master >/dev/null 2>&1'; } 2>&1 >/dev/null | head -n 1 | cut -d ' ' -f 2 | tr -d . | sed 's,^0*,,' | grep . || echo 0
                        # unit: clock ticks (depends on what "time" returns
        )
 }
@@ -620,10 +620,11 @@ case "$cmd" in
                                                o=`( cd "$d0" && git config xonotic.all.mirrorselection 2>/dev/null || true )`
                                                ( cd "$d0" && git config xonotic.all.mirrorselection try_same )
                                                if ! verbose git pull; then
-                                                       fix_upstream_rebase_mergefail || true
-                                                       check_mergeconflict "$d"
-                                                       $ECHO "Pulling failed. Press ENTER to continue, or Ctrl-C to abort."
-                                                       read -r DUMMY
+                                                       if fix_upstream_rebase_mergefail; then
+                                                               check_mergeconflict "$d"
+                                                               $ECHO "Pulling failed. Press ENTER to continue, or Ctrl-C to abort."
+                                                               read -r DUMMY
+                                                       fi
                                                else
                                                        ( cd "$d0" && git config xonotic.all.mirrorselection "$o" )
                                                        fix_upstream_rebase_mergeok || true
@@ -647,13 +648,10 @@ case "$cmd" in
                                fi
                                o=`git config xonotic.all.mirrorselection 2>/dev/null || true`
                                git config xonotic.all.mirrorselection try_same
-                               verbose git clone "$url" "$d0/$d"
+                               verbose git clone --branch "$branch" "$url" "$d0/$d"
                                git config xonotic.all.mirrorselection "$o"
                                enter "$d0/$d" verbose
                                fix_git_config "$url" "$pushurl"
-                               if [ "$branch" != "master" ]; then
-                                       verbose git checkout --track -b "$branch" origin/"$branch"
-                               fi
                                cd "$d0"
                        fi
                }
@@ -697,8 +695,10 @@ case "$cmd" in
                        else
                                b=$branch
                                if git rev-parse "refs/heads/$b" >/dev/null 2>&1; then
+                                       [ -n "$b" ] || exists=true
                                        verbose git checkout $checkoutflags "$b"
                                elif git rev-parse "refs/remotes/$remote/$b" >/dev/null 2>&1; then
+                                       [ -n "$b" ] || exists=true
                                        verbose git checkout $checkoutflags --track -b "$b" "$remote/$b"
                                else
                                        $ECHO "WTF? Not even branch $b doesn't exist in $d"
@@ -957,8 +957,17 @@ case "$cmd" in
                $ECHO "  $SELF keygen"
                $ECHO "  $SELF push|commit [-s]"
                $ECHO "  $SELF update|pull [-N] [-s | -h [-p] | -g [-p]] [-l de|nl|default]"
+               $ECHO "  $SELF grep \"<regex>\""
                handled=false
                ;;
+       grep)
+               for d in $repos; do
+                       if verbose cd "$d0/$d"; then
+                               git grep -In "$@" || true
+                               cd "$d0"
+                       fi
+               done
+               ;;
        *)
                handled=false
                ;;