From a236f900d8f60e567fca0106038f4797341d97b2 Mon Sep 17 00:00:00 2001 From: Kaartic Sivaraam Date: Tue, 3 Apr 2018 10:01:00 +0530 Subject: [PATCH 1/2] branch --list: print useful info whilst interactive rebasing a detached HEAD When rebasing interactively (rebase -i), "git branch --list" prints a line indicating the current branch being rebased. This works well when the interactive rebase is initiated when a local branch is checked out. This doesn't play well when the rebase is initiated on a detached HEAD. When "git branch --list" tries to print information related to the interactive rebase in this case it tries to print the name of a branch using an uninitialized variable and thus tries to print a "null pointer string". As a consequence, it does not provide useful information while also inducing undefined behaviour. So, print the point from which the rebase was started when interactive rebasing a detached HEAD. Signed-off-by: Kaartic Sivaraam Signed-off-by: Junio C Hamano --- ref-filter.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/ref-filter.c b/ref-filter.c index 45fc56216a..d9ef7f0748 100644 --- a/ref-filter.c +++ b/ref-filter.c @@ -1309,10 +1309,14 @@ char *get_head_description(void) memset(&state, 0, sizeof(state)); wt_status_get_state(&state, 1); if (state.rebase_in_progress || - state.rebase_interactive_in_progress) - strbuf_addf(&desc, _("(no branch, rebasing %s)"), - state.branch); - else if (state.bisect_in_progress) + state.rebase_interactive_in_progress) { + if (state.branch) + strbuf_addf(&desc, _("(no branch, rebasing %s)"), + state.branch); + else + strbuf_addf(&desc, _("(no branch, rebasing detached HEAD %s)"), + state.detached_from); + } else if (state.bisect_in_progress) strbuf_addf(&desc, _("(no branch, bisect started on %s)"), state.branch); else if (state.detached_from) { From 1f537be3f21ce1289c5c3ed9ebf58f02938ad9f7 Mon Sep 17 00:00:00 2001 From: Eric Sunshine Date: Tue, 3 Apr 2018 20:17:15 +0530 Subject: [PATCH 2/2] t3200: verify "branch --list" sanity when rebasing from detached HEAD "git branch --list" shows an in-progress rebase as: * (no branch, rebasing ) master ... However, if the rebase is started from a detached HEAD, then there is no , and it would attempt to print a NULL pointer. The previous commit fixed this problem, so add a test to verify that the output is sane in this situation. Signed-off-by: Eric Sunshine Signed-off-by: Kaartic Sivaraam Signed-off-by: Junio C Hamano --- t/t3200-branch.sh | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh index 6c0b7ea4ad..c0ef946811 100755 --- a/t/t3200-branch.sh +++ b/t/t3200-branch.sh @@ -6,6 +6,7 @@ test_description='git branch assorted tests' . ./test-lib.sh +. "$TEST_DIRECTORY"/lib-rebase.sh test_expect_success 'prepare a trivial repository' ' echo Hello >A && @@ -1246,6 +1247,29 @@ test_expect_success '--merged is incompatible with --no-merged' ' test_must_fail git branch --merged HEAD --no-merged HEAD ' +test_expect_success '--list during rebase' ' + test_when_finished "reset_rebase" && + git checkout master && + FAKE_LINES="1 edit 2" && + export FAKE_LINES && + set_fake_editor && + git rebase -i HEAD~2 && + git branch --list >actual && + test_i18ngrep "rebasing master" actual +' + +test_expect_success '--list during rebase from detached HEAD' ' + test_when_finished "reset_rebase && git checkout master" && + git checkout master^0 && + oid=$(git rev-parse --short HEAD) && + FAKE_LINES="1 edit 2" && + export FAKE_LINES && + set_fake_editor && + git rebase -i HEAD~2 && + git branch --list >actual && + test_i18ngrep "rebasing detached HEAD $oid" actual +' + test_expect_success 'tracking with unexpected .fetch refspec' ' rm -rf a b c d && git init a &&