]> git.ipfire.org Git - thirdparty/git.git/blame - t/t4027-diff-submodule.sh
upload-pack: move allow_unadvertised_object_request to upload_pack_data
[thirdparty/git.git] / t / t4027-diff-submodule.sh
CommitLineData
2b459b48
JH
1#!/bin/sh
2
3test_description='difference in submodules'
4
5. ./test-lib.sh
bfdbee98 6. "$TEST_DIRECTORY"/diff-lib.sh
2b459b48 7
2b459b48 8test_expect_success setup '
45e2ef2b 9 test_oid_init &&
2b459b48
JH
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 ) &&
8125a58b 35 echo ":160000 160000 $3 $ZERO_OID M sub" >expect &&
8e08b419 36 subtip=$3 subprev=$2
2b459b48
JH
37'
38
39test_expect_success 'git diff --raw HEAD' '
45e2ef2b 40 hexsz=$(test_oid hexsz) &&
41 git diff --raw --abbrev=$hexsz HEAD >actual &&
82ebb0b6 42 test_cmp expect actual
2b459b48
JH
43'
44
45test_expect_success 'git diff-index --raw HEAD' '
46 git diff-index --raw HEAD >actual.index &&
82ebb0b6 47 test_cmp expect actual.index
2b459b48
JH
48'
49
50test_expect_success 'git diff-files --raw' '
51 git diff-files --raw >actual.files &&
82ebb0b6 52 test_cmp expect actual.files
2b459b48
JH
53'
54
8e08b419
JH
55expect_from_to () {
56 printf "%sSubproject commit %s\n+Subproject commit %s\n" \
57 "-" "$1" "$2"
58}
59
60test_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
67test_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
75test_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
88test_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
101test_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 &&
dd44d419
JL
107 test_cmp expect.body actual.body &&
108 git diff --ignore-submodules HEAD >actual2 &&
ec10b018 109 test_must_be_empty actual2 &&
dd44d419
JL
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 &&
ec10b018 115 test_must_be_empty actual4
8e08b419 116'
6ed7ddaa 117
302ad7a9 118test_expect_success 'git diff HEAD with dirty submodule (work tree, refs match) [.gitmodules]' '
90e14525
JL
119 git config diff.ignoreSubmodules dirty &&
120 git diff HEAD >actual &&
ec10b018 121 test_must_be_empty actual &&
302ad7a9
JL
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 &&
ec10b018 131 test_must_be_empty actual2 &&
302ad7a9
JL
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 &&
ec10b018 139 test_must_be_empty actual4 &&
302ad7a9
JL
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 &&
90e14525 148 git config --unset diff.ignoreSubmodules &&
302ad7a9
JL
149 rm .gitmodules
150'
151
8e08b419
JH
152test_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
165test_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 &&
dd44d419
JL
175 test_cmp expect.body actual.body &&
176 git diff --ignore-submodules=all HEAD >actual2 &&
ec10b018 177 test_must_be_empty actual2 &&
dd44d419 178 git diff --ignore-submodules=untracked HEAD >actual3 &&
ec10b018 179 test_must_be_empty actual3 &&
dd44d419 180 git diff --ignore-submodules=dirty HEAD >actual4 &&
ec10b018 181 test_must_be_empty actual4
8e08b419
JH
182'
183
302ad7a9
JL
184test_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 &&
ec10b018 188 test_must_be_empty actual2 &&
302ad7a9
JL
189 git config -f .gitmodules submodule.subname.ignore untracked &&
190 git diff HEAD >actual3 &&
ec10b018 191 test_must_be_empty actual3 &&
302ad7a9
JL
192 git config -f .gitmodules submodule.subname.ignore dirty &&
193 git diff HEAD >actual4 &&
ec10b018 194 test_must_be_empty actual4 &&
302ad7a9
JL
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
aee9c7d6
JL
206test_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 &&
ec10b018 216 test_must_be_empty actual
aee9c7d6
JL
217'
218
302ad7a9
JL
219test_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 &&
ec10b018 232 test_must_be_empty actual &&
302ad7a9
JL
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
1392a377 243test_expect_success 'git diff (empty submodule dir)' '
7c08a2a6
PY
244 rm -rf sub/* sub/.git &&
245 git diff > actual.empty &&
1c5e94f4 246 test_must_be_empty actual.empty
7c08a2a6
PY
247'
248
7dae8b21 249test_expect_success 'conflicted submodule setup' '
45e2ef2b 250 c=$(test_oid ff_1) &&
7dae8b21 251 (
8125a58b 252 echo "000000 $ZERO_OID 0 sub" &&
a48fcd83
JN
253 echo "160000 1$c 1 sub" &&
254 echo "160000 2$c 2 sub" &&
7dae8b21
JH
255 echo "160000 3$c 3 sub"
256 ) | git update-index --index-info &&
45e2ef2b 257 echo >expect.nosub "diff --cc sub
7dae8b21
JH
258index 2ffffff,3ffffff..0000000
259--- a/sub
260+++ b/sub
261@@@ -1,1 -1,1 +1,1 @@@
45e2ef2b 262- Subproject commit 2$c
263 -Subproject commit 3$c
264++Subproject commit $ZERO_OID" &&
7dae8b21
JH
265
266 hh=$(git rev-parse HEAD) &&
8125a58b 267 sed -e "s/$ZERO_OID/$hh/" expect.nosub >expect.withsub
7dae8b21
JH
268
269'
270
271test_expect_success 'combined (empty submodule)' '
272 rm -fr sub && mkdir sub &&
273 git diff >actual &&
274 test_cmp expect.nosub actual
275'
276
277test_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
2b459b48 286test_done