From: "Rubén Justo" <rjusto@gmail.com>
To: Junio C Hamano <gitster@pobox.com>, git@vger.kernel.org
Subject: Re: [PATCH] branch: do not fail a no-op --edit-desc
Date: Thu, 29 Sep 2022 01:04:21 +0200 [thread overview]
Message-ID: <1faa5c44-1a59-7a60-d29b-c4d4e8d0bf92@gmail.com> (raw)
In-Reply-To: <xmqqczbftina.fsf@gitster.g>
On 28/9/22 21:15, Junio C Hamano wrote:
> In a repository on a branch without branch description, try running
On a branch without description, ..
> The simpler solution of course introduces TOCTOU, but you are
Nice to introduce a term that can generate curiosity.
> fooling yourself in your own repository. Not overwriting the branch
> description on the same branch you added in another window, while
> you had this other editor open, may even be a feature ;-)
Not overwriting if there was no description in the first place, otherwise
will clear.. ¿?
>
> Signed-off-by: Junio C Hamano <gitster@pobox.com>
> ---
> builtin/branch.c | 6 ++++--
> t/t3200-branch.sh | 3 +++
> 2 files changed, 7 insertions(+), 2 deletions(-)
>
> diff --git c/builtin/branch.c w/builtin/branch.c
> index 5d00d0b8d3..dcd847158a 100644
> --- c/builtin/branch.c
> +++ w/builtin/branch.c
> @@ -604,10 +604,11 @@ static GIT_PATH_FUNC(edit_description, "EDIT_DESCRIPTION")
>
> static int edit_branch_description(const char *branch_name)
> {
> + int exists;
> struct strbuf buf = STRBUF_INIT;
> struct strbuf name = STRBUF_INIT;
>
> - read_branch_desc(&buf, branch_name);
> + exists = !read_branch_desc(&buf, branch_name);
> if (!buf.len || buf.buf[buf.len-1] != '\n')
> strbuf_addch(&buf, '\n');
> strbuf_commented_addf(&buf,
> @@ -624,7 +625,8 @@ static int edit_branch_description(const char *branch_name)
> strbuf_stripspace(&buf, 1);
>
> strbuf_addf(&name, "branch.%s.description", branch_name);
> - git_config_set(name.buf, buf.len ? buf.buf : NULL);
> + if (buf.len || exists)
> + git_config_set(name.buf, buf.len ? buf.buf : NULL);
> strbuf_release(&name);
> strbuf_release(&buf);
>
> diff --git c/t/t3200-branch.sh w/t/t3200-branch.sh
> index 9723c2827c..5f72fd7453 100755
> --- c/t/t3200-branch.sh
> +++ w/t/t3200-branch.sh
> @@ -1381,6 +1381,9 @@ test_expect_success 'branch --delete --force removes dangling branch' '
> '
>
> test_expect_success 'use --edit-description' '
> + EDITOR=: git branch --edit-description &&
> + test_must_fail git config branch.main.description &&
> +
> write_script editor <<-\EOF &&
> echo "New contents" >"$1"
> EOF
>
The change looks fine and removes a confusing error. Good.
Thanks.
next prev parent reply other threads:[~2022-09-28 23:04 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-28 19:15 [PATCH] branch: do not fail a no-op --edit-desc Junio C Hamano
2022-09-28 23:04 ` Rubén Justo [this message]
2022-09-28 23:40 ` Junio C Hamano
2022-09-29 21:49 ` Rubén Justo
2022-09-29 22:26 ` Junio C Hamano
2022-09-30 22:59 ` Rubén Justo
2022-10-01 9:15 ` Rubén Justo
2022-09-30 1:27 ` [PATCH v2] " Junio C Hamano
2022-09-30 10:21 ` Ævar Arnfjörð Bjarmason
2022-09-30 17:01 ` Junio C Hamano
2022-09-30 17:58 ` Ævar Arnfjörð Bjarmason
2022-09-30 18:13 ` Junio C Hamano
2022-09-30 18:06 ` [PATCH v3] " 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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1faa5c44-1a59-7a60-d29b-c4d4e8d0bf92@gmail.com \
--to=rjusto@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.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.
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 NNTP newsgroup(s).