summaryrefslogtreecommitdiffstats
path: root/t/t4074-diff-shifted-matched-group.sh
blob: d77fa3b79d2b5353843c92ee7e7bf5090626d018 (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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#!/bin/sh

test_description='shifted diff groups re-diffing during histogram diff'

. ./test-lib.sh

test_expect_success 'shifted/merged diff group should re-diff to minimize patch' '
	test_write_lines A x A A A x A A A >file1 &&
	test_write_lines A x A Z A x A A A >file2 &&

	file1_h=$(git rev-parse --short $(git hash-object file1)) &&
	file2_h=$(git rev-parse --short $(git hash-object file2)) &&

	cat >expect <<-EOF &&
	diff --git a/file1 b/file2
	index $file1_h..$file2_h 100644
	--- a/file1
	+++ b/file2
	@@ -1,7 +1,7 @@
	 A
	 x
	 A
	-A
	+Z
	 A
	 x
	 A
	EOF

	test_expect_code 1 git diff --no-index --histogram file1 file2 >output &&
	test_cmp expect output
'

test_expect_success 'merged diff group with no shift' '
	test_write_lines A Z B x >file1 &&
	test_write_lines C D x Z E x >file2 &&

	file1_h=$(git rev-parse --short $(git hash-object file1)) &&
	file2_h=$(git rev-parse --short $(git hash-object file2)) &&

	cat >expect <<-EOF &&
	diff --git a/file1 b/file2
	index $file1_h..$file2_h 100644
	--- a/file1
	+++ b/file2
	@@ -1,4 +1,6 @@
	-A
	+C
	+D
	+x
	 Z
	-B
	+E
	 x
	EOF

	test_expect_code 1 git diff --no-index --histogram file1 file2 >output &&
	test_cmp expect output
'

test_expect_success 're-diff should preserve diff flags' '
	test_write_lines a b c a b c >file1 &&
	test_write_lines x " b" z a b c >file2 &&

	file1_h=$(git rev-parse --short $(git hash-object file1)) &&
	file2_h=$(git rev-parse --short $(git hash-object file2)) &&

	cat >expect <<-EOF &&
	diff --git a/file1 b/file2
	index $file1_h..$file2_h 100644
	--- a/file1
	+++ b/file2
	@@ -1,6 +1,6 @@
	-a
	-b
	-c
	+x
	+ b
	+z
	 a
	 b
	 c
	EOF

	test_expect_code 1 git diff --no-index --histogram file1 file2 >output &&
	test_cmp expect output &&

	cat >expect_iwhite <<-EOF &&
	diff --git a/file1 b/file2
	index $file1_h..$file2_h 100644
	--- a/file1
	+++ b/file2
	@@ -1,6 +1,6 @@
	-a
	+x
	  b
	-c
	+z
	 a
	 b
	 c
	EOF

	test_expect_code 1 git diff --no-index --histogram --ignore-all-space file1 file2 >output_iwhite &&
	test_cmp expect_iwhite output_iwhite
'

test_expect_success 'shifting on either side should trigger re-diff properly' '
	test_write_lines a b c a b c a b c >file1 &&
	test_write_lines a b c a1 a2 a3 b c1 a b c >file2 &&

	file1_h=$(git rev-parse --short $(git hash-object file1)) &&
	file2_h=$(git rev-parse --short $(git hash-object file2)) &&

	cat >expect1 <<-EOF &&
	diff --git a/file1 b/file2
	index $file1_h..$file2_h 100644
	--- a/file1
	+++ b/file2
	@@ -1,9 +1,11 @@
	 a
	 b
	 c
	-a
	+a1
	+a2
	+a3
	 b
	-c
	+c1
	 a
	 b
	 c
	EOF

	test_expect_code 1 git diff --no-index --histogram file1 file2 >output1 &&
	test_cmp expect1 output1 &&

	cat >expect2 <<-EOF &&
	diff --git a/file2 b/file1
	index $file2_h..$file1_h 100644
	--- a/file2
	+++ b/file1
	@@ -1,11 +1,9 @@
	 a
	 b
	 c
	-a1
	-a2
	-a3
	+a
	 b
	-c1
	+c
	 a
	 b
	 c
	EOF

	test_expect_code 1 git diff --no-index --histogram file2 file1 >output2 &&
	test_cmp expect2 output2
'

test_done