Welcome to mirror list, hosted at ThFree Co, Russian Federation.

t4022-diff-rewrite.sh « t - git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6fed993ea0b34dddae94356354c889ada9f16497 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/bin/sh

test_description='rewrite diff'

. ./test-lib.sh
. "$TEST_DIRECTORY"/lib-diff-data.sh

test_expect_success setup '

	COPYING_test_data >test.data &&
	cp test.data test &&
	git add test &&
	tr \
	  "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" \
	  "nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM" \
	  <test.data >test &&
	echo "to be deleted" >test2 &&
	blob=$(git hash-object test2) &&
	blob=$(git rev-parse --short $blob) &&
	git add test2

'

test_expect_success 'detect rewrite' '

	actual=$(git diff-files -B --summary test) &&
	expr "$actual" : " rewrite test ([0-9]*%)$"

'

cat >expect <<EOF
diff --git a/test2 b/test2
deleted file mode 100644
index $blob..0000000
--- a/test2
+++ /dev/null
@@ -1 +0,0 @@
-to be deleted
EOF
test_expect_success 'show deletion diff without -D' '

	rm test2 &&
	git diff -- test2 >actual &&
	test_cmp expect actual
'

cat >expect <<EOF
diff --git a/test2 b/test2
deleted file mode 100644
index $blob..0000000
EOF
test_expect_success 'suppress deletion diff with -D' '

	git diff -D -- test2 >actual &&
	test_cmp expect actual
'

test_expect_success 'show deletion diff with -B' '

	git diff -B -- test >actual &&
	grep "Linus Torvalds" actual
'

test_expect_success 'suppress deletion diff with -B -D' '

	git diff -B -D -- test >actual &&
	grep -v "Linus Torvalds" actual
'

test_expect_success 'prepare a file that ends with an incomplete line' '
	test_seq 1 99 >seq &&
	printf 100 >>seq &&
	git add seq &&
	git commit seq -m seq
'

test_expect_success 'rewrite the middle 90% of sequence file and terminate with newline' '
	test_seq 1 5 >seq &&
	test_seq 9331 9420 >>seq &&
	test_seq 96 100 >>seq
'

test_expect_success 'confirm that sequence file is considered a rewrite' '
	git diff -B seq >res &&
	grep "dissimilarity index" res
'

test_expect_success 'no newline at eof is on its own line without -B' '
	git diff seq >res &&
	grep "^\\\\ " res &&
	! grep "^..*\\\\ " res
'

test_expect_success 'no newline at eof is on its own line with -B' '
	git diff -B seq >res &&
	grep "^\\\\ " res &&
	! grep "^..*\\\\ " res
'

test_done