t / t1508-at-combinations.shon commit revision: new rev^-n shorthand for rev^n..rev (8779351)
   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                elif test '$2' = 'ref'
  13                then
  14                        git rev-parse --symbolic-full-name '$1' >actual
  15                else
  16                        git cat-file -p '$1' >actual
  17                fi &&
  18                test_cmp expect actual
  19        "
  20}
  21
  22nonsense() {
  23        test_expect_${2:-success} "$1 is nonsensical" "
  24                test_must_fail git rev-parse --verify '$1'
  25        "
  26}
  27
  28fail() {
  29        "$@" failure
  30}
  31
  32test_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 &&
  38        if test_have_prereq !MINGW
  39        then
  40                git checkout -b @/at-test
  41        fi &&
  42        git checkout -b @@/at-test &&
  43        git checkout -b @at-test &&
  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 &&
  50        git branch -u master old-branch &&
  51        git branch -u upstream-branch new-branch
  52'
  53
  54check HEAD ref refs/heads/new-branch
  55check "@{1}" commit new-one
  56check "HEAD@{1}" commit new-one
  57check "@{now}" commit new-two
  58check "HEAD@{now}" commit new-two
  59check "@{-1}" ref refs/heads/old-branch
  60check "@{-1}@{0}" commit old-two
  61check "@{-1}@{1}" commit old-one
  62check "@{u}" ref refs/heads/upstream-branch
  63check "HEAD@{u}" ref refs/heads/upstream-branch
  64check "@{u}@{1}" commit upstream-one
  65check "@{-1}@{u}" ref refs/heads/master
  66check "@{-1}@{u}@{1}" commit master-one
  67check "@" commit new-two
  68check "@@{u}" ref refs/heads/upstream-branch
  69check "@@/at-test" ref refs/heads/@@/at-test
  70test_have_prereq MINGW ||
  71check "@/at-test" ref refs/heads/@/at-test
  72check "@at-test" ref refs/heads/@at-test
  73nonsense "@{u}@{-1}"
  74nonsense "@{0}@{0}"
  75nonsense "@{1}@{u}"
  76nonsense "HEAD@{-1}"
  77nonsense "@{-1}@{-1}"
  78
  79# @{N} versus HEAD@{N}
  80
  81check "HEAD@{3}" commit old-two
  82nonsense "@{3}"
  83
  84test_expect_success 'switch to old-branch' '
  85        git checkout old-branch
  86'
  87
  88check HEAD ref refs/heads/old-branch
  89check "HEAD@{1}" commit new-two
  90check "@{1}" commit old-one
  91
  92test_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
  99check "@:normal" blob content
 100check "@:fun@ny" blob content
 101
 102test_done