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 <kaartic.sivaraam@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Kaartic Sivaraam committed Apr 3, 2018 at 10:01 UTC a236f900d8f60e567fca0106038f4797341d97b2
1 file changed +8 -4
ref-filter.c
+8 -4
@@ -1309,10 +1309,14 @@ char *get_head_description(void)
1309 memset(&state, 0, sizeof(state));
1310 wt_status_get_state(&state, 1);
1311 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)
1320 strbuf_addf(&desc, _("(no branch, bisect started on %s)"),
1321 state.branch);
1322 else if (state.detached_from) {