]> git.ipfire.org Git - thirdparty/git.git/blob - t/t1505-rev-parse-last.sh
Sync with Git 2.45.1
[thirdparty/git.git] / t / t1505-rev-parse-last.sh
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_PASSES_SANITIZE_LEAK=true
9 . ./test-lib.sh
10
11
12 make_commit () {
13 echo "$1" > "$1" &&
14 git add "$1" &&
15 git commit -m "$1"
16 }
17
18
19 test_expect_success 'setup' '
20
21 make_commit 1 &&
22 git branch side &&
23 make_commit 2 &&
24 make_commit 3 &&
25 git checkout side &&
26 make_commit 4 &&
27 git merge main &&
28 git checkout main
29
30 '
31
32 # 1 -- 2 -- 3 main
33 # \ \
34 # \ \
35 # --- 4 --- 5 side
36 #
37 # and 'side' should be the last branch
38
39 test_expect_success '@{-1} works' '
40 test_cmp_rev side @{-1}
41 '
42
43 test_expect_success '@{-1}~2 works' '
44 test_cmp_rev side~2 @{-1}~2
45 '
46
47 test_expect_success '@{-1}^2 works' '
48 test_cmp_rev side^2 @{-1}^2
49 '
50
51 test_expect_success '@{-1}@{1} works' '
52 test_cmp_rev side@{1} @{-1}@{1}
53 '
54
55 test_expect_success '@{-2} works' '
56 test_cmp_rev main @{-2}
57 '
58
59 test_expect_success '@{-3} fails' '
60 test_must_fail git rev-parse @{-3}
61 '
62
63 test_done
64
65