[BUG] git-stash does not handle branch name with slash correctly
- From
Daniel Hahler <git@thequod.de>
- Date
- Nov 10, 2021, 18:55 UTC
- Message-ID
- <693b55f9-3c0e-5a31-5a43-d6495d689779@hahler.de>
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.
(I have noticed this with a script/function that warns me when trying to pop a stash to another branch than where it was stashed from initially, which parses out the (original) branch name from this message.)
[System Info] git version: git version 2.33.1