]>
Commit | Line | Data |
---|---|---|
8415d5c7 JH |
1 | #!/bin/sh |
2 | ||
3 | test_description='previous branch syntax @{-n}' | |
4 | ||
06d53148 | 5 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
334afbc7 JS |
6 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
7 | ||
8415d5c7 JH |
8 | . ./test-lib.sh |
9 | ||
10 | test_expect_success 'branch -d @{-1}' ' | |
11 | test_commit A && | |
12 | git checkout -b junk && | |
13 | git checkout - && | |
06d53148 | 14 | test "$(git symbolic-ref HEAD)" = refs/heads/main && |
8415d5c7 JH |
15 | git branch -d @{-1} && |
16 | test_must_fail git rev-parse --verify refs/heads/junk | |
17 | ' | |
18 | ||
19 | test_expect_success 'branch -d @{-12} when there is not enough switches yet' ' | |
20 | git reflog expire --expire=now && | |
21 | git checkout -b junk2 && | |
22 | git checkout - && | |
06d53148 | 23 | test "$(git symbolic-ref HEAD)" = refs/heads/main && |
8415d5c7 | 24 | test_must_fail git branch -d @{-12} && |
06d53148 | 25 | git rev-parse --verify refs/heads/main |
8415d5c7 JH |
26 | ' |
27 | ||
c9717ee9 JH |
28 | test_expect_success 'merge @{-1}' ' |
29 | git checkout A && | |
30 | test_commit B && | |
31 | git checkout A && | |
32 | test_commit C && | |
84cf2466 | 33 | test_commit D && |
06d53148 | 34 | git branch -f main B && |
c9717ee9 JH |
35 | git branch -f other && |
36 | git checkout other && | |
06d53148 | 37 | git checkout main && |
c9717ee9 JH |
38 | git merge @{-1} && |
39 | git cat-file commit HEAD | grep "Merge branch '\''other'\''" | |
40 | ' | |
41 | ||
84cf2466 | 42 | test_expect_success 'merge @{-1}~1' ' |
06d53148 | 43 | git checkout main && |
84cf2466 JH |
44 | git reset --hard B && |
45 | git checkout other && | |
06d53148 | 46 | git checkout main && |
84cf2466 JH |
47 | git merge @{-1}~1 && |
48 | git cat-file commit HEAD >actual && | |
49 | grep "Merge branch '\''other'\''" actual | |
50 | ' | |
51 | ||
52 | test_expect_success 'merge @{-100} before checking out that many branches yet' ' | |
c9717ee9 | 53 | git reflog expire --expire=now && |
06d53148 | 54 | git checkout -f main && |
c9717ee9 JH |
55 | git reset --hard B && |
56 | git branch -f other C && | |
57 | git checkout other && | |
06d53148 | 58 | git checkout main && |
84cf2466 | 59 | test_must_fail git merge @{-100} |
c9717ee9 JH |
60 | ' |
61 | ||
13228c30 JK |
62 | test_expect_success 'log -g @{-1}' ' |
63 | git checkout -b last_branch && | |
64 | git checkout -b new_branch && | |
65 | echo "last_branch@{0}" >expect && | |
66 | git log -g --format=%gd @{-1} >actual && | |
67 | test_cmp expect actual | |
68 | ' | |
69 | ||
8415d5c7 JH |
70 | test_done |
71 |