{"thread":{"id":"13625","subject":"[PATCH 3/3] bisect: trap critical errors in \"bisect_start\"","startedAt":"2008-05-22T22:39:22Z","lastAt":"2008-05-22T22:39:22Z","messageCount":1,"participants":["Christian Couder"],"isPatch":true,"patchVersion":1,"patchTotal":3},"messages":[{"id":"77507","messageId":"20080523003922.2cba6656.chriscool@tuxfamily.org","threadId":"13625","inReplyTo":null,"subject":"[PATCH 3/3] bisect: trap critical errors in \"bisect_start\"","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2008-05-22T22:39:22Z","receivedAt":"2008-05-22T22:39:22Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"Before this patch, when using \"git bisect start\" with mistaken revs\nor when the checkout of the branch we want to test failed, we exited\nafter having written files like \".git/BISECT_START\",\n\".git/BISECT_NAMES\" and after having written \"refs/bisect/bad\" and\n\"refs/bisect/good-*\" refs.\n\nWith this patch we trap all errors that can happen when writing the\nnew state and when we are in \"bisect_next\". So that we can try to\nclean up everything in case of problems, using \"bisect_clean_state\".\n\nThis patch also contains a \"bisect_write\" cleanup to make it exit\non error and return 0 otherwise.\n\nSigned-off-by: Christian Couder <chriscool@tuxfamily.org>\n---\n git-bisect.sh               |   30 ++++++++++++++++++++++++------\n t/t6030-bisect-porcelain.sh |   10 ++++------\n 2 files changed, 28 insertions(+), 12 deletions(-)\n\ndiff --git a/git-bisect.sh b/git-bisect.sh\nindex 0dcb526..57168b0 100755\n--- a/git-bisect.sh\n+++ b/git-bisect.sh\n@@ -133,11 +133,29 @@ bisect_start() {\n \t    esac\n \tdone\n \n-\tsq \"$@\" >\"$GIT_DIR/BISECT_NAMES\"\n-\techo \"$start_head\" >\"$GIT_DIR/BISECT_START\"\n-\teval \"$eval\"\n-\techo \"git-bisect start$orig_args\" >>\"$GIT_DIR/BISECT_LOG\"\n+\t#\n+\t# Change state.\n+\t# In case of mistaken revs or checkout error, or signals received,\n+\t# \"bisect_auto_next\" below may exit or misbehave.\n+\t# We have to trap this to be able to clean up using\n+\t# \"bisect_clean_state\".\n+\t#\n+\ttrap 'bisect_clean_state' 0\n+\ttrap 'exit 255' 1 2 3 15\n+\n+\t#\n+\t# Write new start state.\n+\t#\n+\tsq \"$@\" >\"$GIT_DIR/BISECT_NAMES\" &&\n+\techo \"$start_head\" >\"$GIT_DIR/BISECT_START\" &&\n+\teval \"$eval\" &&\n+\techo \"git-bisect start$orig_args\" >>\"$GIT_DIR/BISECT_LOG\" || exit\n+\t#\n+\t# Check if we can proceed to the next bisect state.\n+\t#\n \tbisect_auto_next\n+\n+\ttrap '-' 0\n }\n \n bisect_write() {\n@@ -149,9 +167,9 @@ bisect_write() {\n \t\tgood|skip)\ttag=\"$state\"-\"$rev\" ;;\n \t\t*)\t\tdie \"Bad bisect_write argument: $state\" ;;\n \tesac\n-\tgit update-ref \"refs/bisect/$tag\" \"$rev\"\n+\tgit update-ref \"refs/bisect/$tag\" \"$rev\" || exit\n \techo \"# $state: $(git show-branch $rev)\" >>\"$GIT_DIR/BISECT_LOG\"\n-\ttest -z \"$nolog\" && echo \"git-bisect $state $rev\" >>\"$GIT_DIR/BISECT_LOG\"\n+\ttest -n \"$nolog\" || echo \"git-bisect $state $rev\" >>\"$GIT_DIR/BISECT_LOG\"\n }\n \n bisect_state() {\ndiff --git a/t/t6030-bisect-porcelain.sh b/t/t6030-bisect-porcelain.sh\nindex 68b5440..c4f074d 100755\n--- a/t/t6030-bisect-porcelain.sh\n+++ b/t/t6030-bisect-porcelain.sh\n@@ -147,7 +147,7 @@ test_expect_success 'bisect start: no \".git/BISECT_START\" if junk rev' '\n \ttest_must_fail test -e .git/BISECT_START\n '\n \n-test_expect_failure 'bisect start: no \".git/BISECT_START\" if mistaken rev' '\n+test_expect_success 'bisect start: no \".git/BISECT_START\" if mistaken rev' '\n \tgit bisect start $HASH4 $HASH1 -- &&\n \tgit bisect good &&\n \ttest_must_fail git bisect start $HASH1 $HASH4 -- &&\n@@ -156,19 +156,17 @@ test_expect_failure 'bisect start: no \".git/BISECT_START\" if mistaken rev' '\n \ttest_must_fail test -e .git/BISECT_START\n '\n \n-test_expect_failure 'bisect start: no \".git/BISECT_START\" if checkout error' '\n+test_expect_success 'bisect start: no \".git/BISECT_START\" if checkout error' '\n \techo \"temp stuff\" > hello &&\n \ttest_must_fail git bisect start $HASH4 $HASH1 -- &&\n \tgit branch &&\n \tgit branch > branch.output &&\n \tgrep \"* other\" branch.output > /dev/null &&\n \ttest_must_fail test -e .git/BISECT_START &&\n-\ttest -z \"$(git for-each-ref \"refs/bisect/*\")\"\n+\ttest -z \"$(git for-each-ref \"refs/bisect/*\")\" &&\n+\tgit checkout HEAD hello\n '\n \n-# This cleanup is needed whatever the result of the above test.\n-git checkout HEAD hello\n-\n # $HASH1 is good, $HASH4 is bad, we skip $HASH3\n # but $HASH2 is bad,\n # so we should find $HASH2 as the first bad commit\n-- \n1.5.5.1.501.g204d8.dirty\n"}]}