From: Jeff King <peff@peff.net>
To: Daniel Hahler <git@thequod.de>
Cc: git@vger.kernel.org
Subject: Re: [BUG] git-stash does not handle branch name with slash correctly
Date: Wed, 10 Nov 2021 15:53:40 -0500 [thread overview]
Message-ID: <YYwxVO7A29FcN+hN@coredump.intra.peff.net> (raw)
In-Reply-To: <693b55f9-3c0e-5a31-5a43-d6495d689779@hahler.de>
On Wed, Nov 10, 2021 at 07:55:06PM +0100, Daniel Hahler wrote:
> The default (commit) message when creating a stash strips the beginning of
> branch names if they contain a slash,
> e.g. "WIP on 3.2.x: …" instead of "WIP on stable/3.2.x: …"
>
> From builtin/stash.c (in do_create_stash):
>
> branch_ref = resolve_ref_unsafe("HEAD", 0, NULL, &flags);
> if (flags & REF_ISSYMREF)
> branch_name = strrchr(branch_ref, '/') + 1;
>
>
> Whereas git-legacy-stash has this (in create_stash):
>
> if branch=$(git symbolic-ref -q HEAD)
> then
> branch=${branch#refs/heads/}
> else
> branch='(no branch)'
> fi
> msg=$(printf '%s: %s' "$branch" "$head")
>
> I think it should also strip only "refs/heads/" or use another method that
> keeps the branch name intact.
Yes, the C behavior just seems wrong (and came as part of the C rewrite,
so doesn't seem intentional). Something like:
diff --git a/builtin/stash.c b/builtin/stash.c
index d441481d68..70dcb15cb7 100644
--- a/builtin/stash.c
+++ b/builtin/stash.c
@@ -1334,7 +1334,7 @@ static int do_create_stash(const struct pathspec *ps, struct strbuf *stash_msg_b
branch_ref = resolve_ref_unsafe("HEAD", 0, NULL, &flags);
if (flags & REF_ISSYMREF)
- branch_name = strrchr(branch_ref, '/') + 1;
+ skip_prefix(branch_ref, "refs/heads/", &branch_name);
head_short_sha1 = find_unique_abbrev(&head_commit->object.oid,
DEFAULT_ABBREV);
strbuf_addf(&msg, "%s: %s ", branch_name, head_short_sha1);
seems like the right fix. Do you want to try to work that into a patch
with a test?
-Peff
next prev parent reply other threads:[~2021-11-10 20:53 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-10 18:55 [BUG] git-stash does not handle branch name with slash correctly Daniel Hahler
2021-11-10 20:53 ` Jeff King [this message]
2022-01-24 20:53 ` [PATCH] stash: strip "refs/heads/" with skip_prefix Glen Choo
2022-01-25 7:13 ` Junio C Hamano
2022-02-24 7:13 ` Glen Choo
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=YYwxVO7A29FcN+hN@coredump.intra.peff.net \
--to=peff@peff.net \
--cc=git@thequod.de \
--cc=git@vger.kernel.org \
/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).