t / t4045-diff-relative.shon commit Merge branch 'jk/diff-highlight-graph-fix' (d19e556)
   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 () {
  16        dir=$1
  17        shift
  18        expect=$1
  19        shift
  20        cat >expected <<-EOF
  21        diff --git a/$expect b/$expect
  22        new file mode 100644
  23        index 0000000..25c05ef
  24        --- /dev/null
  25        +++ b/$expect
  26        @@ -0,0 +1 @@
  27        +other content
  28        EOF
  29        test_expect_success "-p $*" "
  30                git -C '$dir' diff -p $* HEAD^ >actual &&
  31                test_cmp expected actual
  32        "
  33}
  34
  35check_numstat () {
  36        dir=$1
  37        shift
  38        expect=$1
  39        shift
  40        cat >expected <<-EOF
  41        1       0       $expect
  42        EOF
  43        test_expect_success "--numstat $*" "
  44                echo '1 0       $expect' >expected &&
  45                git -C '$dir' diff --numstat $* HEAD^ >actual &&
  46                test_cmp expected actual
  47        "
  48}
  49
  50check_stat () {
  51        dir=$1
  52        shift
  53        expect=$1
  54        shift
  55        cat >expected <<-EOF
  56         $expect | 1 +
  57         1 file changed, 1 insertion(+)
  58        EOF
  59        test_expect_success "--stat $*" "
  60                git -C '$dir' diff --stat $* HEAD^ >actual &&
  61                test_i18ncmp expected actual
  62        "
  63}
  64
  65check_raw () {
  66        dir=$1
  67        shift
  68        expect=$1
  69        shift
  70        cat >expected <<-EOF
  71        :000000 100644 0000000000000000000000000000000000000000 25c05ef3639d2d270e7fe765a67668f098092bc5 A      $expect
  72        EOF
  73        test_expect_success "--raw $*" "
  74                git -C '$dir' diff --no-abbrev --raw $* HEAD^ >actual &&
  75                test_cmp expected actual
  76        "
  77}
  78
  79for type in diff numstat stat raw
  80do
  81        check_$type . file2 --relative=subdir/
  82        check_$type . file2 --relative=subdir
  83        check_$type subdir file2 --relative
  84        check_$type . dir/file2 --relative=sub
  85done
  86
  87test_done