t / t4022-diff-rewrite.shon commit Merge branch 'cn/maint-lf-to-crlf-filter' into maint (3bb8d69)
   1#!/bin/sh
   2
   3test_description='rewrite diff'
   4
   5. ./test-lib.sh
   6
   7test_expect_success setup '
   8
   9        cat "$TEST_DIRECTORY"/../COPYING >test &&
  10        git add test &&
  11        tr \
  12          "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" \
  13          "nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM" \
  14          <"$TEST_DIRECTORY"/../COPYING >test &&
  15        echo "to be deleted" >test2 &&
  16        git add test2
  17
  18'
  19
  20test_expect_success 'detect rewrite' '
  21
  22        actual=$(git diff-files -B --summary test) &&
  23        expr "$actual" : " rewrite test ([0-9]*%)$" || {
  24                echo "Eh? <<$actual>>"
  25                false
  26        }
  27
  28'
  29
  30cat >expect <<EOF
  31diff --git a/test2 b/test2
  32deleted file mode 100644
  33index 4202011..0000000
  34--- a/test2
  35+++ /dev/null
  36@@ -1 +0,0 @@
  37-to be deleted
  38EOF
  39test_expect_success 'show deletion diff without -D' '
  40
  41        rm test2 &&
  42        git diff -- test2 >actual &&
  43        test_cmp expect actual
  44'
  45
  46cat >expect <<EOF
  47diff --git a/test2 b/test2
  48deleted file mode 100644
  49index 4202011..0000000
  50EOF
  51test_expect_success 'suppress deletion diff with -D' '
  52
  53        git diff -D -- test2 >actual &&
  54        test_cmp expect actual
  55'
  56
  57test_expect_success 'show deletion diff with -B' '
  58
  59        git diff -B -- test >actual &&
  60        grep "Linus Torvalds" actual
  61'
  62
  63test_expect_success 'suppress deletion diff with -B -D' '
  64
  65        git diff -B -D -- test >actual &&
  66        grep -v "Linus Torvalds" actual
  67'
  68
  69test_done
  70