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