Skip to content

Commit daaa03e

Browse files
peffgitster
authored andcommitted
bisect: always clean on reset
Usually "bisect reset" cleans up any refs/bisect/ refs, along with meta-files like .git/BISECT_LOG. But it only does so after deciding that a bisection is active, which it does by reading BISECT_START. This is usually fine, but it's possible to get into a confusing state if the BISECT_START file is gone, but other cruft is left (this might be due to a bug, or a system crash, etc). And since "bisect reset" refuses to do anything in this state, the user has no easy way to clean up the leftover cruft. While another "bisect start" would clear the state, in the interim it can be annoying, as other tools (like our bash prompt code) think we are bisecting, and for-each-ref output may be polluted with refs/bisect/ entries. Further adding to the confusion is that running "bisect reset $some_ref" skips the BISECT_START check. So it never realizes that there's no bisection active and does the cleanup anyway! So let's just make sure we always do the cleanup, whether we looked at BISECT_START or not. If the user doesn't give us a commit to reset to, we'll still say "We are not bisecting" and skip the call to "git checkout". Reported-by: Janik Haag <[email protected]> Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0d1bd1d commit daaa03e

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

builtin/bisect.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -227,11 +227,10 @@ static int bisect_reset(const char *commit)
227227
struct strbuf branch = STRBUF_INIT;
228228

229229
if (!commit) {
230-
if (strbuf_read_file(&branch, git_path_bisect_start(), 0) < 1) {
230+
if (!strbuf_read_file(&branch, git_path_bisect_start(), 0))
231231
printf(_("We are not bisecting.\n"));
232-
return 0;
233-
}
234-
strbuf_rtrim(&branch);
232+
else
233+
strbuf_rtrim(&branch);
235234
} else {
236235
struct object_id oid;
237236

@@ -240,7 +239,7 @@ static int bisect_reset(const char *commit)
240239
strbuf_addstr(&branch, commit);
241240
}
242241

243-
if (!ref_exists("BISECT_HEAD")) {
242+
if (branch.len && !ref_exists("BISECT_HEAD")) {
244243
struct child_process cmd = CHILD_PROCESS_INIT;
245244

246245
cmd.git_cmd = 1;

t/t6030-bisect-porcelain.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,12 @@ test_expect_success 'bisect reset when not bisecting' '
147147
cmp branch.expect branch.output
148148
'
149149

150+
test_expect_success 'bisect reset cleans up even when not bisecting' '
151+
echo garbage >.git/BISECT_LOG &&
152+
git bisect reset &&
153+
test_path_is_missing .git/BISECT_LOG
154+
'
155+
150156
test_expect_success 'bisect reset removes packed refs' '
151157
git bisect reset &&
152158
git bisect start &&

0 commit comments

Comments
 (0)