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 |
Jeff King | 8cd4249 | 2014-01-15 03:31:57 -0500 | [diff] [blame] | 12 | elif test '$2' = 'ref' |
| 13 | then |
Felipe Contreras | c8a81e9 | 2013-05-07 16:55:02 -0500 | [diff] [blame] | 14 | git rev-parse --symbolic-full-name '$1' >actual |
Jeff King | 8cd4249 | 2014-01-15 03:31:57 -0500 | [diff] [blame] | 15 | else |
| 16 | git cat-file -p '$1' >actual |
Felipe Contreras | c8a81e9 | 2013-05-07 16:55:02 -0500 | [diff] [blame] | 17 | fi && |
| 18 | test_cmp expect actual |
| 19 | " |
Jeff King | 42cab60 | 2010-01-28 04:50:20 -0500 | [diff] [blame] | 20 | } |
Felipe Contreras | c8a81e9 | 2013-05-07 16:55:02 -0500 | [diff] [blame] | 21 | |
Jeff King | 42cab60 | 2010-01-28 04:50:20 -0500 | [diff] [blame] | 22 | nonsense() { |
Felipe Contreras | c8a81e9 | 2013-05-07 16:55:02 -0500 | [diff] [blame] | 23 | test_expect_${2:-success} "$1 is nonsensical" " |
Felipe Contreras | 89d5dd4 | 2013-05-07 16:55:03 -0500 | [diff] [blame] | 24 | test_must_fail git rev-parse --verify '$1' |
Felipe Contreras | c8a81e9 | 2013-05-07 16:55:02 -0500 | [diff] [blame] | 25 | " |
Jeff King | 42cab60 | 2010-01-28 04:50:20 -0500 | [diff] [blame] | 26 | } |
Felipe Contreras | c8a81e9 | 2013-05-07 16:55:02 -0500 | [diff] [blame] | 27 | |
Jeff King | 42cab60 | 2010-01-28 04:50:20 -0500 | [diff] [blame] | 28 | fail() { |
| 29 | "$@" failure |
| 30 | } |
| 31 | |
| 32 | test_expect_success 'setup' ' |
| 33 | test_commit master-one && |
| 34 | test_commit master-two && |
| 35 | git checkout -b upstream-branch && |
| 36 | test_commit upstream-one && |
| 37 | test_commit upstream-two && |
Johannes Schindelin | 8facec0 | 2016-01-27 17:19:52 +0100 | [diff] [blame] | 38 | if test_have_prereq !MINGW |
| 39 | then |
| 40 | git checkout -b @/at-test |
| 41 | fi && |
Felipe Contreras | 9ba89f4 | 2013-09-02 01:34:30 -0500 | [diff] [blame] | 42 | git checkout -b @@/at-test && |
| 43 | git checkout -b @at-test && |
Jeff King | 42cab60 | 2010-01-28 04:50:20 -0500 | [diff] [blame] | 44 | git checkout -b old-branch && |
| 45 | test_commit old-one && |
| 46 | test_commit old-two && |
| 47 | git checkout -b new-branch && |
| 48 | test_commit new-one && |
| 49 | test_commit new-two && |
Felipe Contreras | 1bc6d02 | 2013-05-07 16:55:01 -0500 | [diff] [blame] | 50 | git branch -u master old-branch && |
| 51 | git branch -u upstream-branch new-branch |
Jeff King | 42cab60 | 2010-01-28 04:50:20 -0500 | [diff] [blame] | 52 | ' |
| 53 | |
Felipe Contreras | c8a81e9 | 2013-05-07 16:55:02 -0500 | [diff] [blame] | 54 | check HEAD ref refs/heads/new-branch |
| 55 | check "@{1}" commit new-one |
Ramkumar Ramachandra | f58dc19 | 2013-05-07 16:55:04 -0500 | [diff] [blame] | 56 | check "HEAD@{1}" commit new-one |
| 57 | check "@{now}" commit new-two |
| 58 | check "HEAD@{now}" commit new-two |
Felipe Contreras | c8a81e9 | 2013-05-07 16:55:02 -0500 | [diff] [blame] | 59 | check "@{-1}" ref refs/heads/old-branch |
Ramkumar Ramachandra | f58dc19 | 2013-05-07 16:55:04 -0500 | [diff] [blame] | 60 | check "@{-1}@{0}" commit old-two |
Felipe Contreras | c8a81e9 | 2013-05-07 16:55:02 -0500 | [diff] [blame] | 61 | check "@{-1}@{1}" commit old-one |
| 62 | check "@{u}" ref refs/heads/upstream-branch |
Ramkumar Ramachandra | f58dc19 | 2013-05-07 16:55:04 -0500 | [diff] [blame] | 63 | check "HEAD@{u}" ref refs/heads/upstream-branch |
Felipe Contreras | c8a81e9 | 2013-05-07 16:55:02 -0500 | [diff] [blame] | 64 | check "@{u}@{1}" commit upstream-one |
| 65 | check "@{-1}@{u}" ref refs/heads/master |
| 66 | check "@{-1}@{u}@{1}" commit master-one |
Felipe Contreras | 9ba89f4 | 2013-09-02 01:34:30 -0500 | [diff] [blame] | 67 | check "@" commit new-two |
| 68 | check "@@{u}" ref refs/heads/upstream-branch |
| 69 | check "@@/at-test" ref refs/heads/@@/at-test |
Johannes Schindelin | 8facec0 | 2016-01-27 17:19:52 +0100 | [diff] [blame] | 70 | test_have_prereq MINGW || |
Felipe Contreras | 9ba89f4 | 2013-09-02 01:34:30 -0500 | [diff] [blame] | 71 | check "@/at-test" ref refs/heads/@/at-test |
| 72 | check "@at-test" ref refs/heads/@at-test |
Jeff King | 12a258c | 2010-01-28 04:56:43 -0500 | [diff] [blame] | 73 | nonsense "@{u}@{-1}" |
Ramkumar Ramachandra | f58dc19 | 2013-05-07 16:55:04 -0500 | [diff] [blame] | 74 | nonsense "@{0}@{0}" |
Jeff King | 42cab60 | 2010-01-28 04:50:20 -0500 | [diff] [blame] | 75 | nonsense "@{1}@{u}" |
Ramkumar Ramachandra | f58dc19 | 2013-05-07 16:55:04 -0500 | [diff] [blame] | 76 | nonsense "HEAD@{-1}" |
| 77 | nonsense "@{-1}@{-1}" |
Jeff King | 42cab60 | 2010-01-28 04:50:20 -0500 | [diff] [blame] | 78 | |
Ramkumar Ramachandra | 723b74e | 2013-05-07 16:55:05 -0500 | [diff] [blame] | 79 | # @{N} versus HEAD@{N} |
| 80 | |
| 81 | check "HEAD@{3}" commit old-two |
| 82 | nonsense "@{3}" |
| 83 | |
| 84 | test_expect_success 'switch to old-branch' ' |
| 85 | git checkout old-branch |
| 86 | ' |
| 87 | |
| 88 | check HEAD ref refs/heads/old-branch |
| 89 | check "HEAD@{1}" commit new-two |
| 90 | check "@{1}" commit old-one |
| 91 | |
Jeff King | 8cd4249 | 2014-01-15 03:31:57 -0500 | [diff] [blame] | 92 | test_expect_success 'create path with @' ' |
| 93 | echo content >normal && |
| 94 | echo content >fun@ny && |
| 95 | git add normal fun@ny && |
| 96 | git commit -m "funny path" |
| 97 | ' |
| 98 | |
| 99 | check "@:normal" blob content |
| 100 | check "@:fun@ny" blob content |
| 101 | |
Jeff King | 42cab60 | 2010-01-28 04:50:20 -0500 | [diff] [blame] | 102 | test_done |