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 git diff --raw --abbrev=40 HEAD >actual &&
40 test_cmp expect actual
43 test_expect_success
'git diff-index --raw HEAD' '
44 git diff-index --raw HEAD >actual.index &&
45 test_cmp expect actual.index
48 test_expect_success
'git diff-files --raw' '
49 git diff-files --raw >actual.files &&
50 test_cmp expect actual.files
54 printf "%sSubproject commit %s\n+Subproject commit %s\n" \
58 test_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
65 test_expect_success
'git diff HEAD with dirty submodule (work tree)' '
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
73 test_expect_success
'git diff HEAD with dirty submodule (index)' '
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
86 test_expect_success
'git diff HEAD with dirty submodule (untracked)' '
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
99 test_expect_success
'git diff HEAD with dirty submodule (work tree, refs match)' '
100 git commit -m "x" sub &&
102 git diff HEAD >actual &&
103 sed -e "1,/^@@/d" actual >actual.body &&
104 expect_from_to >expect.body $subprev $subprev-dirty &&
105 test_cmp expect.body actual.body &&
106 git diff --ignore-submodules HEAD >actual2 &&
107 test_must_be_empty actual2 &&
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 &&
113 test_must_be_empty actual4
116 test_expect_success
'git diff HEAD with dirty submodule (work tree, refs match) [.gitmodules]' '
117 git config diff.ignoreSubmodules dirty &&
118 git diff HEAD >actual &&
119 test_must_be_empty actual &&
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 &&
129 test_must_be_empty actual2 &&
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 &&
137 test_must_be_empty actual4 &&
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 &&
146 git config --unset diff.ignoreSubmodules &&
150 test_expect_success
'git diff HEAD with dirty submodule (index, refs match)' '
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
163 test_expect_success
'git diff HEAD with dirty submodule (untracked, refs match)' '
170 git diff HEAD >actual &&
171 sed -e "1,/^@@/d" actual >actual.body &&
172 expect_from_to >expect.body $subprev $subprev-dirty &&
173 test_cmp expect.body actual.body &&
174 git diff --ignore-submodules=all HEAD >actual2 &&
175 test_must_be_empty actual2 &&
176 git diff --ignore-submodules=untracked HEAD >actual3 &&
177 test_must_be_empty actual3 &&
178 git diff --ignore-submodules=dirty HEAD >actual4 &&
179 test_must_be_empty actual4
182 test_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 &&
186 test_must_be_empty actual2 &&
187 git config -f .gitmodules submodule.subname.ignore untracked &&
188 git diff HEAD >actual3 &&
189 test_must_be_empty actual3 &&
190 git config -f .gitmodules submodule.subname.ignore dirty &&
191 git diff HEAD >actual4 &&
192 test_must_be_empty actual4 &&
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 &&
204 test_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 &&
214 test_must_be_empty actual
217 test_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 &&
230 test_must_be_empty actual &&
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 &&
241 test_expect_success
'git diff (empty submodule dir)' '
242 rm -rf sub/* sub/.git &&
243 git diff > actual.empty &&
244 test_must_be_empty actual.empty
247 test_expect_success
'conflicted submodule setup' '
250 c=fffffffffffffffffffffffffffffffffffffff &&
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
261 @@@ -1,1 -1,1 +1,1 @@@
262 - Subproject commit 2fffffffffffffffffffffffffffffffffffffff
263 -Subproject commit 3fffffffffffffffffffffffffffffffffffffff
264 ++Subproject commit 0000000000000000000000000000000000000000'\'' &&
266 hh=$(git rev-parse HEAD) &&
267 sed -e "s/$ZERO_OID/$hh/" expect.nosub >expect.withsub
271 test_expect_success
'combined (empty submodule)' '
272 rm -fr sub && mkdir sub &&
274 test_cmp expect.nosub actual
277 test_expect_success
'combined (with submodule)' '
279 git clone --no-checkout . sub &&
281 test_cmp expect.withsub actual