builtin-commit: add --date option
[git/vmiklos.git] / t / t7400-submodule-basic.sh
bloba0cc99ab9f5b262851a1075193f5529b5582fd0a
1 #!/bin/sh
3 # Copyright (c) 2007 Lars Hjemli
6 test_description='Basic porcelain support for submodules
8 This test tries to verify basic sanity of the init, update and status
9 subcommands of git submodule.
12 . ./test-lib.sh
15 # Test setup:
16 # -create a repository in directory init
17 # -add a couple of files
18 # -add directory init to 'superproject', this creates a DIRLINK entry
19 # -add a couple of regular files to enable testing of submodule filtering
20 # -mv init subrepo
21 # -add an entry to .gitmodules for submodule 'example'
23 test_expect_success 'Prepare submodule testing' '
24 : > t &&
25 git add t &&
26 git commit -m "initial commit" &&
27 git branch initial HEAD &&
28 mkdir init &&
29 cd init &&
30 git init &&
31 echo a >a &&
32 git add a &&
33 git commit -m "submodule commit 1" &&
34 git tag -a -m "rev-1" rev-1 &&
35 rev1=$(git rev-parse HEAD) &&
36 if test -z "$rev1"
37 then
38 echo "[OOPS] submodule git rev-parse returned nothing"
39 false
40 fi &&
41 cd .. &&
42 echo a >a &&
43 echo z >z &&
44 git add a init z &&
45 git commit -m "super commit 1" &&
46 mv init .subrepo &&
47 GIT_CONFIG=.gitmodules git config submodule.example.url git://example.com/init.git
50 test_expect_success 'Prepare submodule add testing' '
51 submodurl=$(pwd)
53 mkdir addtest &&
54 cd addtest &&
55 git init
59 test_expect_success 'submodule add' '
61 cd addtest &&
62 git submodule add "$submodurl" submod &&
63 git submodule init
67 test_expect_success 'submodule add --branch' '
69 cd addtest &&
70 git submodule add -b initial "$submodurl" submod-branch &&
71 git submodule init &&
72 cd submod-branch &&
73 git branch | grep initial
77 test_expect_success 'submodule add with ./ in path' '
79 cd addtest &&
80 git submodule add "$submodurl" ././dotsubmod/./frotz/./ &&
81 git submodule init
85 test_expect_success 'submodule add with // in path' '
87 cd addtest &&
88 git submodule add "$submodurl" slashslashsubmod///frotz// &&
89 git submodule init
93 test_expect_success 'submodule add with /.. in path' '
95 cd addtest &&
96 git submodule add "$submodurl" dotdotsubmod/../realsubmod/frotz/.. &&
97 git submodule init
101 test_expect_success 'submodule add with ./, /.. and // in path' '
103 cd addtest &&
104 git submodule add "$submodurl" dot/dotslashsubmod/./../..////realsubmod2/a/b/c/d/../../../../frotz//.. &&
105 git submodule init
109 test_expect_success 'status should fail for unmapped paths' '
110 if git submodule status
111 then
112 echo "[OOPS] submodule status succeeded"
113 false
114 elif ! GIT_CONFIG=.gitmodules git config submodule.example.path init
115 then
116 echo "[OOPS] git config failed to update .gitmodules"
117 false
121 test_expect_success 'status should only print one line' '
122 lines=$(git submodule status | wc -l) &&
123 test $lines = 1
126 test_expect_success 'status should initially be "missing"' '
127 git submodule status | grep "^-$rev1"
130 test_expect_success 'init should register submodule url in .git/config' '
131 git submodule init &&
132 url=$(git config submodule.example.url) &&
133 if test "$url" != "git://example.com/init.git"
134 then
135 echo "[OOPS] init succeeded but submodule url is wrong"
136 false
137 elif test_must_fail git config submodule.example.url ./.subrepo
138 then
139 echo "[OOPS] init succeeded but update of url failed"
140 false
144 test_expect_success 'update should fail when path is used by a file' '
145 echo "hello" >init &&
146 if git submodule update
147 then
148 echo "[OOPS] update should have failed"
149 false
150 elif test "$(cat init)" != "hello"
151 then
152 echo "[OOPS] update failed but init file was molested"
153 false
154 else
155 rm init
159 test_expect_success 'update should fail when path is used by a nonempty directory' '
160 mkdir init &&
161 echo "hello" >init/a &&
162 if git submodule update
163 then
164 echo "[OOPS] update should have failed"
165 false
166 elif test "$(cat init/a)" != "hello"
167 then
168 echo "[OOPS] update failed but init/a was molested"
169 false
170 else
171 rm init/a
175 test_expect_success 'update should work when path is an empty dir' '
176 rm -rf init &&
177 mkdir init &&
178 git submodule update &&
179 head=$(cd init && git rev-parse HEAD) &&
180 if test -z "$head"
181 then
182 echo "[OOPS] Failed to obtain submodule head"
183 false
184 elif test "$head" != "$rev1"
185 then
186 echo "[OOPS] Submodule head is $head but should have been $rev1"
187 false
191 test_expect_success 'status should be "up-to-date" after update' '
192 git submodule status | grep "^ $rev1"
195 test_expect_success 'status should be "modified" after submodule commit' '
196 cd init &&
197 echo b >b &&
198 git add b &&
199 git commit -m "submodule commit 2" &&
200 rev2=$(git rev-parse HEAD) &&
201 cd .. &&
202 if test -z "$rev2"
203 then
204 echo "[OOPS] submodule git rev-parse returned nothing"
205 false
206 fi &&
207 git submodule status | grep "^+$rev2"
210 test_expect_success 'the --cached sha1 should be rev1' '
211 git submodule --cached status | grep "^+$rev1"
214 test_expect_success 'git diff should report the SHA1 of the new submodule commit' '
215 git diff | grep "^+Subproject commit $rev2"
218 test_expect_success 'update should checkout rev1' '
219 git submodule update init &&
220 head=$(cd init && git rev-parse HEAD) &&
221 if test -z "$head"
222 then
223 echo "[OOPS] submodule git rev-parse returned nothing"
224 false
225 elif test "$head" != "$rev1"
226 then
227 echo "[OOPS] init did not checkout correct head"
228 false
232 test_expect_success 'status should be "up-to-date" after update' '
233 git submodule status | grep "^ $rev1"
236 test_expect_success 'checkout superproject with subproject already present' '
237 git checkout initial &&
238 git checkout master
241 test_expect_success 'apply submodule diff' '
242 git branch second &&
244 cd init &&
245 echo s >s &&
246 git add s &&
247 git commit -m "change subproject"
248 ) &&
249 git update-index --add init &&
250 git commit -m "change init" &&
251 git format-patch -1 --stdout >P.diff &&
252 git checkout second &&
253 git apply --index P.diff &&
254 D=$(git diff --cached master) &&
255 test -z "$D"
258 test_expect_success 'update --init' '
260 mv init init2 &&
261 git config -f .gitmodules submodule.example.url "$(pwd)/init2" &&
262 git config --remove-section submodule.example
263 git submodule update init > update.out &&
264 grep "not initialized" update.out &&
265 test ! -d init/.git &&
266 git submodule update --init init &&
267 test -d init/.git
271 test_expect_success 'do not add files from a submodule' '
273 git reset --hard &&
274 test_must_fail git add init/a
278 test_expect_success 'gracefully add submodule with a trailing slash' '
280 git reset --hard &&
281 git commit -m "commit subproject" init &&
282 (cd init &&
283 echo b > a) &&
284 git add init/ &&
285 git diff --exit-code --cached init &&
286 commit=$(cd init &&
287 git commit -m update a >/dev/null &&
288 git rev-parse HEAD) &&
289 git add init/ &&
290 test_must_fail git diff --exit-code --cached init &&
291 test $commit = $(git ls-files --stage |
292 sed -n "s/^160000 \([^ ]*\).*/\1/p")
296 test_expect_success 'ls-files gracefully handles trailing slash' '
298 test "init" = "$(git ls-files init/)"
302 test_expect_success 'submodule <invalid-path> warns' '
304 git submodule no-such-submodule 2> output.err &&
305 grep "^error: .*no-such-submodule" output.err
309 test_expect_success 'add submodules without specifying an explicit path' '
310 mkdir repo &&
311 cd repo &&
312 git init &&
313 echo r >r &&
314 git add r &&
315 git commit -m "repo commit 1" &&
316 cd .. &&
317 git clone --bare repo/ bare.git &&
318 cd addtest &&
319 git submodule add "$submodurl/repo" &&
320 git config -f .gitmodules submodule.repo.path repo &&
321 git submodule add "$submodurl/bare.git" &&
322 git config -f .gitmodules submodule.bare.path bare
325 test_done