clone_submodule: avoid using `access()` on directories
[git.git] / t / t4027-diff-submodule.sh
blob40164ae07d2c06d9ef5fc67b16e5ad8421b2875e
1 #!/bin/sh
3 test_description='difference in submodules'
5 TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
7 . "$TEST_DIRECTORY"/lib-diff.sh
9 test_expect_success setup '
10 test_tick &&
11 test_create_repo sub &&
13 cd sub &&
14 echo hello >world &&
15 git add world &&
16 git commit -m submodule
17 ) &&
19 test_tick &&
20 echo frotz >nitfol &&
21 git add nitfol sub &&
22 git commit -m superproject &&
25 cd sub &&
26 echo goodbye >world &&
27 git add world &&
28 git commit -m "submodule #2"
29 ) &&
31 git -C sub rev-list HEAD >revs &&
32 set x $(cat revs) &&
33 echo ":160000 160000 $3 $ZERO_OID M sub" >expect &&
34 subtip=$3 subprev=$2
37 test_expect_success 'git diff --raw HEAD' '
38 hexsz=$(test_oid hexsz) &&
39 git diff --raw --abbrev=$hexsz 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
53 expect_from_to () {
54 printf "%sSubproject commit %s\n+Subproject commit %s\n" \
55 "-" "$1" "$2"
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)' '
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
73 test_expect_success 'git diff HEAD with dirty submodule (index)' '
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
86 test_expect_success 'git diff HEAD with dirty submodule (untracked)' '
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 &&
96 test_cmp expect.body actual.body
99 test_expect_success 'git diff HEAD with dirty submodule (untracked) (none ignored)' '
100 test_config diff.ignoreSubmodules none &&
101 git diff HEAD >actual &&
102 sed -e "1,/^@@/d" actual >actual.body &&
103 expect_from_to >expect.body $subtip $subprev-dirty &&
104 test_cmp expect.body actual.body
107 test_expect_success 'git diff HEAD with dirty submodule (work tree, refs match)' '
108 git commit -m "x" sub &&
109 echo >>sub/world &&
110 git diff HEAD >actual &&
111 sed -e "1,/^@@/d" actual >actual.body &&
112 expect_from_to >expect.body $subprev $subprev-dirty &&
113 test_cmp expect.body actual.body &&
114 git diff --ignore-submodules HEAD >actual2 &&
115 test_must_be_empty actual2 &&
116 git diff --ignore-submodules=untracked HEAD >actual3 &&
117 sed -e "1,/^@@/d" actual3 >actual3.body &&
118 expect_from_to >expect.body $subprev $subprev-dirty &&
119 test_cmp expect.body actual3.body &&
120 git diff --ignore-submodules=dirty HEAD >actual4 &&
121 test_must_be_empty actual4
124 test_expect_success 'git diff HEAD with dirty submodule (work tree, refs match) [.gitmodules]' '
125 git config diff.ignoreSubmodules dirty &&
126 git diff HEAD >actual &&
127 test_must_be_empty actual &&
128 git config --add -f .gitmodules submodule.subname.ignore none &&
129 git config --add -f .gitmodules submodule.subname.path sub &&
130 git diff HEAD >actual &&
131 sed -e "1,/^@@/d" actual >actual.body &&
132 expect_from_to >expect.body $subprev $subprev-dirty &&
133 test_cmp expect.body actual.body &&
134 git config -f .gitmodules submodule.subname.ignore all &&
135 git config -f .gitmodules submodule.subname.path sub &&
136 git diff HEAD >actual2 &&
137 test_must_be_empty actual2 &&
138 git config -f .gitmodules submodule.subname.ignore untracked &&
139 git diff HEAD >actual3 &&
140 sed -e "1,/^@@/d" actual3 >actual3.body &&
141 expect_from_to >expect.body $subprev $subprev-dirty &&
142 test_cmp expect.body actual3.body &&
143 git config -f .gitmodules submodule.subname.ignore dirty &&
144 git diff HEAD >actual4 &&
145 test_must_be_empty actual4 &&
146 git config submodule.subname.ignore none &&
147 git config submodule.subname.path sub &&
148 git diff HEAD >actual &&
149 sed -e "1,/^@@/d" actual >actual.body &&
150 expect_from_to >expect.body $subprev $subprev-dirty &&
151 test_cmp expect.body actual.body &&
152 git config --remove-section submodule.subname &&
153 git config --remove-section -f .gitmodules submodule.subname &&
154 git config --unset diff.ignoreSubmodules &&
155 rm .gitmodules
158 test_expect_success 'git diff HEAD with dirty submodule (index, refs match)' '
160 cd sub &&
161 git reset --hard &&
162 echo >>world &&
163 git add world
164 ) &&
165 git diff HEAD >actual &&
166 sed -e "1,/^@@/d" actual >actual.body &&
167 expect_from_to >expect.body $subprev $subprev-dirty &&
168 test_cmp expect.body actual.body
171 test_expect_success 'git diff HEAD with dirty submodule (untracked, refs match)' '
173 cd sub &&
174 git reset --hard &&
175 git clean -qfdx &&
176 >cruft
177 ) &&
178 git diff --ignore-submodules=none HEAD >actual &&
179 sed -e "1,/^@@/d" actual >actual.body &&
180 expect_from_to >expect.body $subprev $subprev-dirty &&
181 test_cmp expect.body actual.body &&
182 git diff --ignore-submodules=all HEAD >actual2 &&
183 test_must_be_empty actual2 &&
184 git diff HEAD >actual3 &&
185 test_must_be_empty actual3 &&
186 git diff --ignore-submodules=dirty HEAD >actual4 &&
187 test_must_be_empty actual4
190 test_expect_success 'git diff HEAD with dirty submodule (untracked, refs match) [.gitmodules]' '
191 git config --add -f .gitmodules submodule.subname.ignore all &&
192 git config --add -f .gitmodules submodule.subname.path sub &&
193 git diff HEAD >actual2 &&
194 test_must_be_empty actual2 &&
195 git config -f .gitmodules submodule.subname.ignore untracked &&
196 git diff HEAD >actual3 &&
197 test_must_be_empty actual3 &&
198 git config -f .gitmodules submodule.subname.ignore dirty &&
199 git diff HEAD >actual4 &&
200 test_must_be_empty actual4 &&
201 git config submodule.subname.ignore none &&
202 git config submodule.subname.path sub &&
203 git diff HEAD >actual &&
204 sed -e "1,/^@@/d" actual >actual.body &&
205 expect_from_to >expect.body $subprev $subprev-dirty &&
206 test_cmp expect.body actual.body &&
207 git config --remove-section submodule.subname &&
208 git config --remove-section -f .gitmodules submodule.subname &&
209 rm .gitmodules
212 test_expect_success 'git diff between submodule commits' '
213 git diff HEAD^..HEAD >actual &&
214 sed -e "1,/^@@/d" actual >actual.body &&
215 expect_from_to >expect.body $subtip $subprev &&
216 test_cmp expect.body actual.body &&
217 git diff --ignore-submodules=dirty HEAD^..HEAD >actual &&
218 sed -e "1,/^@@/d" actual >actual.body &&
219 expect_from_to >expect.body $subtip $subprev &&
220 test_cmp expect.body actual.body &&
221 git diff --ignore-submodules HEAD^..HEAD >actual &&
222 test_must_be_empty actual
225 test_expect_success 'git diff between submodule commits [.gitmodules]' '
226 git diff HEAD^..HEAD >actual &&
227 sed -e "1,/^@@/d" actual >actual.body &&
228 expect_from_to >expect.body $subtip $subprev &&
229 test_cmp expect.body actual.body &&
230 git config --add -f .gitmodules submodule.subname.ignore dirty &&
231 git config --add -f .gitmodules submodule.subname.path sub &&
232 git diff HEAD^..HEAD >actual &&
233 sed -e "1,/^@@/d" actual >actual.body &&
234 expect_from_to >expect.body $subtip $subprev &&
235 test_cmp expect.body actual.body &&
236 git config -f .gitmodules submodule.subname.ignore all &&
237 git diff HEAD^..HEAD >actual &&
238 test_must_be_empty actual &&
239 git config submodule.subname.ignore dirty &&
240 git config submodule.subname.path sub &&
241 git diff HEAD^..HEAD >actual &&
242 sed -e "1,/^@@/d" actual >actual.body &&
243 expect_from_to >expect.body $subtip $subprev &&
244 git config --remove-section submodule.subname &&
245 git config --remove-section -f .gitmodules submodule.subname &&
246 rm .gitmodules
249 test_expect_success 'git diff (empty submodule dir)' '
250 rm -rf sub/* sub/.git &&
251 git diff > actual.empty &&
252 test_must_be_empty actual.empty
255 test_expect_success 'conflicted submodule setup' '
256 c=$(test_oid ff_1) &&
258 echo "000000 $ZERO_OID 0 sub" &&
259 echo "160000 1$c 1 sub" &&
260 echo "160000 2$c 2 sub" &&
261 echo "160000 3$c 3 sub"
262 ) | git update-index --index-info &&
263 echo >expect.nosub "diff --cc sub
264 index 2ffffff,3ffffff..0000000
265 --- a/sub
266 +++ b/sub
267 @@@ -1,1 -1,1 +1,1 @@@
268 - Subproject commit 2$c
269 -Subproject commit 3$c
270 ++Subproject commit $ZERO_OID" &&
272 hh=$(git rev-parse HEAD) &&
273 sed -e "s/$ZERO_OID/$hh/" expect.nosub >expect.withsub
277 test_expect_success 'combined (empty submodule)' '
278 rm -fr sub && mkdir sub &&
279 git diff >actual &&
280 test_cmp expect.nosub actual
283 test_expect_success 'combined (with submodule)' '
284 rm -fr sub &&
285 git clone --no-checkout . sub &&
286 git diff >actual &&
287 test_cmp expect.withsub actual
292 test_done