Code

Merge branch 'mf/curl-select-fdset' into maint
[git.git] / t / t6030-bisect-porcelain.sh
index 54b7ea6505d8c189c6c557cffd3d6518df06fb73..691e4a4481eba2994ec40e498d4cd25fcff67f26 100755 (executable)
@@ -126,6 +126,18 @@ test_expect_success 'bisect reset removes packed refs' '
        test -z "$(git for-each-ref "refs/heads/bisect")"
 '
 
+test_expect_success 'bisect reset removes bisect state after --no-checkout' '
+       git bisect reset &&
+       git bisect start --no-checkout &&
+       git bisect good $HASH1 &&
+       git bisect bad $HASH3 &&
+       git bisect next &&
+       git bisect reset &&
+       test -z "$(git for-each-ref "refs/bisect/*")" &&
+       test -z "$(git for-each-ref "refs/heads/bisect")" &&
+       test -z "$(git for-each-ref "BISECT_HEAD")"
+'
+
 test_expect_success 'bisect start: back in good branch' '
        git branch > branch.output &&
        grep "* other" branch.output > /dev/null &&
@@ -138,15 +150,23 @@ test_expect_success 'bisect start: back in good branch' '
        grep "* other" branch.output > /dev/null
 '
 
-test_expect_success 'bisect start: no ".git/BISECT_START" if junk rev' '
-       git bisect start $HASH4 $HASH1 -- &&
-       git bisect good &&
+test_expect_success 'bisect start: no ".git/BISECT_START" created if junk rev' '
+       git bisect reset &&
        test_must_fail git bisect start $HASH4 foo -- &&
        git branch > branch.output &&
        grep "* other" branch.output > /dev/null &&
        test_must_fail test -e .git/BISECT_START
 '
 
+test_expect_success 'bisect start: existing ".git/BISECT_START" not modified if junk rev' '
+       git bisect start $HASH4 $HASH1 -- &&
+       git bisect good &&
+       cp .git/BISECT_START saved &&
+       test_must_fail git bisect start $HASH4 foo -- &&
+       git branch > branch.output &&
+       test_i18ngrep "* (no branch)" branch.output > /dev/null &&
+       test_cmp saved .git/BISECT_START
+'
 test_expect_success 'bisect start: no ".git/BISECT_START" if mistaken rev' '
        git bisect start $HASH4 $HASH1 -- &&
        git bisect good &&
@@ -175,7 +195,7 @@ test_expect_success 'bisect skip: successfull result' '
        git bisect start $HASH4 $HASH1 &&
        git bisect skip &&
        git bisect bad > my_bisect_log.txt &&
-       grep "$HASH2 is first bad commit" my_bisect_log.txt &&
+       grep "$HASH2 is the first bad commit" my_bisect_log.txt &&
        git bisect reset
 '
 
@@ -261,7 +281,7 @@ test_expect_success \
      git bisect good $HASH1 &&
      git bisect bad $HASH4 &&
      git bisect run ./test_script.sh > my_bisect_log.txt &&
-     grep "$HASH3 is first bad commit" my_bisect_log.txt &&
+     grep "$HASH3 is the first bad commit" my_bisect_log.txt &&
      git bisect reset'
 
 # We want to automatically find the commit that
@@ -274,7 +294,7 @@ test_expect_success \
      chmod +x test_script.sh &&
      git bisect start $HASH4 $HASH1 &&
      git bisect run ./test_script.sh > my_bisect_log.txt &&
-     grep "$HASH4 is first bad commit" my_bisect_log.txt &&
+     grep "$HASH4 is the first bad commit" my_bisect_log.txt &&
      git bisect reset'
 
 # $HASH1 is good, $HASH5 is bad, we skip $HASH3
@@ -287,14 +307,14 @@ test_expect_success 'bisect skip: add line and then a new test' '
        git bisect start $HASH5 $HASH1 &&
        git bisect skip &&
        git bisect good > my_bisect_log.txt &&
-       grep "$HASH5 is first bad commit" my_bisect_log.txt &&
+       grep "$HASH5 is the first bad commit" my_bisect_log.txt &&
        git bisect log > log_to_replay.txt &&
        git bisect reset
 '
 
 test_expect_success 'bisect skip and bisect replay' '
        git bisect replay log_to_replay.txt > my_bisect_log.txt &&
-       grep "$HASH5 is first bad commit" my_bisect_log.txt &&
+       grep "$HASH5 is the first bad commit" my_bisect_log.txt &&
        git bisect reset
 '
 
@@ -335,7 +355,7 @@ test_expect_success 'bisect run & skip: find first bad' '
        chmod +x test_script.sh &&
        git bisect start $HASH7 $HASH1 &&
        git bisect run ./test_script.sh > my_bisect_log.txt &&
-       grep "$HASH6 is first bad commit" my_bisect_log.txt
+       grep "$HASH6 is the first bad commit" my_bisect_log.txt
 '
 
 test_expect_success 'bisect skip only one range' '
@@ -385,7 +405,7 @@ test_expect_success 'bisect does not create a "bisect" branch' '
        rev_hash6=$(git rev-parse --verify HEAD) &&
        test "$rev_hash6" = "$HASH6" &&
        git bisect good > my_bisect_log.txt &&
-       grep "$HASH7 is first bad commit" my_bisect_log.txt &&
+       grep "$HASH7 is the first bad commit" my_bisect_log.txt &&
        git bisect reset &&
        rev_hash6=$(git rev-parse --verify bisect) &&
        test "$rev_hash6" = "$HASH6" &&
@@ -423,7 +443,7 @@ test_expect_success 'skipped merge base when good and bad are siblings' '
        grep "merge base must be tested" my_bisect_log.txt &&
        grep $HASH4 my_bisect_log.txt &&
        git bisect skip > my_bisect_log.txt 2>&1 &&
-       grep "Warning" my_bisect_log.txt &&
+       grep "warning" my_bisect_log.txt &&
        grep $SIDE_HASH6 my_bisect_log.txt &&
        git bisect reset
 '
@@ -482,28 +502,17 @@ test_expect_success 'good merge bases when good and bad are siblings' '
        git bisect reset
 '
 
-check_trace() {
-       grep "$1" "$GIT_TRACE" | grep "\^$2" | grep "$3" >/dev/null
-}
-
 test_expect_success 'optimized merge base checks' '
-       GIT_TRACE="$(pwd)/trace.log" &&
-       export GIT_TRACE &&
        git bisect start "$HASH7" "$SIDE_HASH7" > my_bisect_log.txt &&
        grep "merge base must be tested" my_bisect_log.txt &&
        grep "$HASH4" my_bisect_log.txt &&
-       check_trace "rev-list" "$HASH7" "$SIDE_HASH7" &&
        git bisect good > my_bisect_log2.txt &&
        test -f ".git/BISECT_ANCESTORS_OK" &&
        test "$HASH6" = $(git rev-parse --verify HEAD) &&
-       : > "$GIT_TRACE" &&
        git bisect bad > my_bisect_log3.txt &&
-       test_must_fail check_trace "rev-list" "$HASH6" "$SIDE_HASH7" &&
        git bisect good "$A_HASH" > my_bisect_log4.txt &&
        grep "merge base must be tested" my_bisect_log4.txt &&
-       test_must_fail test -f ".git/BISECT_ANCESTORS_OK" &&
-       check_trace "rev-list" "$HASH6" "$A_HASH" &&
-       unset GIT_TRACE
+       test_must_fail test -f ".git/BISECT_ANCESTORS_OK"
 '
 
 # This creates another side branch called "parallel" with some files
@@ -528,13 +537,13 @@ test_expect_success '"parallel" side branch creation' '
        add_line_into_file "2(para): line 2 on parallel branch" dir2/file2 &&
        PARA_HASH2=$(git rev-parse --verify HEAD) &&
        add_line_into_file "3(para): line 3 on parallel branch" dir2/file3 &&
-       PARA_HASH3=$(git rev-parse --verify HEAD)
+       PARA_HASH3=$(git rev-parse --verify HEAD) &&
        git merge -m "merge HASH4 and PARA_HASH3" "$HASH4" &&
-       PARA_HASH4=$(git rev-parse --verify HEAD)
+       PARA_HASH4=$(git rev-parse --verify HEAD) &&
        add_line_into_file "5(para): add line on parallel branch" dir1/file1 &&
-       PARA_HASH5=$(git rev-parse --verify HEAD)
+       PARA_HASH5=$(git rev-parse --verify HEAD) &&
        add_line_into_file "6(para): add line on parallel branch" dir2/file2 &&
-       PARA_HASH6=$(git rev-parse --verify HEAD)
+       PARA_HASH6=$(git rev-parse --verify HEAD) &&
        git merge -m "merge HASH7 and PARA_HASH6" "$HASH7" &&
        PARA_HASH7=$(git rev-parse --verify HEAD)
 '
@@ -545,7 +554,7 @@ test_expect_success 'restricting bisection on one dir' '
        para1=$(git rev-parse --verify HEAD) &&
        test "$para1" = "$PARA_HASH1" &&
        git bisect bad > my_bisect_log.txt &&
-       grep "$PARA_HASH1 is first bad commit" my_bisect_log.txt
+       grep "$PARA_HASH1 is the first bad commit" my_bisect_log.txt
 '
 
 test_expect_success 'restricting bisection on one dir and a file' '
@@ -563,9 +572,175 @@ test_expect_success 'restricting bisection on one dir and a file' '
        para1=$(git rev-parse --verify HEAD) &&
        test "$para1" = "$PARA_HASH1" &&
        git bisect good > my_bisect_log.txt &&
-       grep "$PARA_HASH4 is first bad commit" my_bisect_log.txt
+       grep "$PARA_HASH4 is the first bad commit" my_bisect_log.txt
+'
+
+test_expect_success 'skipping away from skipped commit' '
+       git bisect start $PARA_HASH7 $HASH1 &&
+       para4=$(git rev-parse --verify HEAD) &&
+       test "$para4" = "$PARA_HASH4" &&
+        git bisect skip &&
+       hash7=$(git rev-parse --verify HEAD) &&
+       test "$hash7" = "$HASH7" &&
+        git bisect skip &&
+       para3=$(git rev-parse --verify HEAD) &&
+       test "$para3" = "$PARA_HASH3"
+'
+
+test_expect_success 'erroring out when using bad path parameters' '
+       test_must_fail git bisect start $PARA_HASH7 $HASH1 -- foobar 2> error.txt &&
+       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.
+#
+# H1-H2-H3-H4-H5-H6-H7  <--other
+#            \
+#             S5-S6'-S7'-S8'-S9  <--broken
 #
+# Commits marked with ' have a missing tree.
+#
+test_expect_success 'broken branch creation' '
+       git bisect reset &&
+       git checkout -b broken $HASH4 &&
+       git tag BROKEN_HASH4 $HASH4 &&
+       add_line_into_file "5(broken): first line on a broken branch" hello2 &&
+       git tag BROKEN_HASH5 &&
+       mkdir missing &&
+       :> missing/MISSING &&
+       git add missing/MISSING &&
+       git commit -m "6(broken): Added file that will be deleted"
+       git tag BROKEN_HASH6 &&
+       add_line_into_file "7(broken): second line on a broken branch" hello2 &&
+       git tag BROKEN_HASH7 &&
+       add_line_into_file "8(broken): third line on a broken branch" hello2 &&
+       git tag BROKEN_HASH8 &&
+       git rm missing/MISSING &&
+       git commit -m "9(broken): Remove missing file"
+       git tag BROKEN_HASH9 &&
+       rm .git/objects/39/f7e61a724187ab767d2e08442d9b6b9dab587d
+'
+
+echo "" > expected.ok
+cat > expected.missing-tree.default <<EOF
+fatal: unable to read tree 39f7e61a724187ab767d2e08442d9b6b9dab587d
+EOF
+
+test_expect_success 'bisect fails if tree is broken on start commit' '
+       git bisect reset &&
+       test_must_fail git bisect start BROKEN_HASH7 BROKEN_HASH4 2>error.txt &&
+       test_cmp expected.missing-tree.default error.txt
+'
+
+test_expect_success 'bisect fails if tree is broken on trial commit' '
+       git bisect reset &&
+       test_must_fail git bisect start BROKEN_HASH9 BROKEN_HASH4 2>error.txt &&
+       git reset --hard broken &&
+       git checkout broken &&
+       test_cmp expected.missing-tree.default error.txt
+'
+
+check_same()
+{
+       echo "Checking $1 is the same as $2" &&
+       git rev-parse "$1" > expected.same &&
+       git rev-parse "$2" > expected.actual &&
+       test_cmp expected.same expected.actual
+}
+
+test_expect_success 'bisect: --no-checkout - start commit bad' '
+       git bisect reset &&
+       git bisect start BROKEN_HASH7 BROKEN_HASH4 --no-checkout &&
+       check_same BROKEN_HASH6 BISECT_HEAD &&
+       git bisect reset
+'
+
+test_expect_success 'bisect: --no-checkout - trial commit bad' '
+       git bisect reset &&
+       git bisect start broken BROKEN_HASH4 --no-checkout &&
+       check_same BROKEN_HASH6 BISECT_HEAD &&
+       git bisect reset
+'
+
+test_expect_success 'bisect: --no-checkout - target before breakage' '
+       git bisect reset &&
+       git bisect start broken BROKEN_HASH4 --no-checkout &&
+       check_same BROKEN_HASH6 BISECT_HEAD &&
+       git bisect bad BISECT_HEAD &&
+       check_same BROKEN_HASH5 BISECT_HEAD &&
+       git bisect bad BISECT_HEAD &&
+       check_same BROKEN_HASH5 bisect/bad &&
+       git bisect reset
+'
+
+test_expect_success 'bisect: --no-checkout - target in breakage' '
+       git bisect reset &&
+       git bisect start broken BROKEN_HASH4 --no-checkout &&
+       check_same BROKEN_HASH6 BISECT_HEAD &&
+       git bisect bad BISECT_HEAD &&
+       check_same BROKEN_HASH5 BISECT_HEAD &&
+       git bisect good BISECT_HEAD &&
+       check_same BROKEN_HASH6 bisect/bad &&
+       git bisect reset
+'
+
+test_expect_success 'bisect: --no-checkout - target after breakage' '
+       git bisect reset &&
+       git bisect start broken BROKEN_HASH4 --no-checkout &&
+       check_same BROKEN_HASH6 BISECT_HEAD &&
+       git bisect good BISECT_HEAD &&
+       check_same BROKEN_HASH8 BISECT_HEAD &&
+       git bisect good BISECT_HEAD &&
+       check_same BROKEN_HASH9 bisect/bad &&
+       git bisect reset
+'
+
+test_expect_success 'bisect: demonstrate identification of damage boundary' "
+       git bisect reset &&
+       git checkout broken &&
+       git bisect start broken master --no-checkout &&
+       git bisect run \"\$SHELL_PATH\" -c '
+               GOOD=\$(git for-each-ref \"--format=%(objectname)\" refs/bisect/good-*) &&
+               git rev-list --objects BISECT_HEAD --not \$GOOD >tmp.\$\$ &&
+               git pack-objects --stdout >/dev/null < tmp.\$\$
+               rc=\$?
+               rm -f tmp.\$\$
+               test \$rc = 0' &&
+       check_same BROKEN_HASH6 bisect/bad &&
+       git bisect reset
+"
+
 test_done