]>
Commit | Line | Data |
---|---|---|
f8b6809d JH |
1 | #!/bin/sh |
2 | ||
3 | test_description='rewrite diff' | |
4 | ||
5 | . ./test-lib.sh | |
6 | ||
7 | test_expect_success setup ' | |
8 | ||
bfdbee98 | 9 | cat "$TEST_DIRECTORY"/../COPYING >test && |
f8b6809d | 10 | git add test && |
40a7ce64 JK |
11 | tr \ |
12 | "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" \ | |
13 | "nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM" \ | |
467ddc14 JH |
14 | <"$TEST_DIRECTORY"/../COPYING >test && |
15 | echo "to be deleted" >test2 && | |
16 | git add test2 | |
f8b6809d JH |
17 | |
18 | ' | |
19 | ||
20 | test_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 | ||
467ddc14 JH |
30 | cat >expect <<EOF |
31 | diff --git a/test2 b/test2 | |
32 | deleted file mode 100644 | |
33 | index 4202011..0000000 | |
34 | --- a/test2 | |
35 | +++ /dev/null | |
36 | @@ -1 +0,0 @@ | |
37 | -to be deleted | |
38 | EOF | |
39 | test_expect_success 'show deletion diff without -D' ' | |
40 | ||
41 | rm test2 && | |
42 | git diff -- test2 >actual && | |
43 | test_cmp expect actual | |
44 | ' | |
45 | ||
46 | cat >expect <<EOF | |
47 | diff --git a/test2 b/test2 | |
48 | deleted file mode 100644 | |
49 | index 4202011..0000000 | |
50 | EOF | |
51 | test_expect_success 'suppress deletion diff with -D' ' | |
52 | ||
53 | git diff -D -- test2 >actual && | |
54 | test_cmp expect actual | |
55 | ' | |
56 | ||
57 | test_expect_success 'show deletion diff with -B' ' | |
58 | ||
59 | git diff -B -- test >actual && | |
60 | grep "Linus Torvalds" actual | |
61 | ' | |
62 | ||
63 | test_expect_success 'suppress deletion diff with -B -D' ' | |
64 | ||
65 | git diff -B -D -- test >actual && | |
66 | grep -v "Linus Torvalds" actual | |
67 | ' | |
68 | ||
35e2d03c AB |
69 | test_expect_success 'prepare a file that ends with an incomplete line' ' |
70 | test_seq 1 99 >seq && | |
71 | printf 100 >>seq && | |
72 | git add seq && | |
73 | git commit seq -m seq | |
74 | ' | |
75 | ||
76 | test_expect_success 'rewrite the middle 90% of sequence file and terminate with newline' ' | |
77 | test_seq 1 5 >seq && | |
78 | test_seq 9331 9420 >>seq && | |
79 | test_seq 96 100 >>seq | |
80 | ' | |
81 | ||
82 | test_expect_success 'confirm that sequence file is considered a rewrite' ' | |
83 | git diff -B seq >res && | |
84 | grep "dissimilarity index" res | |
85 | ' | |
86 | ||
87 | test_expect_success 'no newline at eof is on its own line without -B' ' | |
88 | git diff seq >res && | |
89 | grep "^\\\\ " res && | |
90 | ! grep "^..*\\\\ " res | |
91 | ' | |
92 | ||
93 | test_expect_success 'no newline at eof is on its own line with -B' ' | |
94 | git diff -B seq >res && | |
95 | grep "^\\\\ " res && | |
96 | ! grep "^..*\\\\ " res | |
97 | ' | |
98 | ||
f8b6809d JH |
99 | test_done |
100 |