Skip to content

Commit 24c5128

Browse files
jonseymourgitster
authored andcommitted
bisect: add support for bisecting bare repositories
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 <[email protected]> Reviewed-by: Jonathan Nieder <[email protected]> Signed-off-by: Jon Seymour <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 43b8ff4 commit 24c5128

File tree

4 files changed

+40
-3
lines changed

4 files changed

+40
-3
lines changed

Documentation/git-bisect.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,8 @@ it point to the commit that should be tested.
273273
+
274274
This option may be useful when the test you would perform in each step
275275
does not require a checked out tree.
276+
+
277+
If the repository is bare, `--no-checkout` is assumed.
276278

277279
EXAMPLES
278280
--------

git-bisect.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ Please use "git help bisect" to get the full man page.'
2929
OPTIONS_SPEC=
3030
. git-sh-setup
3131
. git-sh-i18n
32-
require_work_tree
3332

3433
_x40='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
3534
_x40="$_x40$_x40$_x40$_x40$_x40$_x40$_x40$_x40"
@@ -79,7 +78,12 @@ bisect_start() {
7978
orig_args=$(git rev-parse --sq-quote "$@")
8079
bad_seen=0
8180
eval=''
82-
mode=''
81+
if test "z$(git rev-parse --is-bare-repository)" != zfalse
82+
then
83+
mode=--no-checkout
84+
else
85+
mode=''
86+
fi
8387
while [ $# -gt 0 ]; do
8488
arg="$1"
8589
case "$arg" in

git.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ static void handle_internal_command(int argc, const char **argv)
320320
{ "annotate", cmd_annotate, RUN_SETUP },
321321
{ "apply", cmd_apply, RUN_SETUP_GENTLY },
322322
{ "archive", cmd_archive },
323-
{ "bisect--helper", cmd_bisect__helper, RUN_SETUP | NEED_WORK_TREE },
323+
{ "bisect--helper", cmd_bisect__helper, RUN_SETUP },
324324
{ "blame", cmd_blame, RUN_SETUP },
325325
{ "branch", cmd_branch, RUN_SETUP },
326326
{ "bundle", cmd_bundle, RUN_SETUP_GENTLY },

t/t6030-bisect-porcelain.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,37 @@ test_expect_success 'erroring out when using bad path parameters' '
592592
grep "bad path parameters" error.txt
593593
'
594594

595+
test_expect_success 'test bisection on bare repo - --no-checkout specified' '
596+
git clone --bare . bare.nocheckout &&
597+
(
598+
cd bare.nocheckout &&
599+
git bisect start --no-checkout &&
600+
git bisect good $HASH1 &&
601+
git bisect bad $HASH4 &&
602+
git bisect run eval \
603+
"test \$(git rev-list BISECT_HEAD ^$HASH2 --max-count=1 | wc -l) = 0" \
604+
>../nocheckout.log &&
605+
git bisect reset
606+
) &&
607+
grep "$HASH3 is the first bad commit" nocheckout.log
608+
'
609+
610+
611+
test_expect_success 'test bisection on bare repo - --no-checkout defaulted' '
612+
git clone --bare . bare.defaulted &&
613+
(
614+
cd bare.defaulted &&
615+
git bisect start &&
616+
git bisect good $HASH1 &&
617+
git bisect bad $HASH4 &&
618+
git bisect run eval \
619+
"test \$(git rev-list BISECT_HEAD ^$HASH2 --max-count=1 | wc -l) = 0" \
620+
>../defaulted.log &&
621+
git bisect reset
622+
) &&
623+
grep "$HASH3 is the first bad commit" defaulted.log
624+
'
625+
595626
#
596627
# This creates a broken branch which cannot be checked out because
597628
# the tree created has been deleted.

0 commit comments

Comments
 (0)