When rebasing interacitvely (rebase -i), "git branch -l" prints a line
indicating the current branch being rebased. This works well when the
interactive rebase was intiated when a local branch is checked out.

This doesn't play well when the rebase was initiated on a remote
branch or an arbitrary commit that is not pointed to by a local
branch. In this case "git branch -l" tries to print the name of a
branch using an unintialized 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 commit from which the rebase started when interactive
rebasing a non-local branch.

Signed-off-by: Kaartic Sivaraam <kaartic.sivar...@gmail.com>
---
 ref-filter.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/ref-filter.c b/ref-filter.c
index f9e25aea7..a4c917c96 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -1310,8 +1310,16 @@ char *get_head_description(void)
        wt_status_get_state(&state, 1);
        if (state.rebase_in_progress ||
            state.rebase_interactive_in_progress)
+       {
+               const char *rebasing = NULL;
+               if (state.branch != NULL)
+                       rebasing = state.branch;
+               else
+                       rebasing = state.detached_from;
+
                strbuf_addf(&desc, _("(no branch, rebasing %s)"),
-                           state.branch);
+                           rebasing);
+       }
        else if (state.bisect_in_progress)
                strbuf_addf(&desc, _("(no branch, bisect started on %s)"),
                            state.branch);
-- 
2.17.0.rc0.231.g781580f06

Reply via email to