Merge branch 'lw/daemon-log-destination'
[git] / t / t4022-diff-rewrite.sh
1 #!/bin/sh
2
3 test_description='rewrite diff'
4
5 . ./test-lib.sh
6
7 test_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
20 test_expect_success 'detect rewrite' '
21
22         actual=$(git diff-files -B --summary test) &&
23         verbose expr "$actual" : " rewrite test ([0-9]*%)$"
24
25 '
26
27 cat >expect <<EOF
28 diff --git a/test2 b/test2
29 deleted file mode 100644
30 index 4202011..0000000
31 --- a/test2
32 +++ /dev/null
33 @@ -1 +0,0 @@
34 -to be deleted
35 EOF
36 test_expect_success 'show deletion diff without -D' '
37
38         rm test2 &&
39         git diff -- test2 >actual &&
40         test_cmp expect actual
41 '
42
43 cat >expect <<EOF
44 diff --git a/test2 b/test2
45 deleted file mode 100644
46 index 4202011..0000000
47 EOF
48 test_expect_success 'suppress deletion diff with -D' '
49
50         git diff -D -- test2 >actual &&
51         test_cmp expect actual
52 '
53
54 test_expect_success 'show deletion diff with -B' '
55
56         git diff -B -- test >actual &&
57         grep "Linus Torvalds" actual
58 '
59
60 test_expect_success 'suppress deletion diff with -B -D' '
61
62         git diff -B -D -- test >actual &&
63         grep -v "Linus Torvalds" actual
64 '
65
66 test_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
73 test_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
79 test_expect_success 'confirm that sequence file is considered a rewrite' '
80         git diff -B seq >res &&
81         grep "dissimilarity index" res
82 '
83
84 test_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
90 test_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
96 test_done
97