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.
16 # -create a repository in directory lib
17 # -add a couple of files
18 # -add directory lib to 'superproject', this creates a DIRLINK entry
19 # -add a couple of regular files to enable testing of submodule filtering
21 # -add an entry to .gitmodules for submodule 'example'
23 test_expect_success
'Prepare submodule testing' '
26 git-commit -m "initial commit" &&
27 git branch initial HEAD &&
33 git-commit -m "submodule commit 1" &&
34 git-tag -a -m "rev-1" rev-1 &&
35 rev1=$(git rev-parse HEAD) &&
38 echo "[OOPS] submodule git rev-parse returned nothing"
45 git-commit -m "super commit 1" &&
47 GIT_CONFIG=.gitmodules git config submodule.example.url git://example.com/lib.git
50 test_expect_success
'status should fail for unmapped paths' '
51 if git-submodule status
53 echo "[OOPS] submodule status succeeded"
55 elif ! GIT_CONFIG=.gitmodules git config submodule.example.path lib
57 echo "[OOPS] git config failed to update .gitmodules"
62 test_expect_success
'status should only print one line' '
63 lines=$(git-submodule status | wc -l) &&
67 test_expect_success
'status should initially be "missing"' '
68 git-submodule status | grep "^-$rev1"
71 test_expect_success
'init should register submodule url in .git/config' '
73 url=$(git config submodule.example.url) &&
74 if test "$url" != "git://example.com/lib.git"
76 echo "[OOPS] init succeeded but submodule url is wrong"
78 elif ! git config submodule.example.url ./.subrepo
80 echo "[OOPS] init succeeded but update of url failed"
85 test_expect_success
'update should fail when path is used by a file' '
87 if git-submodule update
89 echo "[OOPS] update should have failed"
91 elif test "$(cat lib)" != "hello"
93 echo "[OOPS] update failed but lib file was molested"
100 test_expect_success
'update should fail when path is used by a nonempty directory' '
102 echo "hello" >lib/a &&
103 if git-submodule update
105 echo "[OOPS] update should have failed"
107 elif test "$(cat lib/a)" != "hello"
109 echo "[OOPS] update failed but lib/a was molested"
116 test_expect_success
'update should work when path is an empty dir' '
119 git-submodule update &&
120 head=$(cd lib && git rev-parse HEAD) &&
123 echo "[OOPS] Failed to obtain submodule head"
125 elif test "$head" != "$rev1"
127 echo "[OOPS] Submodule head is $head but should have been $rev1"
132 test_expect_success
'status should be "up-to-date" after update' '
133 git-submodule status | grep "^ $rev1"
136 test_expect_success
'status should be "modified" after submodule commit' '
140 git-commit -m "submodule commit 2" &&
141 rev2=$(git rev-parse HEAD) &&
145 echo "[OOPS] submodule git rev-parse returned nothing"
148 git-submodule status | grep "^+$rev2"
151 test_expect_success
'the --cached sha1 should be rev1' '
152 git-submodule --cached status | grep "^+$rev1"
155 test_expect_success
'update should checkout rev1' '
156 git-submodule update &&
157 head=$(cd lib && git rev-parse HEAD) &&
160 echo "[OOPS] submodule git rev-parse returned nothing"
162 elif test "$head" != "$rev1"
164 echo "[OOPS] init did not checkout correct head"
169 test_expect_success
'status should be "up-to-date" after update' '
170 git-submodule status | grep "^ $rev1"
173 test_expect_success
'checkout superproject with subproject already present' '
174 git-checkout initial &&