blob: 6d1c3d949c78bc8fd5a82dbaee519163a8653e86 [file] [log] [blame]
Junio C Hamanof8b68092007-11-21 23:06:44 -08001#!/bin/sh
2
3test_description='rewrite diff'
4
5. ./test-lib.sh
6
7test_expect_success setup '
8
Junio C Hamanobfdbee92008-08-08 02:26:28 -07009 cat "$TEST_DIRECTORY"/../COPYING >test &&
Junio C Hamanof8b68092007-11-21 23:06:44 -080010 git add test &&
Jeff King40a7ce62008-03-12 17:29:57 -040011 tr \
12 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" \
13 "nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM" \
Junio C Hamano467ddc12011-02-28 16:11:55 -080014 <"$TEST_DIRECTORY"/../COPYING >test &&
15 echo "to be deleted" >test2 &&
brian m. carlson10c636a2018-05-21 02:01:38 +000016 blob=$(git hash-object test2) &&
17 blob=$(git rev-parse --short $blob) &&
Junio C Hamano467ddc12011-02-28 16:11:55 -080018 git add test2
Junio C Hamanof8b68092007-11-21 23:06:44 -080019
20'
21
22test_expect_success 'detect rewrite' '
23
24 actual=$(git diff-files -B --summary test) &&
Jeff Kinga167ece2015-03-20 06:09:00 -040025 verbose expr "$actual" : " rewrite test ([0-9]*%)$"
Junio C Hamanof8b68092007-11-21 23:06:44 -080026
27'
28
Junio C Hamano467ddc12011-02-28 16:11:55 -080029cat >expect <<EOF
30diff --git a/test2 b/test2
31deleted file mode 100644
brian m. carlson10c636a2018-05-21 02:01:38 +000032index $blob..0000000
Junio C Hamano467ddc12011-02-28 16:11:55 -080033--- a/test2
34+++ /dev/null
35@@ -1 +0,0 @@
36-to be deleted
37EOF
38test_expect_success 'show deletion diff without -D' '
39
40 rm test2 &&
41 git diff -- test2 >actual &&
42 test_cmp expect actual
43'
44
45cat >expect <<EOF
46diff --git a/test2 b/test2
47deleted file mode 100644
brian m. carlson10c636a2018-05-21 02:01:38 +000048index $blob..0000000
Junio C Hamano467ddc12011-02-28 16:11:55 -080049EOF
50test_expect_success 'suppress deletion diff with -D' '
51
52 git diff -D -- test2 >actual &&
53 test_cmp expect actual
54'
55
56test_expect_success 'show deletion diff with -B' '
57
58 git diff -B -- test >actual &&
59 grep "Linus Torvalds" actual
60'
61
62test_expect_success 'suppress deletion diff with -B -D' '
63
64 git diff -B -D -- test >actual &&
65 grep -v "Linus Torvalds" actual
66'
67
Adam Butcher35e2d032012-08-04 21:07:35 +000068test_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
75test_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
81test_expect_success 'confirm that sequence file is considered a rewrite' '
82 git diff -B seq >res &&
83 grep "dissimilarity index" res
84'
85
86test_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
92test_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
Junio C Hamanof8b68092007-11-21 23:06:44 -080098test_done
99