b2f90bea6a8d353842e059e102f8f93d117e4266
   1#!/bin/sh
   2
   3test_description='tests for ref^{stuff}'
   4
   5. ./test-lib.sh
   6
   7test_expect_success 'setup' '
   8        echo blob >a-blob &&
   9        git tag -a -m blob blob-tag `git hash-object -w a-blob` &&
  10        mkdir a-tree &&
  11        echo moreblobs >a-tree/another-blob &&
  12        git add . &&
  13        TREE_SHA1=`git write-tree` &&
  14        git tag -a -m tree tree-tag "$TREE_SHA1" &&
  15        git commit -m Initial &&
  16        git tag -a -m commit commit-tag &&
  17        git branch ref &&
  18        git checkout master &&
  19        echo modified >>a-blob &&
  20        git add -u &&
  21        git commit -m Modified &&
  22        git branch modref &&
  23        echo changed! >>a-blob &&
  24        git add -u &&
  25        git commit -m !Exp &&
  26        git branch expref &&
  27        echo changed >>a-blob &&
  28        git add -u &&
  29        git commit -m Changed
  30'
  31
  32test_expect_success 'ref^{non-existent}' '
  33        test_must_fail git rev-parse ref^{non-existent}
  34'
  35
  36test_expect_success 'ref^{}' '
  37        git rev-parse ref >expected &&
  38        git rev-parse ref^{} >actual &&
  39        test_cmp expected actual &&
  40        git rev-parse commit-tag^{} >actual &&
  41        test_cmp expected actual
  42'
  43
  44test_expect_success 'ref^{commit}' '
  45        git rev-parse ref >expected &&
  46        git rev-parse ref^{commit} >actual &&
  47        test_cmp expected actual &&
  48        git rev-parse commit-tag^{commit} >actual &&
  49        test_cmp expected actual &&
  50        test_must_fail git rev-parse tree-tag^{commit} &&
  51        test_must_fail git rev-parse blob-tag^{commit}
  52'
  53
  54test_expect_success 'ref^{tree}' '
  55        echo $TREE_SHA1 >expected &&
  56        git rev-parse ref^{tree} >actual &&
  57        test_cmp expected actual &&
  58        git rev-parse commit-tag^{tree} >actual &&
  59        test_cmp expected actual &&
  60        git rev-parse tree-tag^{tree} >actual &&
  61        test_cmp expected actual &&
  62        test_must_fail git rev-parse blob-tag^{tree}
  63'
  64
  65test_expect_success 'ref^{tag}' '
  66        test_must_fail git rev-parse HEAD^{tag} &&
  67        git rev-parse commit-tag >expected &&
  68        git rev-parse commit-tag^{tag} >actual &&
  69        test_cmp expected actual
  70'
  71
  72test_expect_success 'ref^{/.}' '
  73        git rev-parse master >expected &&
  74        git rev-parse master^{/.} >actual &&
  75        test_cmp expected actual
  76'
  77
  78test_expect_success 'ref^{/non-existent}' '
  79        test_must_fail git rev-parse master^{/non-existent}
  80'
  81
  82test_expect_success 'ref^{/Initial}' '
  83        git rev-parse ref >expected &&
  84        git rev-parse master^{/Initial} >actual &&
  85        test_cmp expected actual
  86'
  87
  88test_expect_success 'ref^{/!Exp}' '
  89        test_must_fail git rev-parse master^{/!Exp}
  90'
  91
  92test_expect_success 'ref^{/!}' '
  93        test_must_fail git rev-parse master^{/!}
  94'
  95
  96test_expect_success 'ref^{/!!Exp}' '
  97        git rev-parse expref >expected &&
  98        git rev-parse master^{/!!Exp} >actual &&
  99        test_cmp expected actual
 100'
 101
 102test_done