Re: [PATCH] branch: let '--edit-description' default to rebased branch during rebase
- From
Marc-André Lureau <marcandre.lureau@gmail.com>
- Date
- Jan 11, 2020, 14:54 UTC
- Message-ID
- <CAJ+F1CKW3NACgPdPbmAzYGVwR4iO3r+LCNq+g5st0gcz4X+fzA@mail.gmail.com>
- In-Reply-To
- <CAPig+cQXkiFOz5HczPEgXuSOH_3KsCwXwVwe0qvQzLDtFgnAXw@mail.gmail.com>
Hi
On Sat, Jan 11, 2020 at 5:28 PM Eric Sunshine <sunshine@sunshineco.com> wrote:
Show 29 quoted lines
>
> On Sat, Jan 11, 2020 at 7:36 AM <marcandre.lureau@redhat.com> wrote:
> > Defaulting to editing the description of the rebased branch without an
> > explicit branchname argument would be useful. Even the git bash prompt
> > shows the name of the rebased branch, and then
> >
> > ~/src/git (mybranch|REBASE-i 1/2)$ git branch --edit-description
> > fatal: Cannot give description to detached HEAD
> >
> > looks quite unhelpful.
> >
> > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> > ---
> > diff --git a/builtin/branch.c b/builtin/branch.c
> > @@ -745,15 +745,27 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
> > if (!argc) {
> > - if (filter.detached)
> > - die(_("Cannot give description to detached HEAD"));
> > - branch_name = head;
> > + if (filter.detached) {
> > + struct wt_status_state state;
> > +
> > + memset(&state, 0, sizeof(state));
> > +
> > + if (wt_status_check_rebase(NULL, &state)) {
> > + branch_name = state.branch;
> > + }
>
> Style: drop unneeded braces.ok
Show 9 quoted lines
>
> > +
> > + if (!branch_name)
> > + die(_("Cannot give description to detached HEAD"));
> > +
> > + free(state.onto);
>
> Also, no need for all the blank lines which eat up valuable vertical
> screen real-estate without making the code clearer.ok
Show 7 quoted lines
> > > + } else > > + branch_name = xstrdup(head); > > It would be easier to see what happens in the common case (when not > rebasing) if you invert the condition to `if (!filter.detached)` and > turn this one-line 'else' branch into the 'if' branch.
indeed
Show 8 quoted lines
> > > @@ -772,6 +784,8 @@ int cmd_branch(int argc, const char **argv, const char *prefix) > > if (edit_branch_description(branch_name)) > > return 1; > > + > > + free(branch_name); > > That `return 1` just above this free() is leaking 'branch_name', isn't it?
right, let's fix that too
Show 24 quoted lines
> > > diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh > > @@ -1260,6 +1260,25 @@ test_expect_success 'use --edit-description' ' > > +test_expect_success 'use --edit-description during rebase' ' > > + write_script editor <<-\EOF && > > + echo "Rebase contents" >"$1" > > + EOF > > + ( > > + set_fake_editor && > > + FAKE_LINES="break 1" git rebase -i HEAD^ && > > + EDITOR=./editor git branch --edit-description && > > + git rebase --continue > > + ) && > > + write_script editor <<-\EOF && > > + git stripspace -s <"$1" >"EDITOR_OUTPUT" > > + EOF > > + EDITOR=./editor git branch --edit-description && > > + echo "Rebase contents" >expect && > > + test_cmp expect EDITOR_OUTPUT > > +' > > +test_done > > Strange place for a test_done() invocation considering that existing > tests follow the new one added by this patch.
doh, sorry thanks for the review!
> > > test_expect_success 'detect typo in branch name when using --edit-description' ' > > write_script editor <<-\EOF && > > echo "New contents" >"$1"
-- Marc-André Lureau