]> git.ipfire.org Git - thirdparty/git.git/blob - t/t4027-diff-submodule.sh
The sixth batch
[thirdparty/git.git] / t / t4027-diff-submodule.sh
1 #!/bin/sh
2
3 test_description='difference in submodules'
4
5 . ./test-lib.sh
6 . "$TEST_DIRECTORY"/diff-lib.sh
7
8 test_expect_success setup '
9 test_oid_init &&
10 test_tick &&
11 test_create_repo sub &&
12 (
13 cd sub &&
14 echo hello >world &&
15 git add world &&
16 git commit -m submodule
17 ) &&
18
19 test_tick &&
20 echo frotz >nitfol &&
21 git add nitfol sub &&
22 git commit -m superproject &&
23
24 (
25 cd sub &&
26 echo goodbye >world &&
27 git add world &&
28 git commit -m "submodule #2"
29 ) &&
30
31 set x $(
32 cd sub &&
33 git rev-list HEAD
34 ) &&
35 echo ":160000 160000 $3 $ZERO_OID M sub" >expect &&
36 subtip=$3 subprev=$2
37 '
38
39 test_expect_success 'git diff --raw HEAD' '
40 hexsz=$(test_oid hexsz) &&
41 git diff --raw --abbrev=$hexsz HEAD >actual &&
42 test_cmp expect actual
43 '
44
45 test_expect_success 'git diff-index --raw HEAD' '
46 git diff-index --raw HEAD >actual.index &&
47 test_cmp expect actual.index
48 '
49
50 test_expect_success 'git diff-files --raw' '
51 git diff-files --raw >actual.files &&
52 test_cmp expect actual.files
53 '
54
55 expect_from_to () {
56 printf "%sSubproject commit %s\n+Subproject commit %s\n" \
57 "-" "$1" "$2"
58 }
59
60 test_expect_success 'git diff HEAD' '
61 git diff HEAD >actual &&
62 sed -e "1,/^@@/d" actual >actual.body &&
63 expect_from_to >expect.body $subtip $subprev &&
64 test_cmp expect.body actual.body
65 '
66
67 test_expect_success 'git diff HEAD with dirty submodule (work tree)' '
68 echo >>sub/world &&
69 git diff HEAD >actual &&
70 sed -e "1,/^@@/d" actual >actual.body &&
71 expect_from_to >expect.body $subtip $subprev-dirty &&
72 test_cmp expect.body actual.body
73 '
74
75 test_expect_success 'git diff HEAD with dirty submodule (index)' '
76 (
77 cd sub &&
78 git reset --hard &&
79 echo >>world &&
80 git add world
81 ) &&
82 git diff HEAD >actual &&
83 sed -e "1,/^@@/d" actual >actual.body &&
84 expect_from_to >expect.body $subtip $subprev-dirty &&
85 test_cmp expect.body actual.body
86 '
87
88 test_expect_success 'git diff HEAD with dirty submodule (untracked)' '
89 (
90 cd sub &&
91 git reset --hard &&
92 git clean -qfdx &&
93 >cruft
94 ) &&
95 git diff HEAD >actual &&
96 sed -e "1,/^@@/d" actual >actual.body &&
97 expect_from_to >expect.body $subtip $subprev-dirty &&
98 test_cmp expect.body actual.body
99 '
100
101 test_expect_success 'git diff HEAD with dirty submodule (work tree, refs match)' '
102 git commit -m "x" sub &&
103 echo >>sub/world &&
104 git diff HEAD >actual &&
105 sed -e "1,/^@@/d" actual >actual.body &&
106 expect_from_to >expect.body $subprev $subprev-dirty &&
107 test_cmp expect.body actual.body &&
108 git diff --ignore-submodules HEAD >actual2 &&
109 test_must_be_empty actual2 &&
110 git diff --ignore-submodules=untracked HEAD >actual3 &&
111 sed -e "1,/^@@/d" actual3 >actual3.body &&
112 expect_from_to >expect.body $subprev $subprev-dirty &&
113 test_cmp expect.body actual3.body &&
114 git diff --ignore-submodules=dirty HEAD >actual4 &&
115 test_must_be_empty actual4
116 '
117
118 test_expect_success 'git diff HEAD with dirty submodule (work tree, refs match) [.gitmodules]' '
119 git config diff.ignoreSubmodules dirty &&
120 git diff HEAD >actual &&
121 test_must_be_empty actual &&
122 git config --add -f .gitmodules submodule.subname.ignore none &&
123 git config --add -f .gitmodules submodule.subname.path sub &&
124 git diff HEAD >actual &&
125 sed -e "1,/^@@/d" actual >actual.body &&
126 expect_from_to >expect.body $subprev $subprev-dirty &&
127 test_cmp expect.body actual.body &&
128 git config -f .gitmodules submodule.subname.ignore all &&
129 git config -f .gitmodules submodule.subname.path sub &&
130 git diff HEAD >actual2 &&
131 test_must_be_empty actual2 &&
132 git config -f .gitmodules submodule.subname.ignore untracked &&
133 git diff HEAD >actual3 &&
134 sed -e "1,/^@@/d" actual3 >actual3.body &&
135 expect_from_to >expect.body $subprev $subprev-dirty &&
136 test_cmp expect.body actual3.body &&
137 git config -f .gitmodules submodule.subname.ignore dirty &&
138 git diff HEAD >actual4 &&
139 test_must_be_empty actual4 &&
140 git config submodule.subname.ignore none &&
141 git config submodule.subname.path sub &&
142 git diff HEAD >actual &&
143 sed -e "1,/^@@/d" actual >actual.body &&
144 expect_from_to >expect.body $subprev $subprev-dirty &&
145 test_cmp expect.body actual.body &&
146 git config --remove-section submodule.subname &&
147 git config --remove-section -f .gitmodules submodule.subname &&
148 git config --unset diff.ignoreSubmodules &&
149 rm .gitmodules
150 '
151
152 test_expect_success 'git diff HEAD with dirty submodule (index, refs match)' '
153 (
154 cd sub &&
155 git reset --hard &&
156 echo >>world &&
157 git add world
158 ) &&
159 git diff HEAD >actual &&
160 sed -e "1,/^@@/d" actual >actual.body &&
161 expect_from_to >expect.body $subprev $subprev-dirty &&
162 test_cmp expect.body actual.body
163 '
164
165 test_expect_success 'git diff HEAD with dirty submodule (untracked, refs match)' '
166 (
167 cd sub &&
168 git reset --hard &&
169 git clean -qfdx &&
170 >cruft
171 ) &&
172 git diff HEAD >actual &&
173 sed -e "1,/^@@/d" actual >actual.body &&
174 expect_from_to >expect.body $subprev $subprev-dirty &&
175 test_cmp expect.body actual.body &&
176 git diff --ignore-submodules=all HEAD >actual2 &&
177 test_must_be_empty actual2 &&
178 git diff --ignore-submodules=untracked HEAD >actual3 &&
179 test_must_be_empty actual3 &&
180 git diff --ignore-submodules=dirty HEAD >actual4 &&
181 test_must_be_empty actual4
182 '
183
184 test_expect_success 'git diff HEAD with dirty submodule (untracked, refs match) [.gitmodules]' '
185 git config --add -f .gitmodules submodule.subname.ignore all &&
186 git config --add -f .gitmodules submodule.subname.path sub &&
187 git diff HEAD >actual2 &&
188 test_must_be_empty actual2 &&
189 git config -f .gitmodules submodule.subname.ignore untracked &&
190 git diff HEAD >actual3 &&
191 test_must_be_empty actual3 &&
192 git config -f .gitmodules submodule.subname.ignore dirty &&
193 git diff HEAD >actual4 &&
194 test_must_be_empty actual4 &&
195 git config submodule.subname.ignore none &&
196 git config submodule.subname.path sub &&
197 git diff HEAD >actual &&
198 sed -e "1,/^@@/d" actual >actual.body &&
199 expect_from_to >expect.body $subprev $subprev-dirty &&
200 test_cmp expect.body actual.body &&
201 git config --remove-section submodule.subname &&
202 git config --remove-section -f .gitmodules submodule.subname &&
203 rm .gitmodules
204 '
205
206 test_expect_success 'git diff between submodule commits' '
207 git diff HEAD^..HEAD >actual &&
208 sed -e "1,/^@@/d" actual >actual.body &&
209 expect_from_to >expect.body $subtip $subprev &&
210 test_cmp expect.body actual.body &&
211 git diff --ignore-submodules=dirty HEAD^..HEAD >actual &&
212 sed -e "1,/^@@/d" actual >actual.body &&
213 expect_from_to >expect.body $subtip $subprev &&
214 test_cmp expect.body actual.body &&
215 git diff --ignore-submodules HEAD^..HEAD >actual &&
216 test_must_be_empty actual
217 '
218
219 test_expect_success 'git diff between submodule commits [.gitmodules]' '
220 git diff HEAD^..HEAD >actual &&
221 sed -e "1,/^@@/d" actual >actual.body &&
222 expect_from_to >expect.body $subtip $subprev &&
223 test_cmp expect.body actual.body &&
224 git config --add -f .gitmodules submodule.subname.ignore dirty &&
225 git config --add -f .gitmodules submodule.subname.path sub &&
226 git diff HEAD^..HEAD >actual &&
227 sed -e "1,/^@@/d" actual >actual.body &&
228 expect_from_to >expect.body $subtip $subprev &&
229 test_cmp expect.body actual.body &&
230 git config -f .gitmodules submodule.subname.ignore all &&
231 git diff HEAD^..HEAD >actual &&
232 test_must_be_empty actual &&
233 git config submodule.subname.ignore dirty &&
234 git config submodule.subname.path sub &&
235 git diff HEAD^..HEAD >actual &&
236 sed -e "1,/^@@/d" actual >actual.body &&
237 expect_from_to >expect.body $subtip $subprev &&
238 git config --remove-section submodule.subname &&
239 git config --remove-section -f .gitmodules submodule.subname &&
240 rm .gitmodules
241 '
242
243 test_expect_success 'git diff (empty submodule dir)' '
244 rm -rf sub/* sub/.git &&
245 git diff > actual.empty &&
246 test_must_be_empty actual.empty
247 '
248
249 test_expect_success 'conflicted submodule setup' '
250 c=$(test_oid ff_1) &&
251 (
252 echo "000000 $ZERO_OID 0 sub" &&
253 echo "160000 1$c 1 sub" &&
254 echo "160000 2$c 2 sub" &&
255 echo "160000 3$c 3 sub"
256 ) | git update-index --index-info &&
257 echo >expect.nosub "diff --cc sub
258 index 2ffffff,3ffffff..0000000
259 --- a/sub
260 +++ b/sub
261 @@@ -1,1 -1,1 +1,1 @@@
262 - Subproject commit 2$c
263 -Subproject commit 3$c
264 ++Subproject commit $ZERO_OID" &&
265
266 hh=$(git rev-parse HEAD) &&
267 sed -e "s/$ZERO_OID/$hh/" expect.nosub >expect.withsub
268
269 '
270
271 test_expect_success 'combined (empty submodule)' '
272 rm -fr sub && mkdir sub &&
273 git diff >actual &&
274 test_cmp expect.nosub actual
275 '
276
277 test_expect_success 'combined (with submodule)' '
278 rm -fr sub &&
279 git clone --no-checkout . sub &&
280 git diff >actual &&
281 test_cmp expect.withsub actual
282 '
283
284
285
286 test_done