1#!/bin/sh
2
3test_description='test various @{X} syntax combinations together'
4. ./test-lib.sh
5
6check() {
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 "
17}
18
19nonsense() {
20 test_expect_${2:-success} "$1 is nonsensical" "
21 test_must_fail git rev-parse --verify '$1'
22 "
23}
24
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 &&
35 git checkout -b old-branch &&
36 test_commit old-one &&
37 test_commit old-two &&
38 git checkout -b new-branch &&
39 test_commit new-one &&
40 test_commit new-two &&
41 git branch -u master old-branch &&
42 git branch -u upstream-branch new-branch
43'
44
45check HEAD ref refs/heads/new-branch
46check "@{1}" commit new-one
47check "HEAD@{1}" commit new-one
48check "@{now}" commit new-two
49check "HEAD@{now}" commit new-two
50check "@{-1}" ref refs/heads/old-branch
51check "@{-1}@{0}" commit old-two
52check "@{-1}@{1}" commit old-one
53check "@{u}" ref refs/heads/upstream-branch
54check "HEAD@{u}" ref refs/heads/upstream-branch
55check "@{u}@{1}" commit upstream-one
56check "@{-1}@{u}" ref refs/heads/master
57check "@{-1}@{u}@{1}" commit master-one
58nonsense "@{u}@{-1}"
59nonsense "@{0}@{0}"
60nonsense "@{1}@{u}"
61nonsense "HEAD@{-1}"
62nonsense "@{-1}@{-1}"
63
64# @{N} versus HEAD@{N}
65
66check "HEAD@{3}" commit old-two
67nonsense "@{3}"
68
69test_expect_success 'switch to old-branch' '
70 git checkout old-branch
71'
72
73check HEAD ref refs/heads/old-branch
74check "HEAD@{1}" commit new-two
75check "@{1}" commit old-one
76
77test_done