Linus Torvalds | 8cc6a08 | 2005-07-30 10:08:20 -0700 | [diff] [blame] | 1 | #!/bin/sh |
Fredrik Kuivinen | d025524 | 2005-12-11 10:55:49 +0100 | [diff] [blame] | 2 | |
Christian Couder | 243a60f | 2008-04-11 05:55:21 +0200 | [diff] [blame] | 3 | USAGE='[help|start|bad|good|skip|next|reset|visualize|replay|log|run]' |
| 4 | LONG_USAGE='git bisect help |
| 5 | print this long help message. |
| 6 | git bisect start [<bad> [<good>...]] [--] [<pathspec>...] |
Christian Couder | 38a47fd | 2007-04-04 07:12:02 +0200 | [diff] [blame] | 7 | reset bisect state and start bisection. |
| 8 | git bisect bad [<rev>] |
| 9 | mark <rev> a known-bad revision. |
| 10 | git bisect good [<rev>...] |
| 11 | mark <rev>... known-good revisions. |
Christian Couder | 6ca8b97 | 2007-10-29 05:31:52 +0100 | [diff] [blame] | 12 | git bisect skip [<rev>...] |
| 13 | mark <rev>... untestable revisions. |
Christian Couder | 38a47fd | 2007-04-04 07:12:02 +0200 | [diff] [blame] | 14 | git bisect next |
| 15 | find next bisection to test and check it out. |
| 16 | git bisect reset [<branch>] |
| 17 | finish bisection search and go back to branch. |
| 18 | git bisect visualize |
| 19 | show bisect status in gitk. |
| 20 | git bisect replay <logfile> |
| 21 | replay bisection log. |
| 22 | git bisect log |
| 23 | show bisect log. |
| 24 | git bisect run <cmd>... |
Christian Couder | 243a60f | 2008-04-11 05:55:21 +0200 | [diff] [blame] | 25 | use <cmd>... to automatically bisect. |
| 26 | |
| 27 | Please use "git help bisect" to get the full man page.' |
Fredrik Kuivinen | d025524 | 2005-12-11 10:55:49 +0100 | [diff] [blame] | 28 | |
Junio C Hamano | 8f321a3 | 2007-11-06 01:50:02 -0800 | [diff] [blame] | 29 | OPTIONS_SPEC= |
Junio C Hamano | ae2b0f1 | 2005-11-24 00:12:11 -0800 | [diff] [blame] | 30 | . git-sh-setup |
Junio C Hamano | 4c55068 | 2007-02-05 14:03:27 -0800 | [diff] [blame] | 31 | require_work_tree |
Linus Torvalds | 8cc6a08 | 2005-07-30 10:08:20 -0700 | [diff] [blame] | 32 | |
Johannes Schindelin | ce32660 | 2008-02-10 13:59:50 +0000 | [diff] [blame] | 33 | _x40='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]' |
| 34 | _x40="$_x40$_x40$_x40$_x40$_x40$_x40$_x40$_x40" |
| 35 | |
Junio C Hamano | e9a45d7 | 2005-11-27 17:42:05 -0800 | [diff] [blame] | 36 | sq() { |
Michal Rokos | d9bffc0 | 2006-07-08 17:32:04 +0200 | [diff] [blame] | 37 | @@PERL@@ -e ' |
Junio C Hamano | e9a45d7 | 2005-11-27 17:42:05 -0800 | [diff] [blame] | 38 | for (@ARGV) { |
| 39 | s/'\''/'\'\\\\\'\''/g; |
| 40 | print " '\''$_'\''"; |
| 41 | } |
| 42 | print "\n"; |
| 43 | ' "$@" |
| 44 | } |
| 45 | |
Linus Torvalds | 8cc6a08 | 2005-07-30 10:08:20 -0700 | [diff] [blame] | 46 | bisect_autostart() { |
Christian Couder | 6459c7c | 2007-11-18 16:34:03 +0100 | [diff] [blame] | 47 | test -f "$GIT_DIR/BISECT_NAMES" || { |
Linus Torvalds | 8cc6a08 | 2005-07-30 10:08:20 -0700 | [diff] [blame] | 48 | echo >&2 'You need to start by "git bisect start"' |
| 49 | if test -t 0 |
| 50 | then |
| 51 | echo >&2 -n 'Do you want me to do it for you [Y/n]? ' |
| 52 | read yesno |
| 53 | case "$yesno" in |
| 54 | [Nn]*) |
| 55 | exit ;; |
| 56 | esac |
| 57 | bisect_start |
| 58 | else |
| 59 | exit 1 |
| 60 | fi |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | bisect_start() { |
Linus Torvalds | 8cc6a08 | 2005-07-30 10:08:20 -0700 | [diff] [blame] | 65 | # |
| 66 | # Verify HEAD. If we were bisecting before this, reset to the |
| 67 | # top-of-line master first! |
| 68 | # |
Christian Couder | 48949a1 | 2008-04-16 04:09:49 +0200 | [diff] [blame] | 69 | head=$(GIT_DIR="$GIT_DIR" git symbolic-ref -q HEAD) || |
Johannes Schindelin | ce32660 | 2008-02-10 13:59:50 +0000 | [diff] [blame] | 70 | head=$(GIT_DIR="$GIT_DIR" git rev-parse --verify HEAD) || |
| 71 | die "Bad HEAD - I need a HEAD" |
Gerrit Pape | ee831f7 | 2008-05-05 07:43:00 +0000 | [diff] [blame] | 72 | # |
| 73 | # Check that we either already have BISECT_START, or that the |
| 74 | # branches bisect, new-bisect don't exist, to not override them. |
| 75 | # |
| 76 | test -s "$GIT_DIR/BISECT_START" || |
| 77 | if git show-ref --verify -q refs/heads/bisect || |
| 78 | git show-ref --verify -q refs/heads/new-bisect; then |
| 79 | die 'The branches "bisect" and "new-bisect" must not exist.' |
| 80 | fi |
Christian Couder | d3e54c8 | 2008-04-14 05:41:45 +0200 | [diff] [blame] | 81 | start_head='' |
Linus Torvalds | 8cc6a08 | 2005-07-30 10:08:20 -0700 | [diff] [blame] | 82 | case "$head" in |
Junio C Hamano | 673e583 | 2007-03-23 13:15:21 -0700 | [diff] [blame] | 83 | refs/heads/bisect) |
Gerrit Pape | ee831f7 | 2008-05-05 07:43:00 +0000 | [diff] [blame] | 84 | branch=`cat "$GIT_DIR/BISECT_START"` |
Petr Baudis | 810255f | 2006-02-12 17:06:14 +0100 | [diff] [blame] | 85 | git checkout $branch || exit |
Linus Torvalds | 8cc6a08 | 2005-07-30 10:08:20 -0700 | [diff] [blame] | 86 | ;; |
Johannes Schindelin | ce32660 | 2008-02-10 13:59:50 +0000 | [diff] [blame] | 87 | refs/heads/*|$_x40) |
Carl Worth | b577bb9 | 2008-02-23 17:14:17 -0800 | [diff] [blame] | 88 | # This error message should only be triggered by cogito usage, |
| 89 | # and cogito users should understand it relates to cg-seek. |
Petr Baudis | 810255f | 2006-02-12 17:06:14 +0100 | [diff] [blame] | 90 | [ -s "$GIT_DIR/head-name" ] && die "won't bisect on seeked tree" |
Christian Couder | d3e54c8 | 2008-04-14 05:41:45 +0200 | [diff] [blame] | 91 | start_head="${head#refs/heads/}" |
Linus Torvalds | 8cc6a08 | 2005-07-30 10:08:20 -0700 | [diff] [blame] | 92 | ;; |
| 93 | *) |
Junio C Hamano | 8098a17 | 2005-09-30 14:26:57 -0700 | [diff] [blame] | 94 | die "Bad HEAD - strange symbolic ref" |
Linus Torvalds | 8cc6a08 | 2005-07-30 10:08:20 -0700 | [diff] [blame] | 95 | ;; |
| 96 | esac |
| 97 | |
| 98 | # |
| 99 | # Get rid of any old bisect state |
| 100 | # |
Christian Couder | 38a47fd | 2007-04-04 07:12:02 +0200 | [diff] [blame] | 101 | bisect_clean_state |
Christian Couder | 38a47fd | 2007-04-04 07:12:02 +0200 | [diff] [blame] | 102 | |
| 103 | # |
| 104 | # Check for one bad and then some good revisions. |
| 105 | # |
| 106 | has_double_dash=0 |
| 107 | for arg; do |
| 108 | case "$arg" in --) has_double_dash=1; break ;; esac |
| 109 | done |
| 110 | orig_args=$(sq "$@") |
| 111 | bad_seen=0 |
Christian Couder | d3e54c8 | 2008-04-14 05:41:45 +0200 | [diff] [blame] | 112 | eval='' |
Christian Couder | 38a47fd | 2007-04-04 07:12:02 +0200 | [diff] [blame] | 113 | while [ $# -gt 0 ]; do |
| 114 | arg="$1" |
| 115 | case "$arg" in |
| 116 | --) |
Christian Couder | 8fe26f4 | 2007-10-22 07:48:23 +0200 | [diff] [blame] | 117 | shift |
Christian Couder | 38a47fd | 2007-04-04 07:12:02 +0200 | [diff] [blame] | 118 | break |
| 119 | ;; |
| 120 | *) |
Christian Couder | 8fe26f4 | 2007-10-22 07:48:23 +0200 | [diff] [blame] | 121 | rev=$(git rev-parse --verify "$arg^{commit}" 2>/dev/null) || { |
Christian Couder | 38a47fd | 2007-04-04 07:12:02 +0200 | [diff] [blame] | 122 | test $has_double_dash -eq 1 && |
| 123 | die "'$arg' does not appear to be a valid revision" |
| 124 | break |
| 125 | } |
Christian Couder | 737c74e | 2007-10-24 07:01:13 +0200 | [diff] [blame] | 126 | case $bad_seen in |
| 127 | 0) state='bad' ; bad_seen=1 ;; |
| 128 | *) state='good' ;; |
| 129 | esac |
Christian Couder | d3e54c8 | 2008-04-14 05:41:45 +0200 | [diff] [blame] | 130 | eval="$eval bisect_write '$state' '$rev' 'nolog'; " |
Christian Couder | 8fe26f4 | 2007-10-22 07:48:23 +0200 | [diff] [blame] | 131 | shift |
Christian Couder | 38a47fd | 2007-04-04 07:12:02 +0200 | [diff] [blame] | 132 | ;; |
| 133 | esac |
Christian Couder | 8fe26f4 | 2007-10-22 07:48:23 +0200 | [diff] [blame] | 134 | done |
Christian Couder | 38a47fd | 2007-04-04 07:12:02 +0200 | [diff] [blame] | 135 | |
| 136 | sq "$@" >"$GIT_DIR/BISECT_NAMES" |
Christian Couder | d3e54c8 | 2008-04-14 05:41:45 +0200 | [diff] [blame] | 137 | test -n "$start_head" && echo "$start_head" >"$GIT_DIR/BISECT_START" |
| 138 | eval "$eval" |
Christian Couder | b8652b4 | 2007-04-17 06:40:50 +0200 | [diff] [blame] | 139 | echo "git-bisect start$orig_args" >>"$GIT_DIR/BISECT_LOG" |
Christian Couder | 38a47fd | 2007-04-04 07:12:02 +0200 | [diff] [blame] | 140 | bisect_auto_next |
Linus Torvalds | 8cc6a08 | 2005-07-30 10:08:20 -0700 | [diff] [blame] | 141 | } |
| 142 | |
Christian Couder | 55624f9 | 2007-10-24 07:01:05 +0200 | [diff] [blame] | 143 | bisect_write() { |
| 144 | state="$1" |
| 145 | rev="$2" |
Christian Couder | 737c74e | 2007-10-24 07:01:13 +0200 | [diff] [blame] | 146 | nolog="$3" |
Christian Couder | 55624f9 | 2007-10-24 07:01:05 +0200 | [diff] [blame] | 147 | case "$state" in |
| 148 | bad) tag="$state" ;; |
| 149 | good|skip) tag="$state"-"$rev" ;; |
| 150 | *) die "Bad bisect_write argument: $state" ;; |
| 151 | esac |
Junio C Hamano | 3d7cd64 | 2007-11-15 00:42:04 -0800 | [diff] [blame] | 152 | git update-ref "refs/bisect/$tag" "$rev" |
Johannes Schindelin | f454cdc | 2008-02-12 19:50:57 +0000 | [diff] [blame] | 153 | echo "# $state: $(git show-branch $rev)" >>"$GIT_DIR/BISECT_LOG" |
Christian Couder | 737c74e | 2007-10-24 07:01:13 +0200 | [diff] [blame] | 154 | test -z "$nolog" && echo "git-bisect $state $rev" >>"$GIT_DIR/BISECT_LOG" |
Christian Couder | 55624f9 | 2007-10-24 07:01:05 +0200 | [diff] [blame] | 155 | } |
| 156 | |
Christian Couder | 155fc79 | 2007-10-24 07:01:21 +0200 | [diff] [blame] | 157 | bisect_state() { |
Linus Torvalds | 8cc6a08 | 2005-07-30 10:08:20 -0700 | [diff] [blame] | 158 | bisect_autostart |
Christian Couder | 155fc79 | 2007-10-24 07:01:21 +0200 | [diff] [blame] | 159 | state=$1 |
| 160 | case "$#,$state" in |
| 161 | 0,*) |
| 162 | die "Please call 'bisect_state' with at least one argument." ;; |
| 163 | 1,bad|1,good|1,skip) |
| 164 | rev=$(git rev-parse --verify HEAD) || |
| 165 | die "Bad rev input: HEAD" |
| 166 | bisect_write "$state" "$rev" ;; |
Christian Couder | e338907 | 2008-04-12 07:53:59 +0200 | [diff] [blame] | 167 | 2,bad|*,good|*,skip) |
Christian Couder | 155fc79 | 2007-10-24 07:01:21 +0200 | [diff] [blame] | 168 | shift |
Christian Couder | d3e54c8 | 2008-04-14 05:41:45 +0200 | [diff] [blame] | 169 | eval='' |
Christian Couder | e338907 | 2008-04-12 07:53:59 +0200 | [diff] [blame] | 170 | for rev in "$@" |
Christian Couder | 155fc79 | 2007-10-24 07:01:21 +0200 | [diff] [blame] | 171 | do |
Christian Couder | a179a30 | 2008-04-12 02:17:36 -0700 | [diff] [blame] | 172 | sha=$(git rev-parse --verify "$rev^{commit}") || |
Christian Couder | e338907 | 2008-04-12 07:53:59 +0200 | [diff] [blame] | 173 | die "Bad rev input: $rev" |
Christian Couder | d3e54c8 | 2008-04-14 05:41:45 +0200 | [diff] [blame] | 174 | eval="$eval bisect_write '$state' '$sha'; " |
| 175 | done |
| 176 | eval "$eval" ;; |
Christian Couder | e338907 | 2008-04-12 07:53:59 +0200 | [diff] [blame] | 177 | *,bad) |
| 178 | die "'git bisect bad' can take only one argument." ;; |
Junio C Hamano | cc9f24d | 2005-08-30 12:45:41 -0700 | [diff] [blame] | 179 | *) |
| 180 | usage ;; |
Linus Torvalds | 8cc6a08 | 2005-07-30 10:08:20 -0700 | [diff] [blame] | 181 | esac |
Christian Couder | 97e1c51 | 2007-10-22 07:48:36 +0200 | [diff] [blame] | 182 | bisect_auto_next |
| 183 | } |
| 184 | |
Linus Torvalds | 8cc6a08 | 2005-07-30 10:08:20 -0700 | [diff] [blame] | 185 | bisect_next_check() { |
Junio C Hamano | 0a5280a | 2007-04-05 23:27:44 -0700 | [diff] [blame] | 186 | missing_good= missing_bad= |
| 187 | git show-ref -q --verify refs/bisect/bad || missing_bad=t |
| 188 | test -n "$(git for-each-ref "refs/bisect/good-*")" || missing_good=t |
Junio C Hamano | 6fecf19 | 2007-04-05 22:51:14 -0700 | [diff] [blame] | 189 | |
Junio C Hamano | 0a5280a | 2007-04-05 23:27:44 -0700 | [diff] [blame] | 190 | case "$missing_good,$missing_bad,$1" in |
| 191 | ,,*) |
| 192 | : have both good and bad - ok |
| 193 | ;; |
| 194 | *,) |
| 195 | # do not have both but not asked to fail - just report. |
| 196 | false |
| 197 | ;; |
| 198 | t,,good) |
| 199 | # have bad but not good. we could bisect although |
| 200 | # this is less optimum. |
| 201 | echo >&2 'Warning: bisecting only with a bad commit.' |
| 202 | if test -t 0 |
| 203 | then |
| 204 | printf >&2 'Are you sure [Y/n]? ' |
| 205 | case "$(read yesno)" in [Nn]*) exit 1 ;; esac |
| 206 | fi |
| 207 | : bisect without good... |
| 208 | ;; |
Linus Torvalds | 8cc6a08 | 2005-07-30 10:08:20 -0700 | [diff] [blame] | 209 | *) |
Junio C Hamano | 0a5280a | 2007-04-05 23:27:44 -0700 | [diff] [blame] | 210 | THEN='' |
Christian Couder | 6459c7c | 2007-11-18 16:34:03 +0100 | [diff] [blame] | 211 | test -f "$GIT_DIR/BISECT_NAMES" || { |
Junio C Hamano | 0a5280a | 2007-04-05 23:27:44 -0700 | [diff] [blame] | 212 | echo >&2 'You need to start by "git bisect start".' |
| 213 | THEN='then ' |
| 214 | } |
| 215 | echo >&2 'You '$THEN'need to give me at least one good' \ |
| 216 | 'and one bad revisions.' |
| 217 | echo >&2 '(You can use "git bisect bad" and' \ |
| 218 | '"git bisect good" for that.)' |
| 219 | exit 1 ;; |
Linus Torvalds | 8cc6a08 | 2005-07-30 10:08:20 -0700 | [diff] [blame] | 220 | esac |
| 221 | } |
| 222 | |
| 223 | bisect_auto_next() { |
Junio C Hamano | 434d036 | 2005-09-17 13:51:03 -0700 | [diff] [blame] | 224 | bisect_next_check && bisect_next || : |
Linus Torvalds | 8cc6a08 | 2005-07-30 10:08:20 -0700 | [diff] [blame] | 225 | } |
| 226 | |
Christian Couder | 42ba5ee | 2008-05-07 23:54:28 +0200 | [diff] [blame] | 227 | eval_rev_list() { |
| 228 | _eval="$1" |
| 229 | |
| 230 | eval $_eval |
| 231 | res=$? |
| 232 | |
| 233 | if [ $res -ne 0 ]; then |
| 234 | echo >&2 "'git rev-list --bisect-vars' failed:" |
| 235 | echo >&2 "maybe you mistake good and bad revs?" |
| 236 | exit $res |
| 237 | fi |
| 238 | |
| 239 | return $res |
| 240 | } |
| 241 | |
Christian Couder | 97e1c51 | 2007-10-22 07:48:36 +0200 | [diff] [blame] | 242 | filter_skipped() { |
| 243 | _eval="$1" |
| 244 | _skip="$2" |
| 245 | |
| 246 | if [ -z "$_skip" ]; then |
Christian Couder | 42ba5ee | 2008-05-07 23:54:28 +0200 | [diff] [blame] | 247 | eval_rev_list "$_eval" |
Christian Couder | 97e1c51 | 2007-10-22 07:48:36 +0200 | [diff] [blame] | 248 | return |
| 249 | fi |
| 250 | |
| 251 | # Let's parse the output of: |
| 252 | # "git rev-list --bisect-vars --bisect-all ..." |
Christian Couder | 42ba5ee | 2008-05-07 23:54:28 +0200 | [diff] [blame] | 253 | eval_rev_list "$_eval" | while read hash line |
Christian Couder | 97e1c51 | 2007-10-22 07:48:36 +0200 | [diff] [blame] | 254 | do |
| 255 | case "$VARS,$FOUND,$TRIED,$hash" in |
| 256 | # We display some vars. |
| 257 | 1,*,*,*) echo "$hash $line" ;; |
| 258 | |
| 259 | # Split line. |
| 260 | ,*,*,---*) ;; |
| 261 | |
| 262 | # We had nothing to search. |
| 263 | ,,,bisect_rev*) |
| 264 | echo "bisect_rev=" |
| 265 | VARS=1 |
| 266 | ;; |
| 267 | |
| 268 | # We did not find a good bisect rev. |
| 269 | # This should happen only if the "bad" |
| 270 | # commit is also a "skip" commit. |
| 271 | ,,*,bisect_rev*) |
| 272 | echo "bisect_rev=$TRIED" |
| 273 | VARS=1 |
| 274 | ;; |
| 275 | |
| 276 | # We are searching. |
| 277 | ,,*,*) |
| 278 | TRIED="${TRIED:+$TRIED|}$hash" |
| 279 | case "$_skip" in |
| 280 | *$hash*) ;; |
| 281 | *) |
| 282 | echo "bisect_rev=$hash" |
| 283 | echo "bisect_tried=\"$TRIED\"" |
| 284 | FOUND=1 |
| 285 | ;; |
| 286 | esac |
| 287 | ;; |
| 288 | |
| 289 | # We have already found a rev to be tested. |
| 290 | ,1,*,bisect_rev*) VARS=1 ;; |
| 291 | ,1,*,*) ;; |
| 292 | |
| 293 | # ??? |
| 294 | *) die "filter_skipped error " \ |
| 295 | "VARS: '$VARS' " \ |
| 296 | "FOUND: '$FOUND' " \ |
| 297 | "TRIED: '$TRIED' " \ |
| 298 | "hash: '$hash' " \ |
| 299 | "line: '$line'" |
| 300 | ;; |
| 301 | esac |
| 302 | done |
| 303 | } |
| 304 | |
| 305 | exit_if_skipped_commits () { |
| 306 | _tried=$1 |
| 307 | if expr "$_tried" : ".*[|].*" > /dev/null ; then |
| 308 | echo "There are only 'skip'ped commit left to test." |
| 309 | echo "The first bad commit could be any of:" |
Junio C Hamano | e23cb8c | 2007-11-15 00:39:57 -0800 | [diff] [blame] | 310 | echo "$_tried" | tr '[|]' '[\012]' |
Christian Couder | 97e1c51 | 2007-10-22 07:48:36 +0200 | [diff] [blame] | 311 | echo "We cannot bisect more!" |
| 312 | exit 2 |
| 313 | fi |
| 314 | } |
| 315 | |
Linus Torvalds | 8cc6a08 | 2005-07-30 10:08:20 -0700 | [diff] [blame] | 316 | bisect_next() { |
Christian Couder | 8fe26f4 | 2007-10-22 07:48:23 +0200 | [diff] [blame] | 317 | case "$#" in 0) ;; *) usage ;; esac |
Linus Torvalds | 8cc6a08 | 2005-07-30 10:08:20 -0700 | [diff] [blame] | 318 | bisect_autostart |
Junio C Hamano | 0a5280a | 2007-04-05 23:27:44 -0700 | [diff] [blame] | 319 | bisect_next_check good |
| 320 | |
Christian Couder | 97e1c51 | 2007-10-22 07:48:36 +0200 | [diff] [blame] | 321 | skip=$(git for-each-ref --format='%(objectname)' \ |
Jeff King | 40a7ce6 | 2008-03-12 17:29:57 -0400 | [diff] [blame] | 322 | "refs/bisect/skip-*" | tr '\012' ' ') || exit |
Christian Couder | 97e1c51 | 2007-10-22 07:48:36 +0200 | [diff] [blame] | 323 | |
| 324 | BISECT_OPT='' |
| 325 | test -n "$skip" && BISECT_OPT='--bisect-all' |
| 326 | |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 327 | bad=$(git rev-parse --verify refs/bisect/bad) && |
Junio C Hamano | 0a5280a | 2007-04-05 23:27:44 -0700 | [diff] [blame] | 328 | good=$(git for-each-ref --format='^%(objectname)' \ |
Jeff King | 40a7ce6 | 2008-03-12 17:29:57 -0400 | [diff] [blame] | 329 | "refs/bisect/good-*" | tr '\012' ' ') && |
Christian Couder | 97e1c51 | 2007-10-22 07:48:36 +0200 | [diff] [blame] | 330 | eval="git rev-list --bisect-vars $BISECT_OPT $good $bad --" && |
Junio C Hamano | 0a5280a | 2007-04-05 23:27:44 -0700 | [diff] [blame] | 331 | eval="$eval $(cat "$GIT_DIR/BISECT_NAMES")" && |
Christian Couder | 97e1c51 | 2007-10-22 07:48:36 +0200 | [diff] [blame] | 332 | eval=$(filter_skipped "$eval" "$skip") && |
Junio C Hamano | 0a5280a | 2007-04-05 23:27:44 -0700 | [diff] [blame] | 333 | eval "$eval" || exit |
| 334 | |
| 335 | if [ -z "$bisect_rev" ]; then |
| 336 | echo "$bad was both good and bad" |
| 337 | exit 1 |
Linus Torvalds | 670f5fe | 2005-08-30 11:04:39 -0700 | [diff] [blame] | 338 | fi |
Junio C Hamano | 0a5280a | 2007-04-05 23:27:44 -0700 | [diff] [blame] | 339 | if [ "$bisect_rev" = "$bad" ]; then |
Christian Couder | 97e1c51 | 2007-10-22 07:48:36 +0200 | [diff] [blame] | 340 | exit_if_skipped_commits "$bisect_tried" |
Junio C Hamano | 0a5280a | 2007-04-05 23:27:44 -0700 | [diff] [blame] | 341 | echo "$bisect_rev is first bad commit" |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 342 | git diff-tree --pretty $bisect_rev |
Junio C Hamano | 0a5280a | 2007-04-05 23:27:44 -0700 | [diff] [blame] | 343 | exit 0 |
Linus Torvalds | 8cc6a08 | 2005-07-30 10:08:20 -0700 | [diff] [blame] | 344 | fi |
Junio C Hamano | 0a5280a | 2007-04-05 23:27:44 -0700 | [diff] [blame] | 345 | |
Christian Couder | 97e1c51 | 2007-10-22 07:48:36 +0200 | [diff] [blame] | 346 | # We should exit here only if the "bad" |
| 347 | # commit is also a "skip" commit (see above). |
| 348 | exit_if_skipped_commits "$bisect_rev" |
| 349 | |
Junio C Hamano | 0a5280a | 2007-04-05 23:27:44 -0700 | [diff] [blame] | 350 | echo "Bisecting: $bisect_nr revisions left to test after this" |
Gerrit Pape | ee831f7 | 2008-05-05 07:43:00 +0000 | [diff] [blame] | 351 | git branch -D new-bisect 2> /dev/null |
| 352 | git checkout -q -b new-bisect "$bisect_rev" || exit |
Junio C Hamano | 0bee49c | 2007-11-15 00:47:53 -0800 | [diff] [blame] | 353 | git branch -M new-bisect bisect |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 354 | git show-branch "$bisect_rev" |
Linus Torvalds | 8cc6a08 | 2005-07-30 10:08:20 -0700 | [diff] [blame] | 355 | } |
| 356 | |
Junio C Hamano | cc9f24d | 2005-08-30 12:45:41 -0700 | [diff] [blame] | 357 | bisect_visualize() { |
| 358 | bisect_next_check fail |
Junio C Hamano | 235997c | 2007-12-07 02:25:34 -0800 | [diff] [blame] | 359 | |
| 360 | if test $# = 0 |
| 361 | then |
Johannes Schindelin | 508e84a | 2008-02-14 12:29:58 +0000 | [diff] [blame] | 362 | case "${DISPLAY+set}${MSYSTEM+set}${SECURITYSESSIONID+set}" in |
Junio C Hamano | 235997c | 2007-12-07 02:25:34 -0800 | [diff] [blame] | 363 | '') set git log ;; |
Johannes Schindelin | 508e84a | 2008-02-14 12:29:58 +0000 | [diff] [blame] | 364 | set*) set gitk ;; |
Junio C Hamano | 235997c | 2007-12-07 02:25:34 -0800 | [diff] [blame] | 365 | esac |
| 366 | else |
| 367 | case "$1" in |
| 368 | git*|tig) ;; |
| 369 | -*) set git log "$@" ;; |
| 370 | *) set git "$@" ;; |
| 371 | esac |
| 372 | fi |
| 373 | |
Christian Couder | e3f062b | 2007-11-17 14:35:25 +0100 | [diff] [blame] | 374 | not=$(git for-each-ref --format='%(refname)' "refs/bisect/good-*") |
Junio C Hamano | 235997c | 2007-12-07 02:25:34 -0800 | [diff] [blame] | 375 | eval '"$@"' refs/bisect/bad --not $not -- $(cat "$GIT_DIR/BISECT_NAMES") |
Junio C Hamano | cc9f24d | 2005-08-30 12:45:41 -0700 | [diff] [blame] | 376 | } |
| 377 | |
Linus Torvalds | 8cc6a08 | 2005-07-30 10:08:20 -0700 | [diff] [blame] | 378 | bisect_reset() { |
Christian Couder | fce0499 | 2007-11-20 06:39:53 +0100 | [diff] [blame] | 379 | test -f "$GIT_DIR/BISECT_NAMES" || { |
| 380 | echo "We are not bisecting." |
| 381 | return |
| 382 | } |
Linus Torvalds | 8cc6a08 | 2005-07-30 10:08:20 -0700 | [diff] [blame] | 383 | case "$#" in |
Carl Worth | b577bb9 | 2008-02-23 17:14:17 -0800 | [diff] [blame] | 384 | 0) if [ -s "$GIT_DIR/BISECT_START" ]; then |
| 385 | branch=`cat "$GIT_DIR/BISECT_START"` |
Petr Baudis | 810255f | 2006-02-12 17:06:14 +0100 | [diff] [blame] | 386 | else |
| 387 | branch=master |
| 388 | fi ;; |
Christian Couder | 737c74e | 2007-10-24 07:01:13 +0200 | [diff] [blame] | 389 | 1) git show-ref --verify --quiet -- "refs/heads/$1" || |
| 390 | die "$1 does not seem to be a valid branch" |
Linus Torvalds | 8cc6a08 | 2005-07-30 10:08:20 -0700 | [diff] [blame] | 391 | branch="$1" ;; |
Christian Couder | 8fe26f4 | 2007-10-22 07:48:23 +0200 | [diff] [blame] | 392 | *) |
Linus Torvalds | 8cc6a08 | 2005-07-30 10:08:20 -0700 | [diff] [blame] | 393 | usage ;; |
| 394 | esac |
Petr Baudis | 9b709e4 | 2006-10-16 02:59:25 +0200 | [diff] [blame] | 395 | if git checkout "$branch"; then |
Carl Worth | b577bb9 | 2008-02-23 17:14:17 -0800 | [diff] [blame] | 396 | # Cleanup head-name if it got left by an old version of git-bisect |
Christian Couder | 38a47fd | 2007-04-04 07:12:02 +0200 | [diff] [blame] | 397 | rm -f "$GIT_DIR/head-name" |
Carl Worth | b577bb9 | 2008-02-23 17:14:17 -0800 | [diff] [blame] | 398 | rm -f "$GIT_DIR/BISECT_START" |
Christian Couder | 38a47fd | 2007-04-04 07:12:02 +0200 | [diff] [blame] | 399 | bisect_clean_state |
Petr Baudis | 9b709e4 | 2006-10-16 02:59:25 +0200 | [diff] [blame] | 400 | fi |
Junio C Hamano | e204de2 | 2005-09-10 15:18:31 -0700 | [diff] [blame] | 401 | } |
| 402 | |
Christian Couder | 38a47fd | 2007-04-04 07:12:02 +0200 | [diff] [blame] | 403 | bisect_clean_state() { |
Christian Couder | 947a604 | 2007-11-15 08:18:07 +0100 | [diff] [blame] | 404 | # There may be some refs packed during bisection. |
| 405 | git for-each-ref --format='%(refname) %(objectname)' refs/bisect/\* refs/heads/bisect | |
| 406 | while read ref hash |
| 407 | do |
| 408 | git update-ref -d $ref $hash |
| 409 | done |
Christian Couder | 38a47fd | 2007-04-04 07:12:02 +0200 | [diff] [blame] | 410 | rm -f "$GIT_DIR/BISECT_LOG" |
| 411 | rm -f "$GIT_DIR/BISECT_NAMES" |
| 412 | rm -f "$GIT_DIR/BISECT_RUN" |
| 413 | } |
| 414 | |
Junio C Hamano | e204de2 | 2005-09-10 15:18:31 -0700 | [diff] [blame] | 415 | bisect_replay () { |
Christian Couder | 737c74e | 2007-10-24 07:01:13 +0200 | [diff] [blame] | 416 | test -r "$1" || die "cannot read $1 for replaying" |
Junio C Hamano | e204de2 | 2005-09-10 15:18:31 -0700 | [diff] [blame] | 417 | bisect_reset |
| 418 | while read bisect command rev |
| 419 | do |
| 420 | test "$bisect" = "git-bisect" || continue |
| 421 | case "$command" in |
| 422 | start) |
Junio C Hamano | e9a45d7 | 2005-11-27 17:42:05 -0800 | [diff] [blame] | 423 | cmd="bisect_start $rev" |
Christian Couder | 737c74e | 2007-10-24 07:01:13 +0200 | [diff] [blame] | 424 | eval "$cmd" ;; |
| 425 | good|bad|skip) |
| 426 | bisect_write "$command" "$rev" ;; |
Junio C Hamano | e204de2 | 2005-09-10 15:18:31 -0700 | [diff] [blame] | 427 | *) |
Christian Couder | 737c74e | 2007-10-24 07:01:13 +0200 | [diff] [blame] | 428 | die "?? what are you talking about?" ;; |
Junio C Hamano | e204de2 | 2005-09-10 15:18:31 -0700 | [diff] [blame] | 429 | esac |
| 430 | done <"$1" |
| 431 | bisect_auto_next |
Linus Torvalds | 8cc6a08 | 2005-07-30 10:08:20 -0700 | [diff] [blame] | 432 | } |
| 433 | |
Christian Couder | a17c410 | 2007-03-23 08:49:59 +0100 | [diff] [blame] | 434 | bisect_run () { |
Christian Couder | 8302012 | 2007-03-27 06:49:57 +0200 | [diff] [blame] | 435 | bisect_next_check fail |
| 436 | |
Christian Couder | a17c410 | 2007-03-23 08:49:59 +0100 | [diff] [blame] | 437 | while true |
| 438 | do |
| 439 | echo "running $@" |
| 440 | "$@" |
| 441 | res=$? |
| 442 | |
| 443 | # Check for really bad run error. |
| 444 | if [ $res -lt 0 -o $res -ge 128 ]; then |
| 445 | echo >&2 "bisect run failed:" |
| 446 | echo >&2 "exit code $res from '$@' is < 0 or >= 128" |
| 447 | exit $res |
| 448 | fi |
| 449 | |
Christian Couder | 155fc79 | 2007-10-24 07:01:21 +0200 | [diff] [blame] | 450 | # Find current state depending on run success or failure. |
Christian Couder | 71b0251 | 2007-10-26 05:39:37 +0200 | [diff] [blame] | 451 | # A special exit code of 125 means cannot test. |
| 452 | if [ $res -eq 125 ]; then |
| 453 | state='skip' |
| 454 | elif [ $res -gt 0 ]; then |
Christian Couder | 155fc79 | 2007-10-24 07:01:21 +0200 | [diff] [blame] | 455 | state='bad' |
Christian Couder | a17c410 | 2007-03-23 08:49:59 +0100 | [diff] [blame] | 456 | else |
Christian Couder | 155fc79 | 2007-10-24 07:01:21 +0200 | [diff] [blame] | 457 | state='good' |
Christian Couder | a17c410 | 2007-03-23 08:49:59 +0100 | [diff] [blame] | 458 | fi |
| 459 | |
Christian Couder | 155fc79 | 2007-10-24 07:01:21 +0200 | [diff] [blame] | 460 | # We have to use a subshell because "bisect_state" can exit. |
| 461 | ( bisect_state $state > "$GIT_DIR/BISECT_RUN" ) |
Christian Couder | a17c410 | 2007-03-23 08:49:59 +0100 | [diff] [blame] | 462 | res=$? |
| 463 | |
| 464 | cat "$GIT_DIR/BISECT_RUN" |
| 465 | |
Christian Couder | 71b0251 | 2007-10-26 05:39:37 +0200 | [diff] [blame] | 466 | if grep "first bad commit could be any of" "$GIT_DIR/BISECT_RUN" \ |
| 467 | > /dev/null; then |
| 468 | echo >&2 "bisect run cannot continue any more" |
| 469 | exit $res |
| 470 | fi |
| 471 | |
Christian Couder | a17c410 | 2007-03-23 08:49:59 +0100 | [diff] [blame] | 472 | if [ $res -ne 0 ]; then |
| 473 | echo >&2 "bisect run failed:" |
Christian Couder | 155fc79 | 2007-10-24 07:01:21 +0200 | [diff] [blame] | 474 | echo >&2 "'bisect_state $state' exited with error code $res" |
Christian Couder | a17c410 | 2007-03-23 08:49:59 +0100 | [diff] [blame] | 475 | exit $res |
| 476 | fi |
| 477 | |
| 478 | if grep "is first bad commit" "$GIT_DIR/BISECT_RUN" > /dev/null; then |
| 479 | echo "bisect run success" |
| 480 | exit 0; |
| 481 | fi |
| 482 | |
| 483 | done |
| 484 | } |
| 485 | |
| 486 | |
Linus Torvalds | 8cc6a08 | 2005-07-30 10:08:20 -0700 | [diff] [blame] | 487 | case "$#" in |
| 488 | 0) |
| 489 | usage ;; |
| 490 | *) |
| 491 | cmd="$1" |
| 492 | shift |
| 493 | case "$cmd" in |
Christian Couder | 243a60f | 2008-04-11 05:55:21 +0200 | [diff] [blame] | 494 | help) |
| 495 | git bisect -h ;; |
Linus Torvalds | 8cc6a08 | 2005-07-30 10:08:20 -0700 | [diff] [blame] | 496 | start) |
| 497 | bisect_start "$@" ;; |
Christian Couder | 155fc79 | 2007-10-24 07:01:21 +0200 | [diff] [blame] | 498 | bad|good|skip) |
| 499 | bisect_state "$cmd" "$@" ;; |
Linus Torvalds | 8cc6a08 | 2005-07-30 10:08:20 -0700 | [diff] [blame] | 500 | next) |
| 501 | # Not sure we want "next" at the UI level anymore. |
| 502 | bisect_next "$@" ;; |
Junio C Hamano | 235997c | 2007-12-07 02:25:34 -0800 | [diff] [blame] | 503 | visualize|view) |
Junio C Hamano | cc9f24d | 2005-08-30 12:45:41 -0700 | [diff] [blame] | 504 | bisect_visualize "$@" ;; |
Linus Torvalds | 8cc6a08 | 2005-07-30 10:08:20 -0700 | [diff] [blame] | 505 | reset) |
| 506 | bisect_reset "$@" ;; |
Junio C Hamano | e204de2 | 2005-09-10 15:18:31 -0700 | [diff] [blame] | 507 | replay) |
| 508 | bisect_replay "$@" ;; |
| 509 | log) |
| 510 | cat "$GIT_DIR/BISECT_LOG" ;; |
Christian Couder | a17c410 | 2007-03-23 08:49:59 +0100 | [diff] [blame] | 511 | run) |
| 512 | bisect_run "$@" ;; |
Linus Torvalds | 8cc6a08 | 2005-07-30 10:08:20 -0700 | [diff] [blame] | 513 | *) |
| 514 | usage ;; |
| 515 | esac |
| 516 | esac |