built-in add -i: accept open-ended ranges again
[git/debian.git] / t / t4022-diff-rewrite.sh
blob6d1c3d949c78bc8fd5a82dbaee519163a8653e86
1 #!/bin/sh
3 test_description='rewrite diff'
5 . ./test-lib.sh
7 test_expect_success setup '
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 blob=$(git hash-object test2) &&
17 blob=$(git rev-parse --short $blob) &&
18 git add test2
22 test_expect_success 'detect rewrite' '
24 actual=$(git diff-files -B --summary test) &&
25 verbose expr "$actual" : " rewrite test ([0-9]*%)$"
29 cat >expect <<EOF
30 diff --git a/test2 b/test2
31 deleted file mode 100644
32 index $blob..0000000
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' '
40 rm test2 &&
41 git diff -- test2 >actual &&
42 test_cmp expect actual
45 cat >expect <<EOF
46 diff --git a/test2 b/test2
47 deleted file mode 100644
48 index $blob..0000000
49 EOF
50 test_expect_success 'suppress deletion diff with -D' '
52 git diff -D -- test2 >actual &&
53 test_cmp expect actual
56 test_expect_success 'show deletion diff with -B' '
58 git diff -B -- test >actual &&
59 grep "Linus Torvalds" actual
62 test_expect_success 'suppress deletion diff with -B -D' '
64 git diff -B -D -- test >actual &&
65 grep -v "Linus Torvalds" actual
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
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
81 test_expect_success 'confirm that sequence file is considered a rewrite' '
82 git diff -B seq >res &&
83 grep "dissimilarity index" res
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
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
98 test_done