Skip to content

Commit 990adcc

Browse files
rjustogitster
authored andcommitted
status: fix branch shown when not only bisecting
In 83c750a (wt-status.*: better advice for git status added, 2012-06-05), git-status received new informative messages to describe the ongoing work in a worktree. These messages were enhanced in 0722c80 (status: show the branch name if possible in in-progress info, 2013-02-03), to show, if possible, the branch where the operation was initiated. Since then, we show incorrect information when several operations are in progress and one of them is bisect: $ git checkout -b foo $ GIT_SEQUENCE_EDITOR='echo break >' git rebase -i HEAD~ $ git checkout -b bar $ git bisect start $ git status ... You are currently editing a commit while rebasing branch 'bar' on '...'. You are currently bisecting, started from branch 'bar'. ... Note that we erroneously say "while rebasing branch 'bar'" when we should be referring to "foo". This must have gone unnoticed for so long because it must be unusual to start a bisection while another operation is in progress. And even less usual to involve different branches. It caught my attention reviewing a leak introduced in 8b87cfd (wt-status: move strbuf into read_and_strip_branch(), 2013-03-16). A simple change to deal with this situation can be to record in struct wt_status_state, the branch where the bisect starts separately from the branch related to other operations. Let's do it and so we'll be able to display correct information and we'll avoid the leak as well. Signed-off-by: Rubén Justo <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent fb7d80e commit 990adcc

File tree

6 files changed

+38
-8
lines changed

6 files changed

+38
-8
lines changed

branch.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -419,9 +419,9 @@ static void prepare_checked_out_branches(void)
419419
wt_status_state_free_buffers(&state);
420420

421421
if (wt_status_check_bisect(wt, &state) &&
422-
state.branch) {
422+
state.bisecting_from) {
423423
struct strbuf ref = STRBUF_INIT;
424-
strbuf_addf(&ref, "refs/heads/%s", state.branch);
424+
strbuf_addf(&ref, "refs/heads/%s", state.bisecting_from);
425425
old = strmap_put(&current_checked_out_branches,
426426
ref.buf,
427427
xstrdup(wt->path));

ref-filter.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1773,7 +1773,7 @@ char *get_head_description(void)
17731773
state.detached_from);
17741774
} else if (state.bisect_in_progress)
17751775
strbuf_addf(&desc, _("(no branch, bisect started on %s)"),
1776-
state.branch);
1776+
state.bisecting_from);
17771777
else if (state.detached_from) {
17781778
if (state.detached_at)
17791779
strbuf_addf(&desc, _("(HEAD detached at %s)"),

t/t7512-status-help.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,34 @@ EOF
692692
'
693693

694694

695+
test_expect_success 'status when bisecting while rebasing' '
696+
git reset --hard main &&
697+
test_when_finished "git rebase --abort" &&
698+
ONTO=$(git rev-parse --short HEAD^) &&
699+
FAKE_LINES="break" git rebase -i HEAD^ &&
700+
test_when_finished "git checkout -" &&
701+
git checkout -b bisect_while_rebasing &&
702+
test_when_finished "git bisect reset" &&
703+
git bisect start &&
704+
cat >expected <<EOF &&
705+
On branch bisect_while_rebasing
706+
Last command done (1 command done):
707+
break
708+
No commands remaining.
709+
You are currently editing a commit while rebasing branch '\''bisect'\'' on '\''$ONTO'\''.
710+
(use "git commit --amend" to amend the current commit)
711+
(use "git rebase --continue" once you are satisfied with your changes)
712+
713+
You are currently bisecting, started from branch '\''bisect_while_rebasing'\''.
714+
(use "git bisect reset" to get back to the original branch)
715+
716+
nothing to commit (use -u to show untracked files)
717+
EOF
718+
git status --untracked-files=no >actual &&
719+
test_cmp expected actual
720+
'
721+
722+
695723
test_expect_success 'status when rebase --apply conflicts with statushints disabled' '
696724
git reset --hard main &&
697725
git checkout -b statushints_disabled &&

worktree.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,9 +396,9 @@ int is_worktree_being_bisected(const struct worktree *wt,
396396

397397
memset(&state, 0, sizeof(state));
398398
found_bisect = wt_status_check_bisect(wt, &state) &&
399-
state.branch &&
399+
state.bisecting_from &&
400400
skip_prefix(target, "refs/heads/", &target) &&
401-
!strcmp(state.branch, target);
401+
!strcmp(state.bisecting_from, target);
402402
wt_status_state_free_buffers(&state);
403403
return found_bisect;
404404
}

wt-status.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -858,6 +858,7 @@ void wt_status_state_free_buffers(struct wt_status_state *state)
858858
FREE_AND_NULL(state->branch);
859859
FREE_AND_NULL(state->onto);
860860
FREE_AND_NULL(state->detached_from);
861+
FREE_AND_NULL(state->bisecting_from);
861862
}
862863

863864
static void wt_longstatus_print_unmerged(struct wt_status *s)
@@ -1565,10 +1566,10 @@ static void show_revert_in_progress(struct wt_status *s,
15651566
static void show_bisect_in_progress(struct wt_status *s,
15661567
const char *color)
15671568
{
1568-
if (s->state.branch)
1569+
if (s->state.bisecting_from)
15691570
status_printf_ln(s, color,
15701571
_("You are currently bisecting, started from branch '%s'."),
1571-
s->state.branch);
1572+
s->state.bisecting_from);
15721573
else
15731574
status_printf_ln(s, color,
15741575
_("You are currently bisecting."));
@@ -1729,7 +1730,7 @@ int wt_status_check_bisect(const struct worktree *wt,
17291730

17301731
if (!stat(worktree_git_path(wt, "BISECT_LOG"), &st)) {
17311732
state->bisect_in_progress = 1;
1732-
state->branch = get_branch(wt, "BISECT_START");
1733+
state->bisecting_from = get_branch(wt, "BISECT_START");
17331734
return 1;
17341735
}
17351736
return 0;

wt-status.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ struct wt_status_state {
9494
char *branch;
9595
char *onto;
9696
char *detached_from;
97+
char *bisecting_from;
9798
struct object_id detached_oid;
9899
struct object_id revert_head_oid;
99100
struct object_id cherry_pick_head_oid;

0 commit comments

Comments
 (0)