Skip to content

Commit 11da0a5

Browse files
committed
Merge branch 'gc/stash-on-branch-with-multi-level-name'
"git checkout -b branch/with/multi/level/name && git stash" only recorded the last level component of the branch name, which has been corrected. * gc/stash-on-branch-with-multi-level-name: stash: strip "refs/heads/" with skip_prefix
2 parents 061fd57 + ceaf037 commit 11da0a5

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

builtin/stash.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1327,7 +1327,7 @@ static int do_create_stash(const struct pathspec *ps, struct strbuf *stash_msg_b
13271327

13281328
branch_ref = resolve_ref_unsafe("HEAD", 0, NULL, &flags);
13291329
if (flags & REF_ISSYMREF)
1330-
branch_name = strrchr(branch_ref, '/') + 1;
1330+
skip_prefix(branch_ref, "refs/heads/", &branch_name);
13311331
head_short_sha1 = find_unique_abbrev(&head_commit->object.oid,
13321332
DEFAULT_ABBREV);
13331333
strbuf_addf(&msg, "%s: %s ", branch_name, head_short_sha1);

t/t3903-stash.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,6 +1045,17 @@ test_expect_success 'create stores correct message' '
10451045
test_cmp expect actual
10461046
'
10471047

1048+
test_expect_success 'create when branch name has /' '
1049+
test_when_finished "git checkout main" &&
1050+
git checkout -b some/topic &&
1051+
>foo &&
1052+
git add foo &&
1053+
STASH_ID=$(git stash create "create test message") &&
1054+
echo "On some/topic: create test message" >expect &&
1055+
git show --pretty=%s -s ${STASH_ID} >actual &&
1056+
test_cmp expect actual
1057+
'
1058+
10481059
test_expect_success 'create with multiple arguments for the message' '
10491060
>foo &&
10501061
git add foo &&

0 commit comments

Comments
 (0)