22fcacfa3314112872e6c0884174aeb449884fb2
   1#!/bin/sh
   2
   3test_description='diff --relative tests'
   4. ./test-lib.sh
   5
   6test_expect_success 'setup' '
   7        git commit --allow-empty -m empty &&
   8        echo content >file1 &&
   9        mkdir subdir &&
  10        echo other content >subdir/file2 &&
  11        git add . &&
  12        git commit -m one
  13'
  14
  15check_diff() {
  16dir=$1; shift
  17expect=$1; shift
  18cat >expected <<EOF
  19diff --git a/$expect b/$expect
  20new file mode 100644
  21index 0000000..25c05ef
  22--- /dev/null
  23+++ b/$expect
  24@@ -0,0 +1 @@
  25+other content
  26EOF
  27test_expect_success "-p $*" "
  28        git -C '$dir' diff -p $* HEAD^ >actual &&
  29        test_cmp expected actual
  30"
  31}
  32
  33check_numstat() {
  34dir=$1; shift
  35expect=$1; shift
  36cat >expected <<EOF
  371       0       $expect
  38EOF
  39test_expect_success "--numstat $*" "
  40        echo '1 0       $expect' >expected &&
  41        git -C '$dir' diff --numstat $* HEAD^ >actual &&
  42        test_cmp expected actual
  43"
  44}
  45
  46check_stat() {
  47dir=$1; shift
  48expect=$1; shift
  49cat >expected <<EOF
  50 $expect | 1 +
  51 1 file changed, 1 insertion(+)
  52EOF
  53test_expect_success "--stat $*" "
  54        git -C '$dir' diff --stat $* HEAD^ >actual &&
  55        test_i18ncmp expected actual
  56"
  57}
  58
  59check_raw() {
  60dir=$1; shift
  61expect=$1; shift
  62cat >expected <<EOF
  63:000000 100644 0000000000000000000000000000000000000000 25c05ef3639d2d270e7fe765a67668f098092bc5 A      $expect
  64EOF
  65test_expect_success "--raw $*" "
  66        git -C '$dir' diff --no-abbrev --raw $* HEAD^ >actual &&
  67        test_cmp expected actual
  68"
  69}
  70
  71for type in diff numstat stat raw
  72do
  73        check_$type . file2 --relative=subdir/
  74        check_$type . file2 --relative=subdir
  75        check_$type subdir file2 --relative
  76        check_$type . dir/file2 --relative=sub
  77done
  78
  79test_done