1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-11-16 06:03:44 +01:00
git/t/t0100-previous.sh
Junio C Hamano 84cf246670 strbuf_branchname(): do not double-expand @{-1}~22
If you were on 'frotz' branch before you checked out your current
branch, "git merge @{-1}~22" means the same as "git merge frotz~22".

The strbuf_branchname() function, when interpret_branch_name() gives
up resolving "@{-1}~22" fully, returns "frotz" and tells the caller
that it only resolved "@{-1}" part of the input, mistakes this as a
total failure, and appends the whole thing to the result, yielding
"frotz@{-1}~22", which does not make any sense.

Inspect the return value from interpret_branch_name() a bit more
carefully.  When it errored out without consuming anything, we will
get -1 and we should return the whole thing.  Otherwise, we should
append the remainder (i.e. "~22" in the earlier example) to the
partially resolved name (i.e. "frotz").

The test suite adds enough number of checkout to make @{-12} in the
last test in t0100 that tried to check "we haven't flipped branches
that many times" error case succeed; raise the number to a hundred.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-05-16 12:53:59 -07:00

60 lines
1.4 KiB
Bash
Executable file

#!/bin/sh
test_description='previous branch syntax @{-n}'
. ./test-lib.sh
test_expect_success 'branch -d @{-1}' '
test_commit A &&
git checkout -b junk &&
git checkout - &&
test "$(git symbolic-ref HEAD)" = refs/heads/master &&
git branch -d @{-1} &&
test_must_fail git rev-parse --verify refs/heads/junk
'
test_expect_success 'branch -d @{-12} when there is not enough switches yet' '
git reflog expire --expire=now &&
git checkout -b junk2 &&
git checkout - &&
test "$(git symbolic-ref HEAD)" = refs/heads/master &&
test_must_fail git branch -d @{-12} &&
git rev-parse --verify refs/heads/master
'
test_expect_success 'merge @{-1}' '
git checkout A &&
test_commit B &&
git checkout A &&
test_commit C &&
test_commit D &&
git branch -f master B &&
git branch -f other &&
git checkout other &&
git checkout master &&
git merge @{-1} &&
git cat-file commit HEAD | grep "Merge branch '\''other'\''"
'
test_expect_success 'merge @{-1}~1' '
git checkout master &&
git reset --hard B &&
git checkout other &&
git checkout master &&
git merge @{-1}~1 &&
git cat-file commit HEAD >actual &&
grep "Merge branch '\''other'\''" actual
'
test_expect_success 'merge @{-100} before checking out that many branches yet' '
git reflog expire --expire=now &&
git checkout -f master &&
git reset --hard B &&
git branch -f other C &&
git checkout other &&
git checkout master &&
test_must_fail git merge @{-100}
'
test_done