Merge branch 'rs/use-fspathhash'
[git/debian.git] / git-bisect.sh
blob6a7afaea8da09fa3fb3670d1a688421fbf152747
1 #!/bin/sh
3 USAGE='[help|start|bad|good|new|old|terms|skip|next|reset|visualize|view|replay|log|run]'
4 LONG_USAGE='git bisect help
5 print this long help message.
6 git bisect start [--term-{new,bad}=<term> --term-{old,good}=<term>]
7 [--no-checkout] [--first-parent] [<bad> [<good>...]] [--] [<pathspec>...]
8 reset bisect state and start bisection.
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.
15 git bisect terms [--term-good | --term-bad]
16 show the terms used for old and new commits (default: bad, good)
17 git bisect skip [(<rev>|<range>)...]
18 mark <rev>... untestable revisions.
19 git bisect next
20 find next bisection to test and check it out.
21 git bisect reset [<commit>]
22 finish bisection search and go back to commit.
23 git bisect (visualize|view)
24 show bisect status in gitk.
25 git bisect replay <logfile>
26 replay bisection log.
27 git bisect log
28 show bisect log.
29 git bisect run <cmd>...
30 use <cmd>... to automatically bisect.
32 Please use "git help bisect" to get the full man page.'
34 OPTIONS_SPEC=
35 . git-sh-setup
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"
39 TERM_BAD=bad
40 TERM_GOOD=good
42 bisect_visualize() {
43 git bisect--helper --bisect-next-check $TERM_GOOD $TERM_BAD fail || exit
45 if test $# = 0
46 then
47 if test -n "${DISPLAY+set}${SESSIONNAME+set}${MSYSTEM+set}${SECURITYSESSIONID+set}" &&
48 type gitk >/dev/null 2>&1
49 then
50 set gitk
51 else
52 set git log
54 else
55 case "$1" in
56 git*|tig) ;;
57 -*) set git log "$@" ;;
58 *) set git "$@" ;;
59 esac
62 eval '"$@"' --bisect -- $(cat "$GIT_DIR/BISECT_NAMES")
65 bisect_run () {
66 git bisect--helper --bisect-next-check $TERM_GOOD $TERM_BAD fail || exit
68 test -n "$*" || die "$(gettext "bisect run failed: no command provided.")"
70 while true
72 command="$@"
73 eval_gettextln "running \$command"
74 "$@"
75 res=$?
77 # Check for really bad run error.
78 if [ $res -lt 0 -o $res -ge 128 ]
79 then
80 eval_gettextln "bisect run failed:
81 exit code \$res from '\$command' is < 0 or >= 128" >&2
82 exit $res
85 # Find current state depending on run success or failure.
86 # A special exit code of 125 means cannot test.
87 if [ $res -eq 125 ]
88 then
89 state='skip'
90 elif [ $res -gt 0 ]
91 then
92 state="$TERM_BAD"
93 else
94 state="$TERM_GOOD"
97 git bisect--helper --bisect-state $state >"$GIT_DIR/BISECT_RUN"
98 res=$?
100 cat "$GIT_DIR/BISECT_RUN"
102 if sane_grep "first $TERM_BAD commit could be any of" "$GIT_DIR/BISECT_RUN" \
103 >/dev/null
104 then
105 gettextln "bisect run cannot continue any more" >&2
106 exit $res
109 if [ $res -ne 0 ]
110 then
111 eval_gettextln "bisect run failed:
112 'bisect-state \$state' exited with error code \$res" >&2
113 exit $res
116 if sane_grep "is the first $TERM_BAD commit" "$GIT_DIR/BISECT_RUN" >/dev/null
117 then
118 gettextln "bisect run success"
119 exit 0;
122 done
125 get_terms () {
126 if test -s "$GIT_DIR/BISECT_TERMS"
127 then
129 read TERM_BAD
130 read TERM_GOOD
131 } <"$GIT_DIR/BISECT_TERMS"
135 case "$#" in
137 usage ;;
139 cmd="$1"
140 get_terms
141 shift
142 case "$cmd" in
143 help)
144 git bisect -h ;;
145 start)
146 git bisect--helper --bisect-start "$@" ;;
147 bad|good|new|old|"$TERM_BAD"|"$TERM_GOOD")
148 git bisect--helper --bisect-state "$cmd" "$@" ;;
149 skip)
150 git bisect--helper --bisect-skip "$@" || exit;;
151 next)
152 # Not sure we want "next" at the UI level anymore.
153 git bisect--helper --bisect-next "$@" || exit ;;
154 visualize|view)
155 bisect_visualize "$@" ;;
156 reset)
157 git bisect--helper --bisect-reset "$@" ;;
158 replay)
159 git bisect--helper --bisect-replay "$@" || exit;;
160 log)
161 git bisect--helper --bisect-log || exit ;;
162 run)
163 bisect_run "$@" ;;
164 terms)
165 git bisect--helper --bisect-terms "$@" || exit;;
167 usage ;;
168 esac
169 esac