]>
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) && | |
a167ece0 | 23 | verbose expr "$actual" : " rewrite test ([0-9]*%)$" |
f8b6809d JH |
24 | |
25 | ' | |
26 | ||
467ddc14 JH |
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 | ||
35e2d03c AB |
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 | ||
f8b6809d JH |
96 | test_done |
97 |