Add new @ shortcut for HEAD
[git/git.git] / t / t1508-at-combinations.sh
CommitLineData
42cab601
JK
1#!/bin/sh
2
3test_description='test various @{X} syntax combinations together'
4. ./test-lib.sh
5
6check() {
c8a81e90
FC
7 test_expect_${4:-success} "$1 = $3" "
8 echo '$3' >expect &&
9 if test '$2' = 'commit'
10 then
11 git log -1 --format=%s '$1' >actual
12 else
13 git rev-parse --symbolic-full-name '$1' >actual
14 fi &&
15 test_cmp expect actual
16 "
42cab601 17}
c8a81e90 18
42cab601 19nonsense() {
c8a81e90 20 test_expect_${2:-success} "$1 is nonsensical" "
89d5dd4e 21 test_must_fail git rev-parse --verify '$1'
c8a81e90 22 "
42cab601 23}
c8a81e90 24
42cab601
JK
25fail() {
26 "$@" failure
27}
28
29test_expect_success 'setup' '
30 test_commit master-one &&
31 test_commit master-two &&
32 git checkout -b upstream-branch &&
33 test_commit upstream-one &&
34 test_commit upstream-two &&
9ba89f48
FC
35 git checkout -b @/at-test &&
36 git checkout -b @@/at-test &&
37 git checkout -b @at-test &&
42cab601
JK
38 git checkout -b old-branch &&
39 test_commit old-one &&
40 test_commit old-two &&
41 git checkout -b new-branch &&
42 test_commit new-one &&
43 test_commit new-two &&
1bc6d022
FC
44 git branch -u master old-branch &&
45 git branch -u upstream-branch new-branch
42cab601
JK
46'
47
c8a81e90
FC
48check HEAD ref refs/heads/new-branch
49check "@{1}" commit new-one
f58dc19e
RR
50check "HEAD@{1}" commit new-one
51check "@{now}" commit new-two
52check "HEAD@{now}" commit new-two
c8a81e90 53check "@{-1}" ref refs/heads/old-branch
f58dc19e 54check "@{-1}@{0}" commit old-two
c8a81e90
FC
55check "@{-1}@{1}" commit old-one
56check "@{u}" ref refs/heads/upstream-branch
f58dc19e 57check "HEAD@{u}" ref refs/heads/upstream-branch
c8a81e90
FC
58check "@{u}@{1}" commit upstream-one
59check "@{-1}@{u}" ref refs/heads/master
60check "@{-1}@{u}@{1}" commit master-one
9ba89f48
FC
61check "@" commit new-two
62check "@@{u}" ref refs/heads/upstream-branch
63check "@@/at-test" ref refs/heads/@@/at-test
64check "@/at-test" ref refs/heads/@/at-test
65check "@at-test" ref refs/heads/@at-test
12a258c0 66nonsense "@{u}@{-1}"
f58dc19e 67nonsense "@{0}@{0}"
42cab601 68nonsense "@{1}@{u}"
f58dc19e
RR
69nonsense "HEAD@{-1}"
70nonsense "@{-1}@{-1}"
42cab601 71
723b74ee
RR
72# @{N} versus HEAD@{N}
73
74check "HEAD@{3}" commit old-two
75nonsense "@{3}"
76
77test_expect_success 'switch to old-branch' '
78 git checkout old-branch
79'
80
81check HEAD ref refs/heads/old-branch
82check "HEAD@{1}" commit new-two
83check "@{1}" commit old-one
84
42cab601 85test_done