t / t1513-rev-parse-prefix.shon commit t4018: an infrastructure to test hunk headers (bfa7d01)
   1#!/bin/sh
   2
   3test_description='Tests for rev-parse --prefix'
   4
   5. ./test-lib.sh
   6
   7test_expect_success 'setup' '
   8        mkdir -p sub1/sub2 &&
   9        echo top >top &&
  10        echo file1 >sub1/file1 &&
  11        echo file2 >sub1/sub2/file2 &&
  12        git add top sub1/file1 sub1/sub2/file2 &&
  13        git commit -m commit
  14'
  15
  16test_expect_success 'empty prefix -- file' '
  17        git rev-parse --prefix "" -- top sub1/file1 >actual &&
  18        cat <<-\EOF >expected &&
  19        --
  20        top
  21        sub1/file1
  22        EOF
  23        test_cmp expected actual
  24'
  25
  26test_expect_success 'valid prefix -- file' '
  27        git rev-parse --prefix sub1/ -- file1 sub2/file2 >actual &&
  28        cat <<-\EOF >expected &&
  29        --
  30        sub1/file1
  31        sub1/sub2/file2
  32        EOF
  33        test_cmp expected actual
  34'
  35
  36test_expect_success 'valid prefix -- ../file' '
  37        git rev-parse --prefix sub1/ -- ../top sub2/file2 >actual &&
  38        cat <<-\EOF >expected &&
  39        --
  40        sub1/../top
  41        sub1/sub2/file2
  42        EOF
  43        test_cmp expected actual
  44'
  45
  46test_expect_success 'empty prefix HEAD:./path' '
  47        git rev-parse --prefix "" HEAD:./top >actual &&
  48        git rev-parse HEAD:top >expected &&
  49        test_cmp expected actual
  50'
  51
  52test_expect_success 'valid prefix HEAD:./path' '
  53        git rev-parse --prefix sub1/ HEAD:./file1 >actual &&
  54        git rev-parse HEAD:sub1/file1 >expected &&
  55        test_cmp expected actual
  56'
  57
  58test_expect_success 'valid prefix HEAD:../path' '
  59        git rev-parse --prefix sub1/ HEAD:../top >actual &&
  60        git rev-parse HEAD:top >expected &&
  61        test_cmp expected actual
  62'
  63
  64test_expect_success 'prefix ignored with HEAD:top' '
  65        git rev-parse --prefix sub1/ HEAD:top >actual &&
  66        git rev-parse HEAD:top >expected &&
  67        test_cmp expected actual
  68'
  69
  70test_expect_success 'disambiguate path with valid prefix' '
  71        git rev-parse --prefix sub1/ file1 >actual &&
  72        cat <<-\EOF >expected &&
  73        sub1/file1
  74        EOF
  75        test_cmp expected actual
  76'
  77
  78test_expect_success 'file and refs with prefix' '
  79        git rev-parse --prefix sub1/ master file1 >actual &&
  80        cat <<-EOF >expected &&
  81        $(git rev-parse master)
  82        sub1/file1
  83        EOF
  84        test_cmp expected actual
  85'
  86
  87test_expect_success 'two-levels deep' '
  88        git rev-parse --prefix sub1/sub2/ -- file2 >actual &&
  89        cat <<-\EOF >expected &&
  90        --
  91        sub1/sub2/file2
  92        EOF
  93        test_cmp expected actual
  94'
  95
  96test_done