]>
Commit | Line | Data |
---|---|---|
8cc6a083 | 1 | #!/bin/sh |
d025524d | 2 | |
dbc349bb | 3 | USAGE='[help|start|bad|good|new|old|terms|skip|next|reset|visualize|view|replay|log|run]' |
243a60fb | 4 | LONG_USAGE='git bisect help |
6021be86 | 5 | print this long help message. |
06e6a745 MM |
6 | git bisect start [--term-{old,good}=<term> --term-{new,bad}=<term>] |
7 | [--no-checkout] [<bad> [<good>...]] [--] [<pathspec>...] | |
6021be86 | 8 | reset bisect state and start bisection. |
21e5cfd8 AD |
9 | git bisect (bad|new) [<rev>] |
10 | mark <rev> a known-bad revision/ | |
11 | a revision after change in a given property. | |
12 | git bisect (good|old) [<rev>...] | |
13 | mark <rev>... known-good revisions/ | |
14 | revisions before change in a given property. | |
21b55e33 MM |
15 | git bisect terms [--term-good | --term-bad] |
16 | show the terms used for old and new commits (default: bad, good) | |
5413812f | 17 | git bisect skip [(<rev>|<range>)...] |
6021be86 | 18 | mark <rev>... untestable revisions. |
38a47fd6 | 19 | git bisect next |
6021be86 | 20 | find next bisection to test and check it out. |
6b87ce23 | 21 | git bisect reset [<commit>] |
6021be86 | 22 | finish bisection search and go back to commit. |
dbc349bb | 23 | git bisect (visualize|view) |
6021be86 | 24 | show bisect status in gitk. |
38a47fd6 | 25 | git bisect replay <logfile> |
6021be86 | 26 | replay bisection log. |
38a47fd6 | 27 | git bisect log |
6021be86 | 28 | show bisect log. |
38a47fd6 | 29 | git bisect run <cmd>... |
6021be86 | 30 | use <cmd>... to automatically bisect. |
243a60fb CC |
31 | |
32 | Please use "git help bisect" to get the full man page.' | |
d025524d | 33 | |
8f321a39 | 34 | OPTIONS_SPEC= |
ae2b0f15 | 35 | . git-sh-setup |
8cc6a083 | 36 | |
ce32660e JS |
37 | _x40='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]' |
38 | _x40="$_x40$_x40$_x40$_x40$_x40$_x40$_x40$_x40" | |
43f9d9f3 AD |
39 | TERM_BAD=bad |
40 | TERM_GOOD=good | |
ce32660e | 41 | |
4796e823 JS |
42 | bisect_head() |
43 | { | |
44 | if test -f "$GIT_DIR/BISECT_HEAD" | |
45 | then | |
46 | echo BISECT_HEAD | |
47 | else | |
48 | echo HEAD | |
49 | fi | |
50 | } | |
51 | ||
8cc6a083 | 52 | bisect_autostart() { |
823ea121 | 53 | test -s "$GIT_DIR/BISECT_START" || { |
3145b1a2 | 54 | gettextln "You need to start by \"git bisect start\"" >&2 |
8cc6a083 LT |
55 | if test -t 0 |
56 | then | |
04de0996 ÆAB |
57 | # TRANSLATORS: Make sure to include [Y] and [n] in your |
58 | # translation. The program will only accept English input | |
59 | # at this point. | |
6021be86 | 60 | gettext "Do you want me to do it for you [Y/n]? " >&2 |
8cc6a083 LT |
61 | read yesno |
62 | case "$yesno" in | |
63 | [Nn]*) | |
64 | exit ;; | |
65 | esac | |
66 | bisect_start | |
67 | else | |
68 | exit 1 | |
69 | fi | |
70 | } | |
71 | } | |
72 | ||
73 | bisect_start() { | |
06f5608c | 74 | git bisect--helper --bisect-start $@ || exit |
38a47fd6 | 75 | |
ba963de8 CC |
76 | # |
77 | # Change state. | |
78 | # In case of mistaken revs or checkout error, or signals received, | |
79 | # "bisect_auto_next" below may exit or misbehave. | |
80 | # We have to trap this to be able to clean up using | |
81 | # "bisect_clean_state". | |
82 | # | |
fb71a329 | 83 | trap 'git bisect--helper --bisect-clean-state' 0 |
ba963de8 CC |
84 | trap 'exit 255' 1 2 3 15 |
85 | ||
ba963de8 CC |
86 | # |
87 | # Check if we can proceed to the next bisect state. | |
88 | # | |
06f5608c | 89 | get_terms |
38a47fd6 | 90 | bisect_auto_next |
ba963de8 CC |
91 | |
92 | trap '-' 0 | |
8cc6a083 LT |
93 | } |
94 | ||
ee2314f5 | 95 | bisect_skip() { |
6021be86 | 96 | all='' |
ee2314f5 CC |
97 | for arg in "$@" |
98 | do | |
6021be86 JS |
99 | case "$arg" in |
100 | *..*) | |
101 | revs=$(git rev-list "$arg") || die "$(eval_gettext "Bad rev input: \$arg")" ;; | |
102 | *) | |
103 | revs=$(git rev-parse --sq-quote "$arg") ;; | |
104 | esac | |
105 | all="$all $revs" | |
106 | done | |
107 | eval bisect_state 'skip' $all | |
ee2314f5 CC |
108 | } |
109 | ||
155fc795 | 110 | bisect_state() { |
8cc6a083 | 111 | bisect_autostart |
155fc795 | 112 | state=$1 |
4fbdbd5b PB |
113 | git bisect--helper --check-and-set-terms $state $TERM_GOOD $TERM_BAD || exit |
114 | get_terms | |
155fc795 CC |
115 | case "$#,$state" in |
116 | 0,*) | |
f813fb41 | 117 | die "Please call 'bisect_state' with at least one argument." ;; |
43f9d9f3 | 118 | 1,"$TERM_BAD"|1,"$TERM_GOOD"|1,skip) |
57984dd9 VA |
119 | bisected_head=$(bisect_head) |
120 | rev=$(git rev-parse --verify "$bisected_head") || | |
121 | die "$(eval_gettext "Bad rev input: \$bisected_head")" | |
0f30233a | 122 | git bisect--helper --bisect-write "$state" "$rev" "$TERM_GOOD" "$TERM_BAD" || exit |
b903674b | 123 | git bisect--helper --check-expected-revs "$rev" ;; |
43f9d9f3 | 124 | 2,"$TERM_BAD"|*,"$TERM_GOOD"|*,skip) |
155fc795 | 125 | shift |
6bc02d56 | 126 | hash_list='' |
e3389075 | 127 | for rev in "$@" |
155fc795 | 128 | do |
a179a303 | 129 | sha=$(git rev-parse --verify "$rev^{commit}") || |
15eaa049 | 130 | die "$(eval_gettext "Bad rev input: \$rev")" |
6bc02d56 | 131 | hash_list="$hash_list $sha" |
d3e54c88 | 132 | done |
6bc02d56 CC |
133 | for rev in $hash_list |
134 | do | |
0f30233a | 135 | git bisect--helper --bisect-write "$state" "$rev" "$TERM_GOOD" "$TERM_BAD" || exit |
6bc02d56 | 136 | done |
b903674b | 137 | git bisect--helper --check-expected-revs $hash_list ;; |
43f9d9f3 AD |
138 | *,"$TERM_BAD") |
139 | die "$(eval_gettext "'git bisect \$TERM_BAD' can take only one argument.")" ;; | |
cc9f24d0 JH |
140 | *) |
141 | usage ;; | |
8cc6a083 | 142 | esac |
97e1c51e CC |
143 | bisect_auto_next |
144 | } | |
145 | ||
8cc6a083 | 146 | bisect_auto_next() { |
129a6cf3 | 147 | git bisect--helper --bisect-next-check $TERM_GOOD $TERM_BAD && bisect_next || : |
8cc6a083 LT |
148 | } |
149 | ||
150 | bisect_next() { | |
8fe26f44 | 151 | case "$#" in 0) ;; *) usage ;; esac |
8cc6a083 | 152 | bisect_autostart |
129a6cf3 | 153 | git bisect--helper --bisect-next-check $TERM_GOOD $TERM_BAD $TERM_GOOD|| exit |
0a5280a9 | 154 | |
0871984d | 155 | # Perform all bisection computation, display and checkout |
4796e823 | 156 | git bisect--helper --next-all $(test -f "$GIT_DIR/BISECT_HEAD" && echo --no-checkout) |
5a1d31c7 | 157 | res=$? |
0a5280a9 | 158 | |
6021be86 | 159 | # Check if we should exit because bisection is finished |
a7f8b8ac TH |
160 | if test $res -eq 10 |
161 | then | |
43f9d9f3 | 162 | bad_rev=$(git show-ref --hash --verify refs/bisect/$TERM_BAD) |
a7f8b8ac | 163 | bad_commit=$(git show-branch $bad_rev) |
43f9d9f3 | 164 | echo "# first $TERM_BAD commit: $bad_commit" >>"$GIT_DIR/BISECT_LOG" |
a7f8b8ac | 165 | exit 0 |
f989cac9 TH |
166 | elif test $res -eq 2 |
167 | then | |
168 | echo "# only skipped commits left to test" >>"$GIT_DIR/BISECT_LOG" | |
43f9d9f3 AD |
169 | good_revs=$(git for-each-ref --format="%(objectname)" "refs/bisect/$TERM_GOOD-*") |
170 | for skipped in $(git rev-list refs/bisect/$TERM_BAD --not $good_revs) | |
f989cac9 TH |
171 | do |
172 | skipped_commit=$(git show-branch $skipped) | |
43f9d9f3 | 173 | echo "# possible first $TERM_BAD commit: $skipped_commit" >>"$GIT_DIR/BISECT_LOG" |
f989cac9 TH |
174 | done |
175 | exit $res | |
a7f8b8ac | 176 | fi |
0a5280a9 | 177 | |
5a1d31c7 CC |
178 | # Check for an error in the bisection process |
179 | test $res -ne 0 && exit $res | |
180 | ||
181 | return 0 | |
8cc6a083 LT |
182 | } |
183 | ||
cc9f24d0 | 184 | bisect_visualize() { |
129a6cf3 | 185 | git bisect--helper --bisect-next-check $TERM_GOOD $TERM_BAD fail || exit |
235997c9 JH |
186 | |
187 | if test $# = 0 | |
188 | then | |
c4e4644e | 189 | if test -n "${DISPLAY+set}${SESSIONNAME+set}${MSYSTEM+set}${SECURITYSESSIONID+set}" && |
43b8ff4b | 190 | type gitk >/dev/null 2>&1 |
eef12a9a | 191 | then |
c4e4644e JK |
192 | set gitk |
193 | else | |
194 | set git log | |
195 | fi | |
235997c9 JH |
196 | else |
197 | case "$1" in | |
198 | git*|tig) ;; | |
199 | -*) set git log "$@" ;; | |
200 | *) set git "$@" ;; | |
201 | esac | |
202 | fi | |
203 | ||
fc13aa3d | 204 | eval '"$@"' --bisect -- $(cat "$GIT_DIR/BISECT_NAMES") |
cc9f24d0 JH |
205 | } |
206 | ||
e204de28 | 207 | bisect_replay () { |
55a9fc80 ÆAB |
208 | file="$1" |
209 | test "$#" -eq 1 || die "$(gettext "No logfile given")" | |
210 | test -r "$file" || die "$(eval_gettext "cannot read \$file for replaying")" | |
5e82c3dd | 211 | git bisect--helper --bisect-reset || exit |
6c98c054 | 212 | while read git bisect command rev |
e204de28 | 213 | do |
c82af12a | 214 | test "$git $bisect" = "git bisect" || test "$git" = "git-bisect" || continue |
eef12a9a JS |
215 | if test "$git" = "git-bisect" |
216 | then | |
6c98c054 MV |
217 | rev="$command" |
218 | command="$bisect" | |
219 | fi | |
cb46d630 | 220 | get_terms |
4fbdbd5b PB |
221 | git bisect--helper --check-and-set-terms "$command" "$TERM_GOOD" "$TERM_BAD" || exit |
222 | get_terms | |
e204de28 JH |
223 | case "$command" in |
224 | start) | |
e9a45d75 | 225 | cmd="bisect_start $rev" |
737c74ee | 226 | eval "$cmd" ;; |
cb46d630 | 227 | "$TERM_GOOD"|"$TERM_BAD"|skip) |
0f30233a | 228 | git bisect--helper --bisect-write "$command" "$rev" "$TERM_GOOD" "$TERM_BAD" || exit;; |
21b55e33 | 229 | terms) |
450ebb73 | 230 | git bisect--helper --bisect-terms $rev || exit;; |
e204de28 | 231 | *) |
9570fc1e | 232 | die "$(gettext "?? what are you talking about?")" ;; |
e204de28 | 233 | esac |
55a9fc80 | 234 | done <"$file" |
e204de28 | 235 | bisect_auto_next |
8cc6a083 LT |
236 | } |
237 | ||
a17c4101 | 238 | bisect_run () { |
129a6cf3 | 239 | git bisect--helper --bisect-next-check $TERM_GOOD $TERM_BAD fail || exit |
6021be86 | 240 | |
fecd2dd3 SB |
241 | test -n "$*" || die "$(gettext "bisect run failed: no command provided.")" |
242 | ||
6021be86 JS |
243 | while true |
244 | do | |
245 | command="$@" | |
3145b1a2 | 246 | eval_gettextln "running \$command" |
6021be86 JS |
247 | "$@" |
248 | res=$? | |
249 | ||
250 | # Check for really bad run error. | |
eef12a9a JS |
251 | if [ $res -lt 0 -o $res -ge 128 ] |
252 | then | |
3145b1a2 JS |
253 | eval_gettextln "bisect run failed: |
254 | exit code \$res from '\$command' is < 0 or >= 128" >&2 | |
6021be86 JS |
255 | exit $res |
256 | fi | |
257 | ||
258 | # Find current state depending on run success or failure. | |
259 | # A special exit code of 125 means cannot test. | |
eef12a9a JS |
260 | if [ $res -eq 125 ] |
261 | then | |
6021be86 | 262 | state='skip' |
eef12a9a JS |
263 | elif [ $res -gt 0 ] |
264 | then | |
43f9d9f3 | 265 | state="$TERM_BAD" |
6021be86 | 266 | else |
43f9d9f3 | 267 | state="$TERM_GOOD" |
6021be86 JS |
268 | fi |
269 | ||
270 | # We have to use a subshell because "bisect_state" can exit. | |
305a233c | 271 | ( bisect_state $state >"$GIT_DIR/BISECT_RUN" ) |
6021be86 JS |
272 | res=$? |
273 | ||
274 | cat "$GIT_DIR/BISECT_RUN" | |
275 | ||
43f9d9f3 | 276 | if sane_grep "first $TERM_BAD commit could be any of" "$GIT_DIR/BISECT_RUN" \ |
305a233c | 277 | >/dev/null |
eef12a9a | 278 | then |
3145b1a2 | 279 | gettextln "bisect run cannot continue any more" >&2 |
6021be86 JS |
280 | exit $res |
281 | fi | |
282 | ||
eef12a9a JS |
283 | if [ $res -ne 0 ] |
284 | then | |
3145b1a2 JS |
285 | eval_gettextln "bisect run failed: |
286 | 'bisect_state \$state' exited with error code \$res" >&2 | |
6021be86 JS |
287 | exit $res |
288 | fi | |
a17c4101 | 289 | |
43f9d9f3 | 290 | if sane_grep "is the first $TERM_BAD commit" "$GIT_DIR/BISECT_RUN" >/dev/null |
eef12a9a | 291 | then |
3145b1a2 | 292 | gettextln "bisect run success" |
6021be86 JS |
293 | exit 0; |
294 | fi | |
a17c4101 | 295 | |
6021be86 | 296 | done |
a17c4101 CC |
297 | } |
298 | ||
412ff738 | 299 | bisect_log () { |
9570fc1e | 300 | test -s "$GIT_DIR/BISECT_LOG" || die "$(gettext "We are not bisecting.")" |
412ff738 SG |
301 | cat "$GIT_DIR/BISECT_LOG" |
302 | } | |
a17c4101 | 303 | |
cb46d630 AD |
304 | get_terms () { |
305 | if test -s "$GIT_DIR/BISECT_TERMS" | |
306 | then | |
307 | { | |
308 | read TERM_BAD | |
309 | read TERM_GOOD | |
310 | } <"$GIT_DIR/BISECT_TERMS" | |
311 | fi | |
312 | } | |
313 | ||
8cc6a083 LT |
314 | case "$#" in |
315 | 0) | |
6021be86 | 316 | usage ;; |
8cc6a083 | 317 | *) |
6021be86 | 318 | cmd="$1" |
cb46d630 | 319 | get_terms |
6021be86 JS |
320 | shift |
321 | case "$cmd" in | |
322 | help) | |
323 | git bisect -h ;; | |
324 | start) | |
325 | bisect_start "$@" ;; | |
21e5cfd8 | 326 | bad|good|new|old|"$TERM_BAD"|"$TERM_GOOD") |
6021be86 JS |
327 | bisect_state "$cmd" "$@" ;; |
328 | skip) | |
329 | bisect_skip "$@" ;; | |
330 | next) | |
331 | # Not sure we want "next" at the UI level anymore. | |
332 | bisect_next "$@" ;; | |
333 | visualize|view) | |
334 | bisect_visualize "$@" ;; | |
335 | reset) | |
5e82c3dd | 336 | git bisect--helper --bisect-reset "$@" ;; |
6021be86 JS |
337 | replay) |
338 | bisect_replay "$@" ;; | |
339 | log) | |
340 | bisect_log ;; | |
341 | run) | |
342 | bisect_run "$@" ;; | |
21b55e33 | 343 | terms) |
450ebb73 | 344 | git bisect--helper --bisect-terms "$@" || exit;; |
6021be86 JS |
345 | *) |
346 | usage ;; | |
347 | esac | |
8cc6a083 | 348 | esac |