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-dirty &&
97 test_cmp expect.body actual.body
100 test_expect_success
'git diff HEAD with dirty submodule (work tree, refs match)' '
101 git commit -m "x" sub &&
103 git diff HEAD >actual &&
104 sed -e "1,/^@@/d" actual >actual.body &&
105 expect_from_to >expect.body $subprev $subprev-dirty &&
106 test_cmp expect.body actual.body &&
107 git diff --ignore-submodules HEAD >actual2 &&
108 test_must_be_empty actual2 &&
109 git diff --ignore-submodules=untracked HEAD >actual3 &&
110 sed -e "1,/^@@/d" actual3 >actual3.body &&
111 expect_from_to >expect.body $subprev $subprev-dirty &&
112 test_cmp expect.body actual3.body &&
113 git diff --ignore-submodules=dirty HEAD >actual4 &&
114 test_must_be_empty actual4
117 test_expect_success
'git diff HEAD with dirty submodule (work tree, refs match) [.gitmodules]' '
118 git config diff.ignoreSubmodules dirty &&
119 git diff HEAD >actual &&
120 test_must_be_empty actual &&
121 git config --add -f .gitmodules submodule.subname.ignore none &&
122 git config --add -f .gitmodules submodule.subname.path sub &&
123 git diff HEAD >actual &&
124 sed -e "1,/^@@/d" actual >actual.body &&
125 expect_from_to >expect.body $subprev $subprev-dirty &&
126 test_cmp expect.body actual.body &&
127 git config -f .gitmodules submodule.subname.ignore all &&
128 git config -f .gitmodules submodule.subname.path sub &&
129 git diff HEAD >actual2 &&
130 test_must_be_empty actual2 &&
131 git config -f .gitmodules submodule.subname.ignore untracked &&
132 git diff HEAD >actual3 &&
133 sed -e "1,/^@@/d" actual3 >actual3.body &&
134 expect_from_to >expect.body $subprev $subprev-dirty &&
135 test_cmp expect.body actual3.body &&
136 git config -f .gitmodules submodule.subname.ignore dirty &&
137 git diff HEAD >actual4 &&
138 test_must_be_empty actual4 &&
139 git config submodule.subname.ignore none &&
140 git config submodule.subname.path sub &&
141 git diff HEAD >actual &&
142 sed -e "1,/^@@/d" actual >actual.body &&
143 expect_from_to >expect.body $subprev $subprev-dirty &&
144 test_cmp expect.body actual.body &&
145 git config --remove-section submodule.subname &&
146 git config --remove-section -f .gitmodules submodule.subname &&
147 git config --unset diff.ignoreSubmodules &&
151 test_expect_success
'git diff HEAD with dirty submodule (index, refs match)' '
158 git diff HEAD >actual &&
159 sed -e "1,/^@@/d" actual >actual.body &&
160 expect_from_to >expect.body $subprev $subprev-dirty &&
161 test_cmp expect.body actual.body
164 test_expect_success
'git diff HEAD with dirty submodule (untracked, refs match)' '
171 git diff HEAD >actual &&
172 sed -e "1,/^@@/d" actual >actual.body &&
173 expect_from_to >expect.body $subprev $subprev-dirty &&
174 test_cmp expect.body actual.body &&
175 git diff --ignore-submodules=all HEAD >actual2 &&
176 test_must_be_empty actual2 &&
177 git diff --ignore-submodules=untracked HEAD >actual3 &&
178 test_must_be_empty actual3 &&
179 git diff --ignore-submodules=dirty HEAD >actual4 &&
180 test_must_be_empty actual4
183 test_expect_success
'git diff HEAD with dirty submodule (untracked, refs match) [.gitmodules]' '
184 git config --add -f .gitmodules submodule.subname.ignore all &&
185 git config --add -f .gitmodules submodule.subname.path sub &&
186 git diff HEAD >actual2 &&
187 test_must_be_empty actual2 &&
188 git config -f .gitmodules submodule.subname.ignore untracked &&
189 git diff HEAD >actual3 &&
190 test_must_be_empty actual3 &&
191 git config -f .gitmodules submodule.subname.ignore dirty &&
192 git diff HEAD >actual4 &&
193 test_must_be_empty actual4 &&
194 git config submodule.subname.ignore none &&
195 git config submodule.subname.path sub &&
196 git diff HEAD >actual &&
197 sed -e "1,/^@@/d" actual >actual.body &&
198 expect_from_to >expect.body $subprev $subprev-dirty &&
199 test_cmp expect.body actual.body &&
200 git config --remove-section submodule.subname &&
201 git config --remove-section -f .gitmodules submodule.subname &&
205 test_expect_success
'git diff between submodule commits' '
206 git diff HEAD^..HEAD >actual &&
207 sed -e "1,/^@@/d" actual >actual.body &&
208 expect_from_to >expect.body $subtip $subprev &&
209 test_cmp expect.body actual.body &&
210 git diff --ignore-submodules=dirty HEAD^..HEAD >actual &&
211 sed -e "1,/^@@/d" actual >actual.body &&
212 expect_from_to >expect.body $subtip $subprev &&
213 test_cmp expect.body actual.body &&
214 git diff --ignore-submodules HEAD^..HEAD >actual &&
215 test_must_be_empty actual
218 test_expect_success
'git diff between submodule commits [.gitmodules]' '
219 git diff 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 config --add -f .gitmodules submodule.subname.ignore dirty &&
224 git config --add -f .gitmodules submodule.subname.path sub &&
225 git diff HEAD^..HEAD >actual &&
226 sed -e "1,/^@@/d" actual >actual.body &&
227 expect_from_to >expect.body $subtip $subprev &&
228 test_cmp expect.body actual.body &&
229 git config -f .gitmodules submodule.subname.ignore all &&
230 git diff HEAD^..HEAD >actual &&
231 test_must_be_empty actual &&
232 git config submodule.subname.ignore dirty &&
233 git config 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 git config --remove-section submodule.subname &&
238 git config --remove-section -f .gitmodules submodule.subname &&
242 test_expect_success
'git diff (empty submodule dir)' '
243 rm -rf sub/* sub/.git &&
244 git diff > actual.empty &&
245 test_must_be_empty actual.empty
248 test_expect_success
'conflicted submodule setup' '
249 c=$(test_oid ff_1) &&
251 echo "000000 $ZERO_OID 0 sub" &&
252 echo "160000 1$c 1 sub" &&
253 echo "160000 2$c 2 sub" &&
254 echo "160000 3$c 3 sub"
255 ) | git update-index --index-info &&
256 echo >expect.nosub "diff --cc sub
257 index 2ffffff,3ffffff..0000000
260 @@@ -1,1 -1,1 +1,1 @@@
261 - Subproject commit 2$c
262 -Subproject commit 3$c
263 ++Subproject commit $ZERO_OID" &&
265 hh=$(git rev-parse HEAD) &&
266 sed -e "s/$ZERO_OID/$hh/" expect.nosub >expect.withsub
270 test_expect_success
'combined (empty submodule)' '
271 rm -fr sub && mkdir sub &&
273 test_cmp expect.nosub actual
276 test_expect_success
'combined (with submodule)' '
278 git clone --no-checkout . sub &&
280 test_cmp expect.withsub actual