The eleventh batch
[git/gitster.git] / t / t4022-diff-rewrite.sh
blob77bc36d5d8fd983dcbe82577593e2fdaeb946925
1 #!/bin/sh
3 test_description='rewrite diff'
5 TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
7 . "$TEST_DIRECTORY"/lib-diff-data.sh
9 test_expect_success setup '
11 COPYING_test_data >test.data &&
12 cp test.data test &&
13 git add test &&
14 tr \
15 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" \
16 "nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM" \
17 <test.data >test &&
18 echo "to be deleted" >test2 &&
19 blob=$(git hash-object test2) &&
20 blob=$(git rev-parse --short $blob) &&
21 git add test2
25 test_expect_success 'detect rewrite' '
27 actual=$(git diff-files -B --summary test) &&
28 expr "$actual" : " rewrite test ([0-9]*%)$"
32 cat >expect <<EOF
33 diff --git a/test2 b/test2
34 deleted file mode 100644
35 index $blob..0000000
36 --- a/test2
37 +++ /dev/null
38 @@ -1 +0,0 @@
39 -to be deleted
40 EOF
41 test_expect_success 'show deletion diff without -D' '
43 rm test2 &&
44 git diff -- test2 >actual &&
45 test_cmp expect actual
48 cat >expect <<EOF
49 diff --git a/test2 b/test2
50 deleted file mode 100644
51 index $blob..0000000
52 EOF
53 test_expect_success 'suppress deletion diff with -D' '
55 git diff -D -- test2 >actual &&
56 test_cmp expect actual
59 test_expect_success 'show deletion diff with -B' '
61 git diff -B -- test >actual &&
62 grep "Linus Torvalds" actual
65 test_expect_success 'suppress deletion diff with -B -D' '
67 git diff -B -D -- test >actual &&
68 grep -v "Linus Torvalds" actual
71 test_expect_success 'prepare a file that ends with an incomplete line' '
72 test_seq 1 99 >seq &&
73 printf 100 >>seq &&
74 git add seq &&
75 git commit seq -m seq
78 test_expect_success 'rewrite the middle 90% of sequence file and terminate with newline' '
79 test_seq 1 5 >seq &&
80 test_seq 9331 9420 >>seq &&
81 test_seq 96 100 >>seq
84 test_expect_success 'confirm that sequence file is considered a rewrite' '
85 git diff -B seq >res &&
86 grep "dissimilarity index" res
89 test_expect_success 'no newline at eof is on its own line without -B' '
90 git diff seq >res &&
91 grep "^\\\\ " res &&
92 ! grep "^..*\\\\ " res
95 test_expect_success 'no newline at eof is on its own line with -B' '
96 git diff -B seq >res &&
97 grep "^\\\\ " res &&
98 ! grep "^..*\\\\ " res
101 test_done