Skip to content

Commit 4cbaa6b

Browse files
committed
Merge branch 'ks/branch-list-detached-rebase-i'
"git branch --list" during an interrupted "rebase -i" now lets users distinguish the case where a detached HEAD is being rebased and a normal branch is being rebased. * ks/branch-list-detached-rebase-i: t3200: verify "branch --list" sanity when rebasing from detached HEAD branch --list: print useful info whilst interactive rebasing a detached HEAD
2 parents e6986ab + 1f537be commit 4cbaa6b

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

ref-filter.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1309,10 +1309,14 @@ char *get_head_description(void)
13091309
memset(&state, 0, sizeof(state));
13101310
wt_status_get_state(&state, 1);
13111311
if (state.rebase_in_progress ||
1312-
state.rebase_interactive_in_progress)
1313-
strbuf_addf(&desc, _("(no branch, rebasing %s)"),
1314-
state.branch);
1315-
else if (state.bisect_in_progress)
1312+
state.rebase_interactive_in_progress) {
1313+
if (state.branch)
1314+
strbuf_addf(&desc, _("(no branch, rebasing %s)"),
1315+
state.branch);
1316+
else
1317+
strbuf_addf(&desc, _("(no branch, rebasing detached HEAD %s)"),
1318+
state.detached_from);
1319+
} else if (state.bisect_in_progress)
13161320
strbuf_addf(&desc, _("(no branch, bisect started on %s)"),
13171321
state.branch);
13181322
else if (state.detached_from) {

t/t3200-branch.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
test_description='git branch assorted tests'
77

88
. ./test-lib.sh
9+
. "$TEST_DIRECTORY"/lib-rebase.sh
910

1011
test_expect_success 'prepare a trivial repository' '
1112
echo Hello >A &&
@@ -1246,6 +1247,29 @@ test_expect_success '--merged is incompatible with --no-merged' '
12461247
test_must_fail git branch --merged HEAD --no-merged HEAD
12471248
'
12481249

1250+
test_expect_success '--list during rebase' '
1251+
test_when_finished "reset_rebase" &&
1252+
git checkout master &&
1253+
FAKE_LINES="1 edit 2" &&
1254+
export FAKE_LINES &&
1255+
set_fake_editor &&
1256+
git rebase -i HEAD~2 &&
1257+
git branch --list >actual &&
1258+
test_i18ngrep "rebasing master" actual
1259+
'
1260+
1261+
test_expect_success '--list during rebase from detached HEAD' '
1262+
test_when_finished "reset_rebase && git checkout master" &&
1263+
git checkout master^0 &&
1264+
oid=$(git rev-parse --short HEAD) &&
1265+
FAKE_LINES="1 edit 2" &&
1266+
export FAKE_LINES &&
1267+
set_fake_editor &&
1268+
git rebase -i HEAD~2 &&
1269+
git branch --list >actual &&
1270+
test_i18ngrep "rebasing detached HEAD $oid" actual
1271+
'
1272+
12491273
test_expect_success 'tracking with unexpected .fetch refspec' '
12501274
rm -rf a b c d &&
12511275
git init a &&

0 commit comments

Comments
 (0)