Re: [PATCH] stash: fix incorrect branch name in stash message
- From
Junio C Hamano <gitster@pobox.com>
- Date
- May 12, 2025, 17:49 UTC
- Message-ID
- <xmqqtt5psor5.fsf@gitster.g>
- In-Reply-To
- <20250512164001.62065-1-jayatheerthkulkarni2005@gmail.com>
K Jayatheerth <jayatheerthkulkarni2005@gmail.com> writes:
Show 33 quoted lines
> @@ -1377,6 +1377,7 @@ static int do_create_stash(const struct pathspec *ps, struct strbuf *stash_msg_b
> struct strbuf msg = STRBUF_INIT;
> struct strbuf commit_tree_label = STRBUF_INIT;
> struct strbuf untracked_files = STRBUF_INIT;
> + char *branch_name_buf = NULL;
>
> prepare_fallback_ident("git stash", "git@stash");
>
> @@ -1404,11 +1405,20 @@ static int do_create_stash(const struct pathspec *ps, struct strbuf *stash_msg_b
>
> branch_ref = refs_resolve_ref_unsafe(get_main_ref_store(the_repository),
> "HEAD", 0, NULL, &flags);
> - if (flags & REF_ISSYMREF)
> - skip_prefix(branch_ref, "refs/heads/", &branch_name);
> - head_short_sha1 = repo_find_unique_abbrev(the_repository,
> - &head_commit->object.oid,
> - DEFAULT_ABBREV);
> +
> + if (flags & REF_ISSYMREF) {
> + const char *tmp = NULL;
> + if (skip_prefix(branch_ref, "refs/heads/", &tmp))
> + branch_name_buf = xstrdup(tmp);
> + }
> + if (branch_name_buf)
> + branch_name = branch_name_buf;
> + else
> + branch_name = "(no branch)";
> +
> + head_short_sha1 = repo_find_unique_abbrev(the_repository,
> + &head_commit->object.oid,
> + DEFAULT_ABBREV);
> strbuf_addf(&msg, "%s: %s ", branch_name, head_short_sha1);
> pp_commit_easy(CMIT_FMT_ONELINE, head_commit, &msg);Funny indentation, and branch_name_buf needs to be free'ed after use but other than that, nice digging!
Thanks.