3 test_description='difference in submodules'
6 . "$TEST_DIRECTORY"/diff-lib.sh
8 test_expect_success setup '
10 test_create_repo sub &&
15 git commit -m submodule
21 git commit -m superproject &&
25 echo goodbye >world &&
27 git commit -m "submodule #2"
34 echo ":160000 160000 $3 $ZERO_OID M sub" >expect &&
38 test_expect_success 'git diff --raw HEAD' '
39 hexsz=$(test_oid hexsz) &&
40 git diff --raw --abbrev=$hexsz HEAD >actual &&
41 test_cmp expect actual
44 test_expect_success 'git diff-index --raw HEAD' '
45 git diff-index --raw HEAD >actual.index &&
46 test_cmp expect actual.index
49 test_expect_success 'git diff-files --raw' '
50 git diff-files --raw >actual.files &&
51 test_cmp expect actual.files
55 printf "%sSubproject commit %s\n+Subproject commit %s\n" \
59 test_expect_success 'git diff HEAD' '
60 git diff HEAD >actual &&
61 sed -e "1,/^@@/d" actual >actual.body &&
62 expect_from_to >expect.body $subtip $subprev &&
63 test_cmp expect.body actual.body
66 test_expect_success 'git diff HEAD with dirty submodule (work tree)' '
68 git diff HEAD >actual &&
69 sed -e "1,/^@@/d" actual >actual.body &&
70 expect_from_to >expect.body $subtip $subprev-dirty &&
71 test_cmp expect.body actual.body
74 test_expect_success 'git diff HEAD with dirty submodule (index)' '
81 git diff HEAD >actual &&
82 sed -e "1,/^@@/d" actual >actual.body &&
83 expect_from_to >expect.body $subtip $subprev-dirty &&
84 test_cmp expect.body actual.body
87 test_expect_success 'git diff HEAD with dirty submodule (untracked)' '
94 git diff HEAD >actual &&
95 sed -e "1,/^@@/d" actual >actual.body &&
96 expect_from_to >expect.body $subtip $subprev &&
97 test_cmp expect.body actual.body
100 test_expect_success 'git diff HEAD with dirty submodule (untracked) (none ignored)' '
101 test_config diff.ignoreSubmodules none &&
102 git diff HEAD >actual &&
103 sed -e "1,/^@@/d" actual >actual.body &&
104 expect_from_to >expect.body $subtip $subprev-dirty &&
105 test_cmp expect.body actual.body
108 test_expect_success 'git diff HEAD with dirty submodule (work tree, refs match)' '
109 git commit -m "x" sub &&
111 git diff HEAD >actual &&
112 sed -e "1,/^@@/d" actual >actual.body &&
113 expect_from_to >expect.body $subprev $subprev-dirty &&
114 test_cmp expect.body actual.body &&
115 git diff --ignore-submodules HEAD >actual2 &&
116 test_must_be_empty actual2 &&
117 git diff --ignore-submodules=untracked HEAD >actual3 &&
118 sed -e "1,/^@@/d" actual3 >actual3.body &&
119 expect_from_to >expect.body $subprev $subprev-dirty &&
120 test_cmp expect.body actual3.body &&
121 git diff --ignore-submodules=dirty HEAD >actual4 &&
122 test_must_be_empty actual4
125 test_expect_success 'git diff HEAD with dirty submodule (work tree, refs match) [.gitmodules]' '
126 git config diff.ignoreSubmodules dirty &&
127 git diff HEAD >actual &&
128 test_must_be_empty actual &&
129 git config --add -f .gitmodules submodule.subname.ignore none &&
130 git config --add -f .gitmodules submodule.subname.path sub &&
131 git diff HEAD >actual &&
132 sed -e "1,/^@@/d" actual >actual.body &&
133 expect_from_to >expect.body $subprev $subprev-dirty &&
134 test_cmp expect.body actual.body &&
135 git config -f .gitmodules submodule.subname.ignore all &&
136 git config -f .gitmodules submodule.subname.path sub &&
137 git diff HEAD >actual2 &&
138 test_must_be_empty actual2 &&
139 git config -f .gitmodules submodule.subname.ignore untracked &&
140 git diff HEAD >actual3 &&
141 sed -e "1,/^@@/d" actual3 >actual3.body &&
142 expect_from_to >expect.body $subprev $subprev-dirty &&
143 test_cmp expect.body actual3.body &&
144 git config -f .gitmodules submodule.subname.ignore dirty &&
145 git diff HEAD >actual4 &&
146 test_must_be_empty actual4 &&
147 git config submodule.subname.ignore none &&
148 git config submodule.subname.path sub &&
149 git diff HEAD >actual &&
150 sed -e "1,/^@@/d" actual >actual.body &&
151 expect_from_to >expect.body $subprev $subprev-dirty &&
152 test_cmp expect.body actual.body &&
153 git config --remove-section submodule.subname &&
154 git config --remove-section -f .gitmodules submodule.subname &&
155 git config --unset diff.ignoreSubmodules &&
159 test_expect_success 'git diff HEAD with dirty submodule (index, refs match)' '
166 git diff HEAD >actual &&
167 sed -e "1,/^@@/d" actual >actual.body &&
168 expect_from_to >expect.body $subprev $subprev-dirty &&
169 test_cmp expect.body actual.body
172 test_expect_success 'git diff HEAD with dirty submodule (untracked, refs match)' '
179 git diff --ignore-submodules=none HEAD >actual &&
180 sed -e "1,/^@@/d" actual >actual.body &&
181 expect_from_to >expect.body $subprev $subprev-dirty &&
182 test_cmp expect.body actual.body &&
183 git diff --ignore-submodules=all HEAD >actual2 &&
184 test_must_be_empty actual2 &&
185 git diff HEAD >actual3 &&
186 test_must_be_empty actual3 &&
187 git diff --ignore-submodules=dirty HEAD >actual4 &&
188 test_must_be_empty actual4
191 test_expect_success 'git diff HEAD with dirty submodule (untracked, refs match) [.gitmodules]' '
192 git config --add -f .gitmodules submodule.subname.ignore all &&
193 git config --add -f .gitmodules submodule.subname.path sub &&
194 git diff HEAD >actual2 &&
195 test_must_be_empty actual2 &&
196 git config -f .gitmodules submodule.subname.ignore untracked &&
197 git diff HEAD >actual3 &&
198 test_must_be_empty actual3 &&
199 git config -f .gitmodules submodule.subname.ignore dirty &&
200 git diff HEAD >actual4 &&
201 test_must_be_empty actual4 &&
202 git config submodule.subname.ignore none &&
203 git config submodule.subname.path sub &&
204 git diff HEAD >actual &&
205 sed -e "1,/^@@/d" actual >actual.body &&
206 expect_from_to >expect.body $subprev $subprev-dirty &&
207 test_cmp expect.body actual.body &&
208 git config --remove-section submodule.subname &&
209 git config --remove-section -f .gitmodules submodule.subname &&
213 test_expect_success 'git diff between submodule commits' '
214 git diff HEAD^..HEAD >actual &&
215 sed -e "1,/^@@/d" actual >actual.body &&
216 expect_from_to >expect.body $subtip $subprev &&
217 test_cmp expect.body actual.body &&
218 git diff --ignore-submodules=dirty 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 diff --ignore-submodules HEAD^..HEAD >actual &&
223 test_must_be_empty actual
226 test_expect_success 'git diff between submodule commits [.gitmodules]' '
227 git diff HEAD^..HEAD >actual &&
228 sed -e "1,/^@@/d" actual >actual.body &&
229 expect_from_to >expect.body $subtip $subprev &&
230 test_cmp expect.body actual.body &&
231 git config --add -f .gitmodules submodule.subname.ignore dirty &&
232 git config --add -f .gitmodules 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 test_cmp expect.body actual.body &&
237 git config -f .gitmodules submodule.subname.ignore all &&
238 git diff HEAD^..HEAD >actual &&
239 test_must_be_empty actual &&
240 git config submodule.subname.ignore dirty &&
241 git config submodule.subname.path sub &&
242 git diff HEAD^..HEAD >actual &&
243 sed -e "1,/^@@/d" actual >actual.body &&
244 expect_from_to >expect.body $subtip $subprev &&
245 git config --remove-section submodule.subname &&
246 git config --remove-section -f .gitmodules submodule.subname &&
250 test_expect_success 'git diff (empty submodule dir)' '
251 rm -rf sub/* sub/.git &&
252 git diff > actual.empty &&
253 test_must_be_empty actual.empty
256 test_expect_success 'conflicted submodule setup' '
257 c=$(test_oid ff_1) &&
259 echo "000000 $ZERO_OID 0 sub" &&
260 echo "160000 1$c 1 sub" &&
261 echo "160000 2$c 2 sub" &&
262 echo "160000 3$c 3 sub"
263 ) | git update-index --index-info &&
264 echo >expect.nosub "diff --cc sub
265 index 2ffffff,3ffffff..0000000
268 @@@ -1,1 -1,1 +1,1 @@@
269 - Subproject commit 2$c
270 -Subproject commit 3$c
271 ++Subproject commit $ZERO_OID" &&
273 hh=$(git rev-parse HEAD) &&
274 sed -e "s/$ZERO_OID/$hh/" expect.nosub >expect.withsub
278 test_expect_success 'combined (empty submodule)' '
279 rm -fr sub && mkdir sub &&
281 test_cmp expect.nosub actual
284 test_expect_success 'combined (with submodule)' '
286 git clone --no-checkout . sub &&
288 test_cmp expect.withsub actual