Git 2.45
[git/gitster.git] / t / t1508-at-combinations.sh
blobe841309d0eab1022f3442c23795f884ad98a8280
1 #!/bin/sh
3 test_description='test various @{X} syntax combinations together'
4 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
5 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7 TEST_PASSES_SANITIZE_LEAK=true
8 . ./test-lib.sh
10 check() {
11 test_expect_${4:-success} "$1 = $3" "
12 echo '$3' >expect &&
13 if test '$2' = 'commit'
14 then
15 git log -1 --format=%s '$1' >actual
16 elif test '$2' = 'ref'
17 then
18 git rev-parse --symbolic-full-name '$1' >actual
19 else
20 git cat-file -p '$1' >actual
21 fi &&
22 test_cmp expect actual
26 nonsense() {
27 test_expect_${2:-success} "$1 is nonsensical" "
28 test_must_fail git rev-parse --verify '$1'
32 fail() {
33 "$@" failure
36 test_expect_success 'setup' '
37 test_commit main-one &&
38 test_commit main-two &&
39 git checkout -b upstream-branch &&
40 test_commit upstream-one &&
41 test_commit upstream-two &&
42 if test_have_prereq !MINGW
43 then
44 git checkout -b @/at-test
45 fi &&
46 git checkout -b @@/at-test &&
47 git checkout -b @at-test &&
48 git checkout -b old-branch &&
49 test_commit old-one &&
50 test_commit old-two &&
51 git checkout -b new-branch &&
52 test_commit new-one &&
53 test_commit new-two &&
54 git branch -u main old-branch &&
55 git branch -u upstream-branch new-branch
58 check HEAD ref refs/heads/new-branch
59 check "@{1}" commit new-one
60 check "HEAD@{1}" commit new-one
61 check "@{now}" commit new-two
62 check "HEAD@{now}" commit new-two
63 check "@{-1}" ref refs/heads/old-branch
64 check "@{-1}@{0}" commit old-two
65 check "@{-1}@{1}" commit old-one
66 check "@{u}" ref refs/heads/upstream-branch
67 check "HEAD@{u}" ref refs/heads/upstream-branch
68 check "@{u}@{1}" commit upstream-one
69 check "@{-1}@{u}" ref refs/heads/main
70 check "@{-1}@{u}@{1}" commit main-one
71 check "@" commit new-two
72 check "@@{u}" ref refs/heads/upstream-branch
73 check "@@/at-test" ref refs/heads/@@/at-test
74 test_have_prereq MINGW ||
75 check "@/at-test" ref refs/heads/@/at-test
76 check "@at-test" ref refs/heads/@at-test
77 nonsense "@{u}@{-1}"
78 nonsense "@{0}@{0}"
79 nonsense "@{1}@{u}"
80 nonsense "HEAD@{-1}"
81 nonsense "@{-1}@{-1}"
83 # @{N} versus HEAD@{N}
85 check "HEAD@{3}" commit old-two
86 nonsense "@{3}"
88 test_expect_success 'switch to old-branch' '
89 git checkout old-branch
92 check HEAD ref refs/heads/old-branch
93 check "HEAD@{1}" commit new-two
94 check "@{1}" commit old-one
96 test_expect_success 'create path with @' '
97 echo content >normal &&
98 echo content >fun@ny &&
99 git add normal fun@ny &&
100 git commit -m "funny path"
103 check "@:normal" blob content
104 check "@:fun@ny" blob content
106 test_expect_success '@{1} works with only one reflog entry' '
107 git checkout -B newbranch main &&
108 git reflog expire --expire=now refs/heads/newbranch &&
109 git commit --allow-empty -m "first after expiration" &&
110 test_cmp_rev newbranch~ newbranch@{1}
113 test_expect_success '@{0} works with empty reflog' '
114 git checkout -B newbranch main &&
115 git reflog expire --expire=now refs/heads/newbranch &&
116 test_cmp_rev newbranch newbranch@{0}
119 test_done