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