Merge branch 'gp/bisect-fix'
authorJunio C Hamano <gitster@pobox.com>
Mon, 12 May 2008 22:44:43 +0000 (15:44 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 12 May 2008 22:44:43 +0000 (15:44 -0700)
* gp/bisect-fix:
bisect: print an error message when "git rev-list --bisect-vars" fails
git-bisect.sh: don't accidentally override existing branch "bisect"

1  2 
Documentation/git-bisect.txt
git-bisect.sh
index 539f37df26b735b61325ec77994f95e63ddc3b48,0855b98b281c95830850b01a3db59a1ceb8f6eb2..0b8b0ebba758871ac9c79e729664b5057128e9ac
@@@ -15,7 -15,6 +15,7 @@@ DESCRIPTIO
  The command takes various subcommands, and different options depending
  on the subcommand:
  
 + git bisect help
   git bisect start [<bad> [<good>...]] [--] [<paths>...]
   git bisect bad [<rev>]
   git bisect good [<rev>...]
@@@ -30,12 -29,6 +30,12 @@@ This command uses 'git-rev-list --bisec
  binary search process to find which change introduced a bug, given an
  old "good" commit object name and a later "bad" commit object name.
  
 +Getting help
 +~~~~~~~~~~~~
 +
 +Use "git bisect" to get a short usage description, and "git bisect
 +help" or "git bisect -h" to get a long usage description.
 +
  Basic bisect commands: start, bad, good
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  
@@@ -85,7 -78,7 +85,7 @@@ Oh, and then after you want to reset t
  $ git bisect reset
  ------------------------------------------------
  
- to get back to the master branch, instead of being in one of the
+ to get back to the original branch, instead of being in one of the
  bisection branches ("git bisect start" will do that for you too,
  actually: it will reset the bisection state, and before it does that
  it checks that you're not using some old bisection branch).
@@@ -224,55 -217,6 +224,55 @@@ tree to the pristine state.  Finally th
  the status of the real test to let "git bisect run" command loop to
  know the outcome.
  
 +EXAMPLES
 +--------
 +
 +* Automatically bisect a broken build between v1.2 and HEAD:
 ++
 +------------
 +$ git bisect start HEAD v1.2 --      # HEAD is bad, v1.2 is good
 +$ git bisect run make                # "make" builds the app
 +------------
 +
 +* Automatically bisect a broken test suite:
 ++
 +------------
 +$ cat ~/test.sh
 +#!/bin/sh
 +make || exit 125                   # this "skip"s broken builds
 +make test                          # "make test" runs the test suite
 +$ git bisect start v1.3 v1.1 --    # v1.3 is bad, v1.1 is good
 +$ git bisect run ~/test.sh
 +------------
 ++
 +Here we use a "test.sh" custom script. In this script, if "make"
 +fails, we "skip" the current commit.
 ++
 +It's safer to use a custom script outside the repo to prevent
 +interactions between the bisect, make and test processes and the
 +script.
 ++
 +And "make test" should "exit 0", if the test suite passes, and
 +"exit 1" (for example) otherwise.
 +
 +* Automatically bisect a broken test case:
 ++
 +------------
 +$ cat ~/test.sh
 +#!/bin/sh
 +make || exit 125                     # this "skip"s broken builds
 +~/check_test_case.sh                 # does the test case passes ?
 +$ git bisect start HEAD HEAD~10 --   # culprit is among the last 10
 +$ git bisect run ~/test.sh
 +------------
 ++
 +Here "check_test_case.sh" should "exit 0", if the test case passes,
 +and "exit 1" (for example) otherwise.
 ++
 +It's safer if both "test.sh" and "check_test_case.sh" scripts are
 +outside the repo to prevent interactions between the bisect, make and
 +test processes and the scripts.
 +
  Author
  ------
  Written by Linus Torvalds <torvalds@osdl.org>
diff --combined git-bisect.sh
index d8d9bfde4cdd4b558992c68cb7cdaaa1b8a1212d,b1800edaf713f972131431fcd26b5e7f64f089fc..164e8ed81fc3ecb5d33dafb9af0992761bfe513d
@@@ -1,9 -1,7 +1,9 @@@
  #!/bin/sh
  
 -USAGE='[start|bad|good|skip|next|reset|visualize|replay|log|run]'
 -LONG_USAGE='git bisect start [<bad> [<good>...]] [--] [<pathspec>...]
 +USAGE='[help|start|bad|good|skip|next|reset|visualize|replay|log|run]'
 +LONG_USAGE='git bisect help
 +        print this long help message.
 +git bisect start [<bad> [<good>...]] [--] [<pathspec>...]
          reset bisect state and start bisection.
  git bisect bad [<rev>]
          mark <rev> a known-bad revision.
@@@ -22,9 -20,7 +22,9 @@@ git bisect replay <logfile
  git bisect log
          show bisect log.
  git bisect run <cmd>...
 -        use <cmd>... to automatically bisect.'
 +        use <cmd>... to automatically bisect.
 +
 +Please use "git help bisect" to get the full man page.'
  
  OPTIONS_SPEC=
  . git-sh-setup
@@@ -69,14 -65,19 +69,19 @@@ bisect_start() 
        head=$(GIT_DIR="$GIT_DIR" git symbolic-ref -q HEAD) ||
        head=$(GIT_DIR="$GIT_DIR" git rev-parse --verify HEAD) ||
        die "Bad HEAD - I need a HEAD"
+       #
+       # Check that we either already have BISECT_START, or that the
+       # branches bisect, new-bisect don't exist, to not override them.
+       #
+       test -s "$GIT_DIR/BISECT_START" ||
+               if git show-ref --verify -q refs/heads/bisect ||
+                   git show-ref --verify -q refs/heads/new-bisect; then
+                       die 'The branches "bisect" and "new-bisect" must not exist.'
+               fi
        start_head=''
        case "$head" in
        refs/heads/bisect)
-               if [ -s "$GIT_DIR/BISECT_START" ]; then
-                   branch=`cat "$GIT_DIR/BISECT_START"`
-               else
-                   branch=master
-               fi
+               branch=`cat "$GIT_DIR/BISECT_START"`
                git checkout $branch || exit
                ;;
        refs/heads/*|$_x40)
@@@ -219,18 -220,33 +224,33 @@@ bisect_auto_next() 
        bisect_next_check && bisect_next || :
  }
  
+ eval_rev_list() {
+       _eval="$1"
+       eval $_eval
+       res=$?
+       if [ $res -ne 0 ]; then
+               echo >&2 "'git rev-list --bisect-vars' failed:"
+               echo >&2 "maybe you mistake good and bad revs?"
+               exit $res
+       fi
+       return $res
+ }
  filter_skipped() {
        _eval="$1"
        _skip="$2"
  
        if [ -z "$_skip" ]; then
-               eval $_eval
+               eval_rev_list "$_eval"
                return
        fi
  
        # Let's parse the output of:
        # "git rev-list --bisect-vars --bisect-all ..."
-       eval $_eval | while read hash line
+       eval_rev_list "$_eval" | while read hash line
        do
                case "$VARS,$FOUND,$TRIED,$hash" in
                        # We display some vars.
@@@ -328,8 -344,8 +348,8 @@@ bisect_next() 
        exit_if_skipped_commits "$bisect_rev"
  
        echo "Bisecting: $bisect_nr revisions left to test after this"
-       git branch -f new-bisect "$bisect_rev"
-       git checkout -q new-bisect || exit
+       git branch -D new-bisect 2> /dev/null
+       git checkout -q -b new-bisect "$bisect_rev" || exit
        git branch -M new-bisect bisect
        git show-branch "$bisect_rev"
  }
@@@ -471,8 -487,6 +491,8 @@@ case "$#" i
      cmd="$1"
      shift
      case "$cmd" in
 +    help)
 +        git bisect -h ;;
      start)
          bisect_start "$@" ;;
      bad|good|skip)