| 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='test @{-N} syntax' |
| 4 | |
| 5 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
| 6 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
| 7 | |
| 8 | . ./test-lib.sh |
| 9 | |
| 10 | |
| 11 | make_commit () { |
| 12 | echo "$1" > "$1" && |
| 13 | git add "$1" && |
| 14 | git commit -m "$1" |
| 15 | } |
| 16 | |
| 17 | |
| 18 | test_expect_success 'setup' ' |
| 19 | |
| 20 | make_commit 1 && |
| 21 | git branch side && |
| 22 | make_commit 2 && |
| 23 | make_commit 3 && |
| 24 | git checkout side && |
| 25 | make_commit 4 && |
| 26 | git merge main && |
| 27 | git checkout main |
| 28 | |
| 29 | ' |
| 30 | |
| 31 | # 1 -- 2 -- 3 main |
| 32 | # \ \ |
| 33 | # \ \ |
| 34 | # --- 4 --- 5 side |
| 35 | # |
| 36 | # and 'side' should be the last branch |
| 37 | |
| 38 | test_expect_success '@{-1} works' ' |
| 39 | test_cmp_rev side @{-1} |
| 40 | ' |
| 41 | |
| 42 | test_expect_success '@{-1}~2 works' ' |
| 43 | test_cmp_rev side~2 @{-1}~2 |
| 44 | ' |
| 45 | |
| 46 | test_expect_success '@{-1}^2 works' ' |
| 47 | test_cmp_rev side^2 @{-1}^2 |
| 48 | ' |
| 49 | |
| 50 | test_expect_success '@{-1}@{1} works' ' |
| 51 | test_cmp_rev side@{1} @{-1}@{1} |
| 52 | ' |
| 53 | |
| 54 | test_expect_success '@{-2} works' ' |
| 55 | test_cmp_rev main @{-2} |
| 56 | ' |
| 57 | |
| 58 | test_expect_success '@{-3} fails' ' |
| 59 | test_must_fail git rev-parse @{-3} |
| 60 | ' |
| 61 | |
| 62 | test_done |
| 63 | |
| 64 |