Jeff King | 42cab60 | 2010-01-28 04:50:20 -0500 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='test various @{X} syntax combinations together' |
| 4 | . ./test-lib.sh |
| 5 | |
| 6 | check() { |
Felipe Contreras | c8a81e9 | 2013-05-07 16:55:02 -0500 | [diff] [blame] | 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 | " |
Jeff King | 42cab60 | 2010-01-28 04:50:20 -0500 | [diff] [blame] | 17 | } |
Felipe Contreras | c8a81e9 | 2013-05-07 16:55:02 -0500 | [diff] [blame] | 18 | |
Jeff King | 42cab60 | 2010-01-28 04:50:20 -0500 | [diff] [blame] | 19 | nonsense() { |
Felipe Contreras | c8a81e9 | 2013-05-07 16:55:02 -0500 | [diff] [blame] | 20 | test_expect_${2:-success} "$1 is nonsensical" " |
Felipe Contreras | 89d5dd4 | 2013-05-07 16:55:03 -0500 | [diff] [blame] | 21 | test_must_fail git rev-parse --verify '$1' |
Felipe Contreras | c8a81e9 | 2013-05-07 16:55:02 -0500 | [diff] [blame] | 22 | " |
Jeff King | 42cab60 | 2010-01-28 04:50:20 -0500 | [diff] [blame] | 23 | } |
Felipe Contreras | c8a81e9 | 2013-05-07 16:55:02 -0500 | [diff] [blame] | 24 | |
Jeff King | 42cab60 | 2010-01-28 04:50:20 -0500 | [diff] [blame] | 25 | fail() { |
| 26 | "$@" failure |
| 27 | } |
| 28 | |
| 29 | test_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 && |
Felipe Contreras | 1bc6d02 | 2013-05-07 16:55:01 -0500 | [diff] [blame] | 41 | git branch -u master old-branch && |
| 42 | git branch -u upstream-branch new-branch |
Jeff King | 42cab60 | 2010-01-28 04:50:20 -0500 | [diff] [blame] | 43 | ' |
| 44 | |
Felipe Contreras | c8a81e9 | 2013-05-07 16:55:02 -0500 | [diff] [blame] | 45 | check HEAD ref refs/heads/new-branch |
| 46 | check "@{1}" commit new-one |
Ramkumar Ramachandra | f58dc19 | 2013-05-07 16:55:04 -0500 | [diff] [blame^] | 47 | check "HEAD@{1}" commit new-one |
| 48 | check "@{now}" commit new-two |
| 49 | check "HEAD@{now}" commit new-two |
Felipe Contreras | c8a81e9 | 2013-05-07 16:55:02 -0500 | [diff] [blame] | 50 | check "@{-1}" ref refs/heads/old-branch |
Ramkumar Ramachandra | f58dc19 | 2013-05-07 16:55:04 -0500 | [diff] [blame^] | 51 | check "@{-1}@{0}" commit old-two |
Felipe Contreras | c8a81e9 | 2013-05-07 16:55:02 -0500 | [diff] [blame] | 52 | check "@{-1}@{1}" commit old-one |
| 53 | check "@{u}" ref refs/heads/upstream-branch |
Ramkumar Ramachandra | f58dc19 | 2013-05-07 16:55:04 -0500 | [diff] [blame^] | 54 | check "HEAD@{u}" ref refs/heads/upstream-branch |
Felipe Contreras | c8a81e9 | 2013-05-07 16:55:02 -0500 | [diff] [blame] | 55 | check "@{u}@{1}" commit upstream-one |
| 56 | check "@{-1}@{u}" ref refs/heads/master |
| 57 | check "@{-1}@{u}@{1}" commit master-one |
Jeff King | 12a258c | 2010-01-28 04:56:43 -0500 | [diff] [blame] | 58 | nonsense "@{u}@{-1}" |
Ramkumar Ramachandra | f58dc19 | 2013-05-07 16:55:04 -0500 | [diff] [blame^] | 59 | nonsense "@{0}@{0}" |
Jeff King | 42cab60 | 2010-01-28 04:50:20 -0500 | [diff] [blame] | 60 | nonsense "@{1}@{u}" |
Ramkumar Ramachandra | f58dc19 | 2013-05-07 16:55:04 -0500 | [diff] [blame^] | 61 | nonsense "HEAD@{-1}" |
| 62 | nonsense "@{-1}@{-1}" |
Jeff King | 42cab60 | 2010-01-28 04:50:20 -0500 | [diff] [blame] | 63 | |
| 64 | test_done |