Merge branch 'ar/submodule-add-config'
[git/debian.git] / t / t1508-at-combinations.sh
blob87a42864145f85ed539b9d1cbb9a3dd5f71fc708
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-lib.sh
9 check() {
10 test_expect_${4:-success} "$1 = $3" "
11 echo '$3' >expect &&
12 if test '$2' = 'commit'
13 then
14 git log -1 --format=%s '$1' >actual
15 elif test '$2' = 'ref'
16 then
17 git rev-parse --symbolic-full-name '$1' >actual
18 else
19 git cat-file -p '$1' >actual
20 fi &&
21 test_cmp expect actual
25 nonsense() {
26 test_expect_${2:-success} "$1 is nonsensical" "
27 test_must_fail git rev-parse --verify '$1'
31 fail() {
32 "$@" failure
35 test_expect_success 'setup' '
36 test_commit main-one &&
37 test_commit main-two &&
38 git checkout -b upstream-branch &&
39 test_commit upstream-one &&
40 test_commit upstream-two &&
41 if test_have_prereq !MINGW
42 then
43 git checkout -b @/at-test
44 fi &&
45 git checkout -b @@/at-test &&
46 git checkout -b @at-test &&
47 git checkout -b old-branch &&
48 test_commit old-one &&
49 test_commit old-two &&
50 git checkout -b new-branch &&
51 test_commit new-one &&
52 test_commit new-two &&
53 git branch -u main old-branch &&
54 git branch -u upstream-branch new-branch
57 check HEAD ref refs/heads/new-branch
58 check "@{1}" commit new-one
59 check "HEAD@{1}" commit new-one
60 check "@{now}" commit new-two
61 check "HEAD@{now}" commit new-two
62 check "@{-1}" ref refs/heads/old-branch
63 check "@{-1}@{0}" commit old-two
64 check "@{-1}@{1}" commit old-one
65 check "@{u}" ref refs/heads/upstream-branch
66 check "HEAD@{u}" ref refs/heads/upstream-branch
67 check "@{u}@{1}" commit upstream-one
68 check "@{-1}@{u}" ref refs/heads/main
69 check "@{-1}@{u}@{1}" commit main-one
70 check "@" commit new-two
71 check "@@{u}" ref refs/heads/upstream-branch
72 check "@@/at-test" ref refs/heads/@@/at-test
73 test_have_prereq MINGW ||
74 check "@/at-test" ref refs/heads/@/at-test
75 check "@at-test" ref refs/heads/@at-test
76 nonsense "@{u}@{-1}"
77 nonsense "@{0}@{0}"
78 nonsense "@{1}@{u}"
79 nonsense "HEAD@{-1}"
80 nonsense "@{-1}@{-1}"
82 # @{N} versus HEAD@{N}
84 check "HEAD@{3}" commit old-two
85 nonsense "@{3}"
87 test_expect_success 'switch to old-branch' '
88 git checkout old-branch
91 check HEAD ref refs/heads/old-branch
92 check "HEAD@{1}" commit new-two
93 check "@{1}" commit old-one
95 test_expect_success 'create path with @' '
96 echo content >normal &&
97 echo content >fun@ny &&
98 git add normal fun@ny &&
99 git commit -m "funny path"
102 check "@:normal" blob content
103 check "@:fun@ny" blob content
105 test_expect_success '@{1} works with only one reflog entry' '
106 git checkout -B newbranch main &&
107 git reflog expire --expire=now refs/heads/newbranch &&
108 git commit --allow-empty -m "first after expiration" &&
109 test_cmp_rev newbranch~ newbranch@{1}
112 test_expect_success '@{0} works with empty reflog' '
113 git checkout -B newbranch main &&
114 git reflog expire --expire=now refs/heads/newbranch &&
115 test_cmp_rev newbranch newbranch@{0}
118 test_done