]>
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. |
ef4d9f8a | 6 | git bisect start [--term-{new,bad}=<term> --term-{old,good}=<term>] |
6028f5f6 | 7 | [--no-checkout] [--first-parent] [<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 | |
ee2314f5 | 42 | bisect_skip() { |
6021be86 | 43 | all='' |
ee2314f5 CC |
44 | for arg in "$@" |
45 | do | |
6021be86 JS |
46 | case "$arg" in |
47 | *..*) | |
48 | revs=$(git rev-list "$arg") || die "$(eval_gettext "Bad rev input: \$arg")" ;; | |
49 | *) | |
50 | revs=$(git rev-parse --sq-quote "$arg") ;; | |
51 | esac | |
52 | all="$all $revs" | |
53 | done | |
27257bc4 | 54 | eval git bisect--helper --bisect-state 'skip' $all |
8cc6a083 LT |
55 | } |
56 | ||
cc9f24d0 | 57 | bisect_visualize() { |
129a6cf3 | 58 | git bisect--helper --bisect-next-check $TERM_GOOD $TERM_BAD fail || exit |
235997c9 JH |
59 | |
60 | if test $# = 0 | |
61 | then | |
c4e4644e | 62 | if test -n "${DISPLAY+set}${SESSIONNAME+set}${MSYSTEM+set}${SECURITYSESSIONID+set}" && |
43b8ff4b | 63 | type gitk >/dev/null 2>&1 |
eef12a9a | 64 | then |
c4e4644e JK |
65 | set gitk |
66 | else | |
67 | set git log | |
68 | fi | |
235997c9 JH |
69 | else |
70 | case "$1" in | |
71 | git*|tig) ;; | |
72 | -*) set git log "$@" ;; | |
73 | *) set git "$@" ;; | |
74 | esac | |
75 | fi | |
76 | ||
fc13aa3d | 77 | eval '"$@"' --bisect -- $(cat "$GIT_DIR/BISECT_NAMES") |
cc9f24d0 JH |
78 | } |
79 | ||
e204de28 | 80 | bisect_replay () { |
55a9fc80 ÆAB |
81 | file="$1" |
82 | test "$#" -eq 1 || die "$(gettext "No logfile given")" | |
83 | test -r "$file" || die "$(eval_gettext "cannot read \$file for replaying")" | |
5e82c3dd | 84 | git bisect--helper --bisect-reset || exit |
6c722cbe | 85 | oIFS="$IFS" IFS="$IFS$(printf '\015')" |
173cb08d | 86 | while read git bisect command rev tail |
e204de28 | 87 | do |
c82af12a | 88 | test "$git $bisect" = "git bisect" || test "$git" = "git-bisect" || continue |
eef12a9a JS |
89 | if test "$git" = "git-bisect" |
90 | then | |
6c98c054 MV |
91 | rev="$command" |
92 | command="$bisect" | |
93 | fi | |
cb46d630 | 94 | get_terms |
4fbdbd5b PB |
95 | git bisect--helper --check-and-set-terms "$command" "$TERM_GOOD" "$TERM_BAD" || exit |
96 | get_terms | |
e204de28 JH |
97 | case "$command" in |
98 | start) | |
88ad372f | 99 | eval "git bisect--helper --bisect-start $rev $tail" ;; |
cb46d630 | 100 | "$TERM_GOOD"|"$TERM_BAD"|skip) |
0f30233a | 101 | git bisect--helper --bisect-write "$command" "$rev" "$TERM_GOOD" "$TERM_BAD" || exit;; |
21b55e33 | 102 | terms) |
450ebb73 | 103 | git bisect--helper --bisect-terms $rev || exit;; |
e204de28 | 104 | *) |
9570fc1e | 105 | die "$(gettext "?? what are you talking about?")" ;; |
e204de28 | 106 | esac |
55a9fc80 | 107 | done <"$file" |
6c722cbe | 108 | IFS="$oIFS" |
517ecb31 | 109 | git bisect--helper --bisect-auto-next || exit |
8cc6a083 LT |
110 | } |
111 | ||
a17c4101 | 112 | bisect_run () { |
129a6cf3 | 113 | git bisect--helper --bisect-next-check $TERM_GOOD $TERM_BAD fail || exit |
6021be86 | 114 | |
fecd2dd3 SB |
115 | test -n "$*" || die "$(gettext "bisect run failed: no command provided.")" |
116 | ||
6021be86 JS |
117 | while true |
118 | do | |
119 | command="$@" | |
3145b1a2 | 120 | eval_gettextln "running \$command" |
6021be86 JS |
121 | "$@" |
122 | res=$? | |
123 | ||
124 | # Check for really bad run error. | |
eef12a9a JS |
125 | if [ $res -lt 0 -o $res -ge 128 ] |
126 | then | |
3145b1a2 JS |
127 | eval_gettextln "bisect run failed: |
128 | exit code \$res from '\$command' is < 0 or >= 128" >&2 | |
6021be86 JS |
129 | exit $res |
130 | fi | |
131 | ||
132 | # Find current state depending on run success or failure. | |
133 | # A special exit code of 125 means cannot test. | |
eef12a9a JS |
134 | if [ $res -eq 125 ] |
135 | then | |
6021be86 | 136 | state='skip' |
eef12a9a JS |
137 | elif [ $res -gt 0 ] |
138 | then | |
43f9d9f3 | 139 | state="$TERM_BAD" |
6021be86 | 140 | else |
43f9d9f3 | 141 | state="$TERM_GOOD" |
6021be86 JS |
142 | fi |
143 | ||
27257bc4 | 144 | git bisect--helper --bisect-state $state >"$GIT_DIR/BISECT_RUN" |
6021be86 JS |
145 | res=$? |
146 | ||
147 | cat "$GIT_DIR/BISECT_RUN" | |
148 | ||
43f9d9f3 | 149 | if sane_grep "first $TERM_BAD commit could be any of" "$GIT_DIR/BISECT_RUN" \ |
305a233c | 150 | >/dev/null |
eef12a9a | 151 | then |
3145b1a2 | 152 | gettextln "bisect run cannot continue any more" >&2 |
6021be86 JS |
153 | exit $res |
154 | fi | |
155 | ||
eef12a9a JS |
156 | if [ $res -ne 0 ] |
157 | then | |
3145b1a2 | 158 | eval_gettextln "bisect run failed: |
27257bc4 | 159 | 'bisect-state \$state' exited with error code \$res" >&2 |
6021be86 JS |
160 | exit $res |
161 | fi | |
a17c4101 | 162 | |
43f9d9f3 | 163 | if sane_grep "is the first $TERM_BAD commit" "$GIT_DIR/BISECT_RUN" >/dev/null |
eef12a9a | 164 | then |
3145b1a2 | 165 | gettextln "bisect run success" |
6021be86 JS |
166 | exit 0; |
167 | fi | |
a17c4101 | 168 | |
6021be86 | 169 | done |
a17c4101 CC |
170 | } |
171 | ||
412ff738 | 172 | bisect_log () { |
9570fc1e | 173 | test -s "$GIT_DIR/BISECT_LOG" || die "$(gettext "We are not bisecting.")" |
412ff738 SG |
174 | cat "$GIT_DIR/BISECT_LOG" |
175 | } | |
a17c4101 | 176 | |
cb46d630 AD |
177 | get_terms () { |
178 | if test -s "$GIT_DIR/BISECT_TERMS" | |
179 | then | |
180 | { | |
181 | read TERM_BAD | |
182 | read TERM_GOOD | |
183 | } <"$GIT_DIR/BISECT_TERMS" | |
184 | fi | |
185 | } | |
186 | ||
8cc6a083 LT |
187 | case "$#" in |
188 | 0) | |
6021be86 | 189 | usage ;; |
8cc6a083 | 190 | *) |
6021be86 | 191 | cmd="$1" |
cb46d630 | 192 | get_terms |
6021be86 JS |
193 | shift |
194 | case "$cmd" in | |
195 | help) | |
196 | git bisect -h ;; | |
197 | start) | |
88ad372f | 198 | git bisect--helper --bisect-start "$@" ;; |
21e5cfd8 | 199 | bad|good|new|old|"$TERM_BAD"|"$TERM_GOOD") |
27257bc4 | 200 | git bisect--helper --bisect-state "$cmd" "$@" ;; |
6021be86 JS |
201 | skip) |
202 | bisect_skip "$@" ;; | |
203 | next) | |
204 | # Not sure we want "next" at the UI level anymore. | |
517ecb31 | 205 | git bisect--helper --bisect-next "$@" || exit ;; |
6021be86 JS |
206 | visualize|view) |
207 | bisect_visualize "$@" ;; | |
208 | reset) | |
5e82c3dd | 209 | git bisect--helper --bisect-reset "$@" ;; |
6021be86 JS |
210 | replay) |
211 | bisect_replay "$@" ;; | |
212 | log) | |
213 | bisect_log ;; | |
214 | run) | |
215 | bisect_run "$@" ;; | |
21b55e33 | 216 | terms) |
450ebb73 | 217 | git bisect--helper --bisect-terms "$@" || exit;; |
6021be86 JS |
218 | *) |
219 | usage ;; | |
220 | esac | |
8cc6a083 | 221 | esac |