From: Eric Sunshine <sunshine@sunshineco.com>
To: marcandre.lureau@redhat.com
Cc: "Git List" <git@vger.kernel.org>, "SZEDER Gábor" <szeder.dev@gmail.com>
Subject: Re: [PATCH] branch: let '--edit-description' default to rebased branch during rebase
Date: Sat, 11 Jan 2020 08:26:53 -0500 [thread overview]
Message-ID: <CAPig+cQXkiFOz5HczPEgXuSOH_3KsCwXwVwe0qvQzLDtFgnAXw@mail.gmail.com> (raw)
In-Reply-To: <20200111123533.1613844-1-marcandre.lureau@redhat.com>
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.
> +
> + 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.
> + } 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.
> @@ -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?
> 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.
> test_expect_success 'detect typo in branch name when using --edit-description' '
> write_script editor <<-\EOF &&
> echo "New contents" >"$1"
next prev parent reply other threads:[~2020-01-11 13:27 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-11 12:35 [PATCH] branch: let '--edit-description' default to rebased branch during rebase marcandre.lureau
2020-01-11 13:26 ` Eric Sunshine [this message]
2020-01-11 14:54 ` Marc-André Lureau
2020-01-12 1:27 ` Eric Sunshine
2020-01-12 6:44 ` Marc-André Lureau
2020-01-12 12:14 ` SZEDER Gábor
2020-01-13 1:59 ` Eric Sunshine
2020-01-24 22:41 ` SZEDER Gábor
2020-01-30 21:37 ` Marc-André Lureau
2020-01-31 15:52 ` SZEDER Gábor
2020-01-31 15:59 ` Marc-André Lureau
2020-01-31 16:16 ` SZEDER Gábor
2020-02-06 22:26 ` Marc-André Lureau
2020-02-07 10:02 ` SZEDER Gábor
2020-02-07 14:16 ` Marc-André Lureau
2020-02-07 18:57 ` Junio C Hamano
2020-02-07 19:09 ` Marc-André Lureau
2020-02-07 19:12 ` Junio C Hamano
2020-02-07 19:29 ` Eric Sunshine
2020-02-07 20:14 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAPig+cQXkiFOz5HczPEgXuSOH_3KsCwXwVwe0qvQzLDtFgnAXw@mail.gmail.com \
--to=sunshine@sunshineco.com \
--cc=git@vger.kernel.org \
--cc=marcandre.lureau@redhat.com \
--cc=szeder.dev@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).