bisect: add support for bisecting bare repositories
authorJon Seymour <jon.seymour@gmail.com>
Tue, 9 Aug 2011 02:11:54 +0000 (12:11 +1000)
committerJunio C Hamano <gitster@pobox.com>
Tue, 9 Aug 2011 17:26:18 +0000 (10:26 -0700)
This enhances the support for bisecting history in bare repositories.

The "git bisect" command no longer needs to be run inside a repository
with a working tree; it defaults to --no-checkout when run in a bare
repository.

Two tests are included to demonstrate this behaviour.

Suggested-by: Junio C Hamano <gitster@pobox.com>
Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Jon Seymour <jon.seymour@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/git-bisect.txt
git-bisect.sh
git.c
t/t6030-bisect-porcelain.sh

index 41e6ca832ba7636db4517e0b3dd09fbb07edbdcb..e4f46bc18dba1e55da83e4af76b8a7f30a7f40be 100644 (file)
@@ -273,6 +273,8 @@ it point to the commit that should be tested.
 +
 This option may be useful when the test you would perform in each step
 does not require a checked out tree.
++
+If the repository is bare, `--no-checkout` is assumed.
 
 EXAMPLES
 --------
index 22c4da5a9a77d0124e613303f29adbbb537c60be..e0ca3fb853083d0ebdfe11e5eb3fead4723248ad 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"
@@ -79,7 +78,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
diff --git a/git.c b/git.c
index 8828c18d6cce99b8becfbb510fcc9b2b752598ca..7fdcab29345b071a29a8040a39cfe2b6d4b29d7c 100644 (file)
--- a/git.c
+++ b/git.c
@@ -320,7 +320,7 @@ static void handle_internal_command(int argc, const char **argv)
                { "annotate", cmd_annotate, RUN_SETUP },
                { "apply", cmd_apply, RUN_SETUP_GENTLY },
                { "archive", cmd_archive },
-               { "bisect--helper", cmd_bisect__helper, RUN_SETUP | NEED_WORK_TREE },
+               { "bisect--helper", cmd_bisect__helper, RUN_SETUP },
                { "blame", cmd_blame, RUN_SETUP },
                { "branch", cmd_branch, RUN_SETUP },
                { "bundle", cmd_bundle, RUN_SETUP_GENTLY },
index 4fb7d11c4739a0c61f0d0157a92b88e25b02f903..62125eca8163f1ca52d57959fb872340479b9002 100755 (executable)
@@ -592,6 +592,37 @@ test_expect_success 'erroring out when using bad path parameters' '
        grep "bad path parameters" error.txt
 '
 
+test_expect_success 'test bisection on bare repo - --no-checkout specified' '
+       git clone --bare . bare.nocheckout &&
+       (
+               cd bare.nocheckout &&
+               git bisect start --no-checkout &&
+               git bisect good $HASH1 &&
+               git bisect bad $HASH4 &&
+               git bisect run eval \
+                       "test \$(git rev-list BISECT_HEAD ^$HASH2 --max-count=1 | wc -l) = 0" \
+                       >../nocheckout.log &&
+               git bisect reset
+       ) &&
+       grep "$HASH3 is the first bad commit" nocheckout.log
+'
+
+
+test_expect_success 'test bisection on bare repo - --no-checkout defaulted' '
+       git clone --bare . bare.defaulted &&
+       (
+               cd bare.defaulted &&
+               git bisect start &&
+               git bisect good $HASH1 &&
+               git bisect bad $HASH4 &&
+               git bisect run eval \
+                       "test \$(git rev-list BISECT_HEAD ^$HASH2 --max-count=1 | wc -l) = 0" \
+                       >../defaulted.log &&
+               git bisect reset
+       ) &&
+       grep "$HASH3 is the first bad commit" defaulted.log
+'
+
 #
 # This creates a broken branch which cannot be checked out because
 # the tree created has been deleted.