3 test_description
='difference in submodules'
5 TEST_PASSES_SANITIZE_LEAK
=true
7 .
"$TEST_DIRECTORY"/lib-diff.sh
9 test_expect_success setup
'
11 test_create_repo sub &&
16 git commit -m submodule
22 git commit -m superproject &&
26 echo goodbye >world &&
28 git commit -m "submodule #2"
35 echo ":160000 160000 $3 $ZERO_OID M sub" >expect &&
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
45 test_expect_success
'git diff-index --raw HEAD' '
46 git diff-index --raw HEAD >actual.index &&
47 test_cmp expect actual.index
50 test_expect_success
'git diff-files --raw' '
51 git diff-files --raw >actual.files &&
52 test_cmp expect actual.files
56 printf "%sSubproject commit %s\n+Subproject commit %s\n" \
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
67 test_expect_success
'git diff HEAD with dirty submodule (work tree)' '
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
75 test_expect_success
'git diff HEAD with dirty submodule (index)' '
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
88 test_expect_success
'git diff HEAD with dirty submodule (untracked)' '
95 git diff HEAD >actual &&
96 sed -e "1,/^@@/d" actual >actual.body &&
97 expect_from_to >expect.body $subtip $subprev &&
98 test_cmp expect.body actual.body
101 test_expect_success
'git diff HEAD with dirty submodule (untracked) (none ignored)' '
102 test_config diff.ignoreSubmodules none &&
103 git diff HEAD >actual &&
104 sed -e "1,/^@@/d" actual >actual.body &&
105 expect_from_to >expect.body $subtip $subprev-dirty &&
106 test_cmp expect.body actual.body
109 test_expect_success
'git diff HEAD with dirty submodule (work tree, refs match)' '
110 git commit -m "x" sub &&
112 git diff HEAD >actual &&
113 sed -e "1,/^@@/d" actual >actual.body &&
114 expect_from_to >expect.body $subprev $subprev-dirty &&
115 test_cmp expect.body actual.body &&
116 git diff --ignore-submodules HEAD >actual2 &&
117 test_must_be_empty actual2 &&
118 git diff --ignore-submodules=untracked HEAD >actual3 &&
119 sed -e "1,/^@@/d" actual3 >actual3.body &&
120 expect_from_to >expect.body $subprev $subprev-dirty &&
121 test_cmp expect.body actual3.body &&
122 git diff --ignore-submodules=dirty HEAD >actual4 &&
123 test_must_be_empty actual4
126 test_expect_success
'git diff HEAD with dirty submodule (work tree, refs match) [.gitmodules]' '
127 git config diff.ignoreSubmodules dirty &&
128 git diff HEAD >actual &&
129 test_must_be_empty actual &&
130 git config --add -f .gitmodules submodule.subname.ignore none &&
131 git config --add -f .gitmodules submodule.subname.path sub &&
132 git diff HEAD >actual &&
133 sed -e "1,/^@@/d" actual >actual.body &&
134 expect_from_to >expect.body $subprev $subprev-dirty &&
135 test_cmp expect.body actual.body &&
136 git config -f .gitmodules submodule.subname.ignore all &&
137 git config -f .gitmodules submodule.subname.path sub &&
138 git diff HEAD >actual2 &&
139 test_must_be_empty actual2 &&
140 git config -f .gitmodules submodule.subname.ignore untracked &&
141 git diff HEAD >actual3 &&
142 sed -e "1,/^@@/d" actual3 >actual3.body &&
143 expect_from_to >expect.body $subprev $subprev-dirty &&
144 test_cmp expect.body actual3.body &&
145 git config -f .gitmodules submodule.subname.ignore dirty &&
146 git diff HEAD >actual4 &&
147 test_must_be_empty actual4 &&
148 git config submodule.subname.ignore none &&
149 git config submodule.subname.path sub &&
150 git diff HEAD >actual &&
151 sed -e "1,/^@@/d" actual >actual.body &&
152 expect_from_to >expect.body $subprev $subprev-dirty &&
153 test_cmp expect.body actual.body &&
154 git config --remove-section submodule.subname &&
155 git config --remove-section -f .gitmodules submodule.subname &&
156 git config --unset diff.ignoreSubmodules &&
160 test_expect_success
'git diff HEAD with dirty submodule (index, refs match)' '
167 git diff HEAD >actual &&
168 sed -e "1,/^@@/d" actual >actual.body &&
169 expect_from_to >expect.body $subprev $subprev-dirty &&
170 test_cmp expect.body actual.body
173 test_expect_success
'git diff HEAD with dirty submodule (untracked, refs match)' '
180 git diff --ignore-submodules=none HEAD >actual &&
181 sed -e "1,/^@@/d" actual >actual.body &&
182 expect_from_to >expect.body $subprev $subprev-dirty &&
183 test_cmp expect.body actual.body &&
184 git diff --ignore-submodules=all HEAD >actual2 &&
185 test_must_be_empty actual2 &&
186 git diff HEAD >actual3 &&
187 test_must_be_empty actual3 &&
188 git diff --ignore-submodules=dirty HEAD >actual4 &&
189 test_must_be_empty actual4
192 test_expect_success
'git diff HEAD with dirty submodule (untracked, refs match) [.gitmodules]' '
193 git config --add -f .gitmodules submodule.subname.ignore all &&
194 git config --add -f .gitmodules submodule.subname.path sub &&
195 git diff HEAD >actual2 &&
196 test_must_be_empty actual2 &&
197 git config -f .gitmodules submodule.subname.ignore untracked &&
198 git diff HEAD >actual3 &&
199 test_must_be_empty actual3 &&
200 git config -f .gitmodules submodule.subname.ignore dirty &&
201 git diff HEAD >actual4 &&
202 test_must_be_empty actual4 &&
203 git config submodule.subname.ignore none &&
204 git config submodule.subname.path sub &&
205 git diff HEAD >actual &&
206 sed -e "1,/^@@/d" actual >actual.body &&
207 expect_from_to >expect.body $subprev $subprev-dirty &&
208 test_cmp expect.body actual.body &&
209 git config --remove-section submodule.subname &&
210 git config --remove-section -f .gitmodules submodule.subname &&
214 test_expect_success
'git diff between submodule commits' '
215 git diff HEAD^..HEAD >actual &&
216 sed -e "1,/^@@/d" actual >actual.body &&
217 expect_from_to >expect.body $subtip $subprev &&
218 test_cmp expect.body actual.body &&
219 git diff --ignore-submodules=dirty HEAD^..HEAD >actual &&
220 sed -e "1,/^@@/d" actual >actual.body &&
221 expect_from_to >expect.body $subtip $subprev &&
222 test_cmp expect.body actual.body &&
223 git diff --ignore-submodules HEAD^..HEAD >actual &&
224 test_must_be_empty actual
227 test_expect_success
'git diff between submodule commits [.gitmodules]' '
228 git diff HEAD^..HEAD >actual &&
229 sed -e "1,/^@@/d" actual >actual.body &&
230 expect_from_to >expect.body $subtip $subprev &&
231 test_cmp expect.body actual.body &&
232 git config --add -f .gitmodules submodule.subname.ignore dirty &&
233 git config --add -f .gitmodules submodule.subname.path sub &&
234 git diff HEAD^..HEAD >actual &&
235 sed -e "1,/^@@/d" actual >actual.body &&
236 expect_from_to >expect.body $subtip $subprev &&
237 test_cmp expect.body actual.body &&
238 git config -f .gitmodules submodule.subname.ignore all &&
239 git diff HEAD^..HEAD >actual &&
240 test_must_be_empty actual &&
241 git config submodule.subname.ignore dirty &&
242 git config submodule.subname.path sub &&
243 git diff HEAD^..HEAD >actual &&
244 sed -e "1,/^@@/d" actual >actual.body &&
245 expect_from_to >expect.body $subtip $subprev &&
246 git config --remove-section submodule.subname &&
247 git config --remove-section -f .gitmodules submodule.subname &&
251 test_expect_success
'git diff (empty submodule dir)' '
252 rm -rf sub/* sub/.git &&
253 git diff > actual.empty &&
254 test_must_be_empty actual.empty
257 test_expect_success
'conflicted submodule setup' '
258 c=$(test_oid ff_1) &&
260 echo "000000 $ZERO_OID 0 sub" &&
261 echo "160000 1$c 1 sub" &&
262 echo "160000 2$c 2 sub" &&
263 echo "160000 3$c 3 sub"
264 ) | git update-index --index-info &&
265 echo >expect.nosub "diff --cc sub
266 index 2ffffff,3ffffff..0000000
269 @@@ -1,1 -1,1 +1,1 @@@
270 - Subproject commit 2$c
271 -Subproject commit 3$c
272 ++Subproject commit $ZERO_OID" &&
274 hh=$(git rev-parse HEAD) &&
275 sed -e "s/$ZERO_OID/$hh/" expect.nosub >expect.withsub
279 test_expect_success
'combined (empty submodule)' '
280 rm -fr sub && mkdir sub &&
282 test_cmp expect.nosub actual
285 test_expect_success
'combined (with submodule)' '
287 git clone --no-checkout . sub &&
289 test_cmp expect.withsub actual