Code

diff-index: enable recursive pathspec matching in unpack_trees
[git.git] / git-bisect.sh
index f5d9ede9dde988f7b2ce9dc89c1f86d74c30664c..99efbe884528ffa730d6c0297e20d9de93d5ad9e 100755 (executable)
@@ -29,7 +29,6 @@ Please use "git help bisect" to get the full man page.'
 OPTIONS_SPEC=
 . git-sh-setup
 . git-sh-i18n
-require_work_tree
 
 _x40='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
 _x40="$_x40$_x40$_x40$_x40$_x40$_x40$_x40$_x40"
@@ -46,10 +45,7 @@ bisect_head()
 
 bisect_autostart() {
        test -s "$GIT_DIR/BISECT_START" || {
-               (
-                       gettext "You need to start by \"git bisect start\"" &&
-                       echo
-               ) >&2
+               gettextln "You need to start by \"git bisect start\"" >&2
                if test -t 0
                then
                        # TRANSLATORS: Make sure to include [Y] and [n] in your
@@ -79,7 +75,12 @@ bisect_start() {
        orig_args=$(git rev-parse --sq-quote "$@")
        bad_seen=0
        eval=''
-       mode=''
+       if test "z$(git rev-parse --is-bare-repository)" != zfalse
+       then
+               mode=--no-checkout
+       else
+               mode=''
+       fi
        while [ $# -gt 0 ]; do
                arg="$1"
                case "$arg" in
@@ -94,9 +95,9 @@ bisect_start() {
                        die "$(eval_gettext "unrecognised option: '\$arg'")" ;;
                *)
                        rev=$(git rev-parse -q --verify "$arg^{commit}") || {
-                           test $has_double_dash -eq 1 &&
-                       die "$(eval_gettext "'\$arg' does not appear to be a valid revision")"
-                           break
+                               test $has_double_dash -eq 1 &&
+                               die "$(eval_gettext "'\$arg' does not appear to be a valid revision")"
+                               break
                        }
                        case $bad_seen in
                        0) state='bad' ; bad_seen=1 ;;
@@ -125,7 +126,8 @@ bisect_start() {
                start_head=$(cat "$GIT_DIR/BISECT_START")
                if test "z$mode" != "z--no-checkout"
                then
-                   git checkout "$start_head" --
+                       git checkout "$start_head" -- ||
+                       die "$(eval_gettext "Checking out '\$start_head' failed. Try 'git bisect reset <validbranch>'.")"
                fi
        else
                # Get rev from where we start.
@@ -198,7 +200,8 @@ is_expected_rev() {
 
 check_expected_revs() {
        for _rev in "$@"; do
-               if ! is_expected_rev "$_rev"; then
+               if ! is_expected_rev "$_rev"
+               then
                        rm -f "$GIT_DIR/BISECT_ANCESTORS_OK"
                        rm -f "$GIT_DIR/BISECT_EXPECTED_REV"
                        return
@@ -267,10 +270,7 @@ bisect_next_check() {
        t,,good)
                # have bad but not good.  we could bisect although
                # this is less optimum.
-               (
-                       gettext "Warning: bisecting only with a bad commit." &&
-                       echo
-               ) >&2
+               gettextln "Warning: bisecting only with a bad commit." >&2
                if test -t 0
                then
                        # TRANSLATORS: Make sure to include [Y] and [n] in your
@@ -286,18 +286,12 @@ bisect_next_check() {
 
                if test -s "$GIT_DIR/BISECT_START"
                then
-                       (
-                               gettext "You need to give me at least one good and one bad revisions.
-(You can use \"git bisect bad\" and \"git bisect good\" for that.)" &&
-                               echo
-                       ) >&2
+                       gettextln "You need to give me at least one good and one bad revisions.
+(You can use \"git bisect bad\" and \"git bisect good\" for that.)" >&2
                else
-                       (
-                               gettext "You need to start by \"git bisect start\".
+                       gettextln "You need to start by \"git bisect start\".
 You then need to give me at least one good and one bad revisions.
-(You can use \"git bisect bad\" and \"git bisect good\" for that.)" &&
-                               echo
-                       ) >&2
+(You can use \"git bisect bad\" and \"git bisect good\" for that.)" >&2
                fi
                exit 1 ;;
        esac
@@ -331,7 +325,8 @@ bisect_visualize() {
        if test $# = 0
        then
                if test -n "${DISPLAY+set}${SESSIONNAME+set}${MSYSTEM+set}${SECURITYSESSIONID+set}" &&
-                  type gitk >/dev/null 2>&1; then
+                       type gitk >/dev/null 2>&1
+               then
                        set gitk
                else
                        set git log
@@ -349,7 +344,7 @@ bisect_visualize() {
 
 bisect_reset() {
        test -s "$GIT_DIR/BISECT_START" || {
-               gettext "We are not bisecting."; echo
+               gettextln "We are not bisecting."
                return
        }
        case "$#" in
@@ -362,13 +357,11 @@ bisect_reset() {
        *)
                usage ;;
        esac
-       if ! test -f "$GIT_DIR/BISECT_HEAD"
+
+       if ! test -f "$GIT_DIR/BISECT_HEAD" && ! git checkout "$branch" --
        then
-               if ! git checkout "$branch" --
-               then
-                       die "$(eval_gettext "Could not check out original HEAD '\$branch'.
+               die "$(eval_gettext "Could not check out original HEAD '\$branch'.
 Try 'git bisect reset <commit>'.")"
-               fi
        fi
        bisect_clean_state
 }
@@ -400,7 +393,8 @@ bisect_replay () {
        while read git bisect command rev
        do
                test "$git $bisect" = "git bisect" -o "$git" = "git-bisect" || continue
-               if test "$git" = "git-bisect"; then
+               if test "$git" = "git-bisect"
+               then
                        rev="$command"
                        command="$bisect"
                fi
@@ -423,25 +417,25 @@ bisect_run () {
        while true
        do
                command="$@"
-               eval_gettext "running \$command"; echo
+               eval_gettextln "running \$command"
                "$@"
                res=$?
 
                # Check for really bad run error.
-               if [ $res -lt 0 -o $res -ge 128 ]; then
-                       (
-                               eval_gettext "bisect run failed:
-exit code \$res from '\$command' is < 0 or >= 128" &&
-                               echo
-                       ) >&2
+               if [ $res -lt 0 -o $res -ge 128 ]
+               then
+                       eval_gettextln "bisect run failed:
+exit code \$res from '\$command' is < 0 or >= 128" >&2
                        exit $res
                fi
 
                # Find current state depending on run success or failure.
                # A special exit code of 125 means cannot test.
-               if [ $res -eq 125 ]; then
+               if [ $res -eq 125 ]
+               then
                        state='skip'
-               elif [ $res -gt 0 ]; then
+               elif [ $res -gt 0 ]
+               then
                        state='bad'
                else
                        state='good'
@@ -454,25 +448,22 @@ exit code \$res from '\$command' is < 0 or >= 128" &&
                cat "$GIT_DIR/BISECT_RUN"
 
                if sane_grep "first bad commit could be any of" "$GIT_DIR/BISECT_RUN" \
-                       > /dev/null; then
-                       (
-                               gettext "bisect run cannot continue any more" &&
-                               echo
-                       ) >&2
+                       > /dev/null
+               then
+                       gettextln "bisect run cannot continue any more" >&2
                        exit $res
                fi
 
-               if [ $res -ne 0 ]; then
-                       (
-                               eval_gettext "bisect run failed:
-'bisect_state \$state' exited with error code \$res" &&
-                               echo
-                       ) >&2
+               if [ $res -ne 0 ]
+               then
+                       eval_gettextln "bisect run failed:
+'bisect_state \$state' exited with error code \$res" >&2
                        exit $res
                fi
 
-               if sane_grep "is the first bad commit" "$GIT_DIR/BISECT_RUN" > /dev/null; then
-                       gettext "bisect run success"; echo
+               if sane_grep "is the first bad commit" "$GIT_DIR/BISECT_RUN" > /dev/null
+               then
+                       gettextln "bisect run success"
                        exit 0;
                fi