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