]> git.ipfire.org Git - thirdparty/git.git/blame - t/t1508-at-combinations.sh
Merge branch 'eg/config-type-path-docfix'
[thirdparty/git.git] / t / t1508-at-combinations.sh
CommitLineData
42cab601
JK
1#!/bin/sh
2
3test_description='test various @{X} syntax combinations together'
06d53148 4GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
334afbc7
JS
5export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
6
80d32e84 7TEST_PASSES_SANITIZE_LEAK=true
42cab601
JK
8. ./test-lib.sh
9
10check() {
c8a81e90
FC
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
8cd4249c
JK
16 elif test '$2' = 'ref'
17 then
c8a81e90 18 git rev-parse --symbolic-full-name '$1' >actual
8cd4249c
JK
19 else
20 git cat-file -p '$1' >actual
c8a81e90
FC
21 fi &&
22 test_cmp expect actual
23 "
42cab601 24}
c8a81e90 25
42cab601 26nonsense() {
c8a81e90 27 test_expect_${2:-success} "$1 is nonsensical" "
89d5dd4e 28 test_must_fail git rev-parse --verify '$1'
c8a81e90 29 "
42cab601 30}
c8a81e90 31
42cab601
JK
32fail() {
33 "$@" failure
34}
35
36test_expect_success 'setup' '
06d53148
JS
37 test_commit main-one &&
38 test_commit main-two &&
42cab601
JK
39 git checkout -b upstream-branch &&
40 test_commit upstream-one &&
41 test_commit upstream-two &&
8facec08
JS
42 if test_have_prereq !MINGW
43 then
44 git checkout -b @/at-test
45 fi &&
9ba89f48
FC
46 git checkout -b @@/at-test &&
47 git checkout -b @at-test &&
42cab601
JK
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 &&
06d53148 54 git branch -u main old-branch &&
1bc6d022 55 git branch -u upstream-branch new-branch
42cab601
JK
56'
57
c8a81e90
FC
58check HEAD ref refs/heads/new-branch
59check "@{1}" commit new-one
f58dc19e
RR
60check "HEAD@{1}" commit new-one
61check "@{now}" commit new-two
62check "HEAD@{now}" commit new-two
c8a81e90 63check "@{-1}" ref refs/heads/old-branch
f58dc19e 64check "@{-1}@{0}" commit old-two
c8a81e90
FC
65check "@{-1}@{1}" commit old-one
66check "@{u}" ref refs/heads/upstream-branch
f58dc19e 67check "HEAD@{u}" ref refs/heads/upstream-branch
c8a81e90 68check "@{u}@{1}" commit upstream-one
06d53148
JS
69check "@{-1}@{u}" ref refs/heads/main
70check "@{-1}@{u}@{1}" commit main-one
9ba89f48
FC
71check "@" commit new-two
72check "@@{u}" ref refs/heads/upstream-branch
73check "@@/at-test" ref refs/heads/@@/at-test
8facec08 74test_have_prereq MINGW ||
9ba89f48
FC
75check "@/at-test" ref refs/heads/@/at-test
76check "@at-test" ref refs/heads/@at-test
12a258c0 77nonsense "@{u}@{-1}"
f58dc19e 78nonsense "@{0}@{0}"
42cab601 79nonsense "@{1}@{u}"
f58dc19e
RR
80nonsense "HEAD@{-1}"
81nonsense "@{-1}@{-1}"
42cab601 82
723b74ee
RR
83# @{N} versus HEAD@{N}
84
85check "HEAD@{3}" commit old-two
86nonsense "@{3}"
87
88test_expect_success 'switch to old-branch' '
89 git checkout old-branch
90'
91
92check HEAD ref refs/heads/old-branch
93check "HEAD@{1}" commit new-two
94check "@{1}" commit old-one
95
8cd4249c
JK
96test_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"
101'
102
103check "@:normal" blob content
104check "@:fun@ny" blob content
105
6436a202 106test_expect_success '@{1} works with only one reflog entry' '
27d7c859 107 git checkout -B newbranch main &&
6436a202
DL
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}
111'
112
113test_expect_success '@{0} works with empty reflog' '
27d7c859 114 git checkout -B newbranch main &&
6436a202
DL
115 git reflog expire --expire=now refs/heads/newbranch &&
116 test_cmp_rev newbranch newbranch@{0}
117'
118
42cab601 119test_done