git-bisect: allow bisecting with only one bad commit.
This allows you to say: git bisect start git bisect bad $bad git bisect next to start bisection without knowing a good commit. This would have you try a commit that is half-way since the beginning of the history, which is rather wasteful if you already know a good commit, but if you don't (or your history is short enough that you do not care), there is no reason not to allow this. Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Apr 5, 2007 at 23:27 UTC
0a5280a9f444c33b0e4ebf2f073df5899c112cf8
2 files changed
+59
-45
git-bisect.sh
+53
-34
@@ -168,26 +168,40 @@ bisect_write_good() {
168
}
169
170
bisect_next_check() {
171
- next_ok=no
172
- git show-ref -q --verify refs/bisect/bad &&
173
- test -n "$(git for-each-ref "refs/bisect/good-*")" &&
174
- next_ok=yes
175
-
176
- case "$next_ok,$1" in
177
- no,) false ;;
178
- no,fail)
179
- THEN=''
180
- test -d "$GIT_DIR/refs/bisect" || {
181
- echo >&2 'You need to start by "git bisect start".'
182
- THEN='then '
183
- }
184
- echo >&2 'You '$THEN'need to give me at least one good' \
185
- 'and one bad revisions.'
186
- echo >&2 '(You can use "git bisect bad" and' \
187
- '"git bisect good" for that.)'
188
- exit 1 ;;
171
+ missing_good= missing_bad=
172
+ git show-ref -q --verify refs/bisect/bad || missing_bad=t
173
+ test -n "$(git for-each-ref "refs/bisect/good-*")" || missing_good=t
174
+
175
+ case "$missing_good,$missing_bad,$1" in
176
+ ,,*)
177
+ : have both good and bad - ok
178
+ ;;
179
+ *,)
180
+ # do not have both but not asked to fail - just report.
181
+ false
182
+ ;;
183
+ t,,good)
184
+ # have bad but not good. we could bisect although
185
+ # this is less optimum.
186
+ echo >&2 'Warning: bisecting only with a bad commit.'
187
+ if test -t 0
188
+ then
189
+ printf >&2 'Are you sure [Y/n]? '
190
+ case "$(read yesno)" in [Nn]*) exit 1 ;; esac
191
+ fi
192
+ : bisect without good...
193
+ ;;
194
*)
190
- true ;;
195
+ THEN=''
196
+ test -d "$GIT_DIR/refs/bisect" || {
197
+ echo >&2 'You need to start by "git bisect start".'
198
+ THEN='then '
199
+ }
200
+ echo >&2 'You '$THEN'need to give me at least one good' \
201
+ 'and one bad revisions.'
202
+ echo >&2 '(You can use "git bisect bad" and' \
203
+ '"git bisect good" for that.)'
204
+ exit 1 ;;
205
esac
206
}
207
@@ -198,27 +212,32 @@ bisect_auto_next() {
212
bisect_next() {
213
case "$#" in 0) ;; *) usage ;; esac
214
bisect_autostart
201
- bisect_next_check fail
215
+ bisect_next_check good
216
+
217
bad=$(git-rev-parse --verify refs/bisect/bad) &&
203
- good=$(git-rev-parse --sq --revs-only --not \
204
- $(cd "$GIT_DIR" && ls refs/bisect/good-*)) &&
205
- rev=$(eval "git-rev-list --bisect $good $bad -- $(cat "$GIT_DIR/BISECT_NAMES")") || exit
206
- if [ -z "$rev" ]; then
207
- echo "$bad was both good and bad"
208
- exit 1
218
+ good=$(git for-each-ref --format='^%(objectname)' \
219
+ "refs/bisect/good-*" | tr '[\012]' ' ') &&
220
+ eval="git-rev-list --bisect-vars $good $bad --" &&
221
+ eval="$eval $(cat "$GIT_DIR/BISECT_NAMES")" &&
222
+ eval=$(eval "$eval") &&
223
+ eval "$eval" || exit
224
+
225
+ if [ -z "$bisect_rev" ]; then
226
+ echo "$bad was both good and bad"
227
+ exit 1
228
fi
210
- if [ "$rev" = "$bad" ]; then
211
- echo "$rev is first bad commit"
212
- git-diff-tree --pretty $rev
213
- exit 0
229
+ if [ "$bisect_rev" = "$bad" ]; then
230
+ echo "$bisect_rev is first bad commit"
231
+ git-diff-tree --pretty $bisect_rev
232
+ exit 0
233
fi
215
- nr=$(eval "git-rev-list $rev $good -- $(cat $GIT_DIR/BISECT_NAMES)" | wc -l) || exit
216
- echo "Bisecting: $nr revisions left to test after this"
217
- echo "$rev" > "$GIT_DIR/refs/heads/new-bisect"
234
+
235
+ echo "Bisecting: $bisect_nr revisions left to test after this"
236
+ echo "$bisect_rev" >"$GIT_DIR/refs/heads/new-bisect"
237
git checkout -q new-bisect || exit
238
mv "$GIT_DIR/refs/heads/new-bisect" "$GIT_DIR/refs/heads/bisect" &&
239
GIT_DIR="$GIT_DIR" git-symbolic-ref HEAD refs/heads/bisect
221
- git-show-branch "$rev"
240
+ git-show-branch "$bisect_rev"
241
}
242
243
bisect_visualize() {
t/t6030-bisect-run.sh
+6
-11
@@ -4,6 +4,8 @@
4
#
5
test_description='Tests git-bisect functionality'
6
7
+exec </dev/null
8
+
9
. ./test-lib.sh
10
11
add_line_into_file()
@@ -37,21 +39,14 @@ test_expect_success \
39
HASH3=$(git rev-list HEAD | head -2 | tail -1) &&
40
HASH4=$(git rev-list HEAD | head -1)'
41
40
-test_expect_success 'bisect does not start with only one bad' '
42
+test_expect_success 'bisect starts with only one bad' '
43
git bisect reset &&
44
git bisect start &&
43
- git bisect bad $HASH4 || return 1
44
-
45
- if git bisect next
46
- then
47
- echo Oops, should have failed.
48
- false
49
- else
50
- :
51
- fi
45
+ git bisect bad $HASH4 &&
46
+ git bisect next
47
'
48
54
-test_expect_success 'bisect does not start with only one good' '
49
+test_expect_success 'bisect starts with only one good' '
50
git bisect reset &&
51
git bisect start &&
52
git bisect good $HASH1 || return 1