1#!/bin/sh
2
3test_description='test @{-N} syntax'
4
5. ./test-lib.sh
6
7
8make_commit () {
9 echo "$1" > "$1" &&
10 git add "$1" &&
11 git commit -m "$1"
12}
13
14
15test_expect_success 'setup' '
16
17 make_commit 1 &&
18 git branch side &&
19 make_commit 2 &&
20 make_commit 3 &&
21 git checkout side &&
22 make_commit 4 &&
23 git merge master &&
24 git checkout master
25
26'
27
28# 1 -- 2 -- 3 master
29# \ \
30# \ \
31# --- 4 --- 5 side
32#
33# and 'side' should be the last branch
34
35git log --graph --all --pretty=oneline --decorate
36
37test_rev_equivalent () {
38
39 git rev-parse "$1" > expect &&
40 git rev-parse "$2" > output &&
41 test_cmp expect output
42
43}
44
45test_expect_success '@{-1} works' '
46 test_rev_equivalent side @{-1}
47'
48
49test_expect_success '@{-1}~2 works' '
50 test_rev_equivalent side~2 @{-1}~2
51'
52
53test_expect_success '@{-1}^2 works' '
54 test_rev_equivalent side^2 @{-1}^2
55'
56
57test_expect_failure '@{-1}@{1} works' '
58 test_rev_equivalent side@{1} @{-1}@{1}
59'
60
61test_expect_success '@{-2} works' '
62 test_rev_equivalent master @{-2}
63'
64
65test_expect_success '@{-3} fails' '
66 test_must_fail git rev-parse @{-3}
67'
68
69test_done
70
71