]> git.ipfire.org Git - thirdparty/git.git/blame - t/t4027-diff-submodule.sh
Merge branch 'wb/fsmonitor-bitmap-fix'
[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
JH
8test_expect_success setup '
9 test_tick &&
10 test_create_repo sub &&
11 (
12 cd sub &&
13 echo hello >world &&
14 git add world &&
15 git commit -m submodule
16 ) &&
17
18 test_tick &&
19 echo frotz >nitfol &&
20 git add nitfol sub &&
21 git commit -m superproject &&
22
23 (
24 cd sub &&
25 echo goodbye >world &&
26 git add world &&
27 git commit -m "submodule #2"
28 ) &&
29
30 set x $(
31 cd sub &&
32 git rev-list HEAD
33 ) &&
8125a58b 34 echo ":160000 160000 $3 $ZERO_OID M sub" >expect &&
8e08b419 35 subtip=$3 subprev=$2
2b459b48
JH
36'
37
38test_expect_success 'git diff --raw HEAD' '
39 git diff --raw --abbrev=40 HEAD >actual &&
82ebb0b6 40 test_cmp expect actual
2b459b48
JH
41'
42
43test_expect_success 'git diff-index --raw HEAD' '
44 git diff-index --raw HEAD >actual.index &&
82ebb0b6 45 test_cmp expect actual.index
2b459b48
JH
46'
47
48test_expect_success 'git diff-files --raw' '
49 git diff-files --raw >actual.files &&
82ebb0b6 50 test_cmp expect actual.files
2b459b48
JH
51'
52
8e08b419
JH
53expect_from_to () {
54 printf "%sSubproject commit %s\n+Subproject commit %s\n" \
55 "-" "$1" "$2"
56}
57
58test_expect_success 'git diff HEAD' '
59 git diff HEAD >actual &&
60 sed -e "1,/^@@/d" actual >actual.body &&
61 expect_from_to >expect.body $subtip $subprev &&
62 test_cmp expect.body actual.body
63'
64
65test_expect_success 'git diff HEAD with dirty submodule (work tree)' '
66 echo >>sub/world &&
67 git diff HEAD >actual &&
68 sed -e "1,/^@@/d" actual >actual.body &&
69 expect_from_to >expect.body $subtip $subprev-dirty &&
70 test_cmp expect.body actual.body
71'
72
73test_expect_success 'git diff HEAD with dirty submodule (index)' '
74 (
75 cd sub &&
76 git reset --hard &&
77 echo >>world &&
78 git add world
79 ) &&
80 git diff HEAD >actual &&
81 sed -e "1,/^@@/d" actual >actual.body &&
82 expect_from_to >expect.body $subtip $subprev-dirty &&
83 test_cmp expect.body actual.body
84'
85
86test_expect_success 'git diff HEAD with dirty submodule (untracked)' '
87 (
88 cd sub &&
89 git reset --hard &&
90 git clean -qfdx &&
91 >cruft
92 ) &&
93 git diff HEAD >actual &&
94 sed -e "1,/^@@/d" actual >actual.body &&
95 expect_from_to >expect.body $subtip $subprev-dirty &&
96 test_cmp expect.body actual.body
97'
98
99test_expect_success 'git diff HEAD with dirty submodule (work tree, refs match)' '
100 git commit -m "x" sub &&
101 echo >>sub/world &&
102 git diff HEAD >actual &&
103 sed -e "1,/^@@/d" actual >actual.body &&
104 expect_from_to >expect.body $subprev $subprev-dirty &&
dd44d419
JL
105 test_cmp expect.body actual.body &&
106 git diff --ignore-submodules HEAD >actual2 &&
ec10b018 107 test_must_be_empty actual2 &&
dd44d419
JL
108 git diff --ignore-submodules=untracked HEAD >actual3 &&
109 sed -e "1,/^@@/d" actual3 >actual3.body &&
110 expect_from_to >expect.body $subprev $subprev-dirty &&
111 test_cmp expect.body actual3.body &&
112 git diff --ignore-submodules=dirty HEAD >actual4 &&
ec10b018 113 test_must_be_empty actual4
8e08b419 114'
6ed7ddaa 115
302ad7a9 116test_expect_success 'git diff HEAD with dirty submodule (work tree, refs match) [.gitmodules]' '
90e14525
JL
117 git config diff.ignoreSubmodules dirty &&
118 git diff HEAD >actual &&
ec10b018 119 test_must_be_empty actual &&
302ad7a9
JL
120 git config --add -f .gitmodules submodule.subname.ignore none &&
121 git config --add -f .gitmodules submodule.subname.path sub &&
122 git diff HEAD >actual &&
123 sed -e "1,/^@@/d" actual >actual.body &&
124 expect_from_to >expect.body $subprev $subprev-dirty &&
125 test_cmp expect.body actual.body &&
126 git config -f .gitmodules submodule.subname.ignore all &&
127 git config -f .gitmodules submodule.subname.path sub &&
128 git diff HEAD >actual2 &&
ec10b018 129 test_must_be_empty actual2 &&
302ad7a9
JL
130 git config -f .gitmodules submodule.subname.ignore untracked &&
131 git diff HEAD >actual3 &&
132 sed -e "1,/^@@/d" actual3 >actual3.body &&
133 expect_from_to >expect.body $subprev $subprev-dirty &&
134 test_cmp expect.body actual3.body &&
135 git config -f .gitmodules submodule.subname.ignore dirty &&
136 git diff HEAD >actual4 &&
ec10b018 137 test_must_be_empty actual4 &&
302ad7a9
JL
138 git config submodule.subname.ignore none &&
139 git config submodule.subname.path sub &&
140 git diff HEAD >actual &&
141 sed -e "1,/^@@/d" actual >actual.body &&
142 expect_from_to >expect.body $subprev $subprev-dirty &&
143 test_cmp expect.body actual.body &&
144 git config --remove-section submodule.subname &&
145 git config --remove-section -f .gitmodules submodule.subname &&
90e14525 146 git config --unset diff.ignoreSubmodules &&
302ad7a9
JL
147 rm .gitmodules
148'
149
8e08b419
JH
150test_expect_success 'git diff HEAD with dirty submodule (index, refs match)' '
151 (
152 cd sub &&
153 git reset --hard &&
154 echo >>world &&
155 git add world
156 ) &&
157 git diff HEAD >actual &&
158 sed -e "1,/^@@/d" actual >actual.body &&
159 expect_from_to >expect.body $subprev $subprev-dirty &&
160 test_cmp expect.body actual.body
161'
162
163test_expect_success 'git diff HEAD with dirty submodule (untracked, refs match)' '
164 (
165 cd sub &&
166 git reset --hard &&
167 git clean -qfdx &&
168 >cruft
169 ) &&
170 git diff HEAD >actual &&
171 sed -e "1,/^@@/d" actual >actual.body &&
172 expect_from_to >expect.body $subprev $subprev-dirty &&
dd44d419
JL
173 test_cmp expect.body actual.body &&
174 git diff --ignore-submodules=all HEAD >actual2 &&
ec10b018 175 test_must_be_empty actual2 &&
dd44d419 176 git diff --ignore-submodules=untracked HEAD >actual3 &&
ec10b018 177 test_must_be_empty actual3 &&
dd44d419 178 git diff --ignore-submodules=dirty HEAD >actual4 &&
ec10b018 179 test_must_be_empty actual4
8e08b419
JH
180'
181
302ad7a9
JL
182test_expect_success 'git diff HEAD with dirty submodule (untracked, refs match) [.gitmodules]' '
183 git config --add -f .gitmodules submodule.subname.ignore all &&
184 git config --add -f .gitmodules submodule.subname.path sub &&
185 git diff HEAD >actual2 &&
ec10b018 186 test_must_be_empty actual2 &&
302ad7a9
JL
187 git config -f .gitmodules submodule.subname.ignore untracked &&
188 git diff HEAD >actual3 &&
ec10b018 189 test_must_be_empty actual3 &&
302ad7a9
JL
190 git config -f .gitmodules submodule.subname.ignore dirty &&
191 git diff HEAD >actual4 &&
ec10b018 192 test_must_be_empty actual4 &&
302ad7a9
JL
193 git config submodule.subname.ignore none &&
194 git config submodule.subname.path sub &&
195 git diff HEAD >actual &&
196 sed -e "1,/^@@/d" actual >actual.body &&
197 expect_from_to >expect.body $subprev $subprev-dirty &&
198 test_cmp expect.body actual.body &&
199 git config --remove-section submodule.subname &&
200 git config --remove-section -f .gitmodules submodule.subname &&
201 rm .gitmodules
202'
203
aee9c7d6
JL
204test_expect_success 'git diff between submodule commits' '
205 git diff HEAD^..HEAD >actual &&
206 sed -e "1,/^@@/d" actual >actual.body &&
207 expect_from_to >expect.body $subtip $subprev &&
208 test_cmp expect.body actual.body &&
209 git diff --ignore-submodules=dirty HEAD^..HEAD >actual &&
210 sed -e "1,/^@@/d" actual >actual.body &&
211 expect_from_to >expect.body $subtip $subprev &&
212 test_cmp expect.body actual.body &&
213 git diff --ignore-submodules HEAD^..HEAD >actual &&
ec10b018 214 test_must_be_empty actual
aee9c7d6
JL
215'
216
302ad7a9
JL
217test_expect_success 'git diff between submodule commits [.gitmodules]' '
218 git diff HEAD^..HEAD >actual &&
219 sed -e "1,/^@@/d" actual >actual.body &&
220 expect_from_to >expect.body $subtip $subprev &&
221 test_cmp expect.body actual.body &&
222 git config --add -f .gitmodules submodule.subname.ignore dirty &&
223 git config --add -f .gitmodules submodule.subname.path sub &&
224 git diff HEAD^..HEAD >actual &&
225 sed -e "1,/^@@/d" actual >actual.body &&
226 expect_from_to >expect.body $subtip $subprev &&
227 test_cmp expect.body actual.body &&
228 git config -f .gitmodules submodule.subname.ignore all &&
229 git diff HEAD^..HEAD >actual &&
ec10b018 230 test_must_be_empty actual &&
302ad7a9
JL
231 git config submodule.subname.ignore dirty &&
232 git config submodule.subname.path sub &&
233 git diff HEAD^..HEAD >actual &&
234 sed -e "1,/^@@/d" actual >actual.body &&
235 expect_from_to >expect.body $subtip $subprev &&
236 git config --remove-section submodule.subname &&
237 git config --remove-section -f .gitmodules submodule.subname &&
238 rm .gitmodules
239'
240
1392a377 241test_expect_success 'git diff (empty submodule dir)' '
7c08a2a6
PY
242 rm -rf sub/* sub/.git &&
243 git diff > actual.empty &&
1c5e94f4 244 test_must_be_empty actual.empty
7c08a2a6
PY
245'
246
7dae8b21
JH
247test_expect_success 'conflicted submodule setup' '
248
249 # 39 efs
a48fcd83 250 c=fffffffffffffffffffffffffffffffffffffff &&
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 &&
257 echo >expect.nosub '\''diff --cc sub
258index 2ffffff,3ffffff..0000000
259--- a/sub
260+++ b/sub
261@@@ -1,1 -1,1 +1,1 @@@
262- Subproject commit 2fffffffffffffffffffffffffffffffffffffff
263 -Subproject commit 3fffffffffffffffffffffffffffffffffffffff
264++Subproject commit 0000000000000000000000000000000000000000'\'' &&
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