t / t4045-diff-relative.shon commit Fix typo: existant->existent (7be8b3b)
   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() {
  16expect=$1; shift
  17cat >expected <<EOF
  18diff --git a/$expect b/$expect
  19new file mode 100644
  20index 0000000..25c05ef
  21--- /dev/null
  22+++ b/$expect
  23@@ -0,0 +1 @@
  24+other content
  25EOF
  26test_expect_success "-p $*" "
  27        git diff -p $* HEAD^ >actual &&
  28        test_cmp expected actual
  29"
  30}
  31
  32check_stat() {
  33expect=$1; shift
  34cat >expected <<EOF
  35 $expect |    1 +
  36 1 files changed, 1 insertions(+), 0 deletions(-)
  37EOF
  38test_expect_success "--stat $*" "
  39        git diff --stat $* HEAD^ >actual &&
  40        test_cmp expected actual
  41"
  42}
  43
  44check_raw() {
  45expect=$1; shift
  46cat >expected <<EOF
  47:000000 100644 0000000000000000000000000000000000000000 25c05ef3639d2d270e7fe765a67668f098092bc5 A      $expect
  48EOF
  49test_expect_success "--raw $*" "
  50        git diff --no-abbrev --raw $* HEAD^ >actual &&
  51        test_cmp expected actual
  52"
  53}
  54
  55for type in diff stat raw; do
  56        check_$type file2 --relative=subdir/
  57        check_$type file2 --relative=subdir
  58        check_$type dir/file2 --relative=sub
  59done
  60
  61test_done