t / t4022-diff-rewrite.shon commit Merge branch 'master' of https://github.com/Softcatala/git-po (8a8a584)
   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        verbose expr "$actual" : " rewrite test ([0-9]*%)$"
  24
  25'
  26
  27cat >expect <<EOF
  28diff --git a/test2 b/test2
  29deleted file mode 100644
  30index 4202011..0000000
  31--- a/test2
  32+++ /dev/null
  33@@ -1 +0,0 @@
  34-to be deleted
  35EOF
  36test_expect_success 'show deletion diff without -D' '
  37
  38        rm test2 &&
  39        git diff -- test2 >actual &&
  40        test_cmp expect actual
  41'
  42
  43cat >expect <<EOF
  44diff --git a/test2 b/test2
  45deleted file mode 100644
  46index 4202011..0000000
  47EOF
  48test_expect_success 'suppress deletion diff with -D' '
  49
  50        git diff -D -- test2 >actual &&
  51        test_cmp expect actual
  52'
  53
  54test_expect_success 'show deletion diff with -B' '
  55
  56        git diff -B -- test >actual &&
  57        grep "Linus Torvalds" actual
  58'
  59
  60test_expect_success 'suppress deletion diff with -B -D' '
  61
  62        git diff -B -D -- test >actual &&
  63        grep -v "Linus Torvalds" actual
  64'
  65
  66test_expect_success 'prepare a file that ends with an incomplete line' '
  67        test_seq 1 99 >seq &&
  68        printf 100 >>seq &&
  69        git add seq &&
  70        git commit seq -m seq
  71'
  72
  73test_expect_success 'rewrite the middle 90% of sequence file and terminate with newline' '
  74        test_seq 1 5 >seq &&
  75        test_seq 9331 9420 >>seq &&
  76        test_seq 96 100 >>seq
  77'
  78
  79test_expect_success 'confirm that sequence file is considered a rewrite' '
  80        git diff -B seq >res &&
  81        grep "dissimilarity index" res
  82'
  83
  84test_expect_success 'no newline at eof is on its own line without -B' '
  85        git diff seq >res &&
  86        grep "^\\\\ " res &&
  87        ! grep "^..*\\\\ " res
  88'
  89
  90test_expect_success 'no newline at eof is on its own line with -B' '
  91        git diff -B seq >res &&
  92        grep "^\\\\ " res &&
  93        ! grep "^..*\\\\ " res
  94'
  95
  96test_done
  97