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' '
29 git-commit -m "submodule commit 1" &&
30 git-tag -a -m "rev-1" rev-1 &&
31 rev1=$(git-rev-parse HEAD) &&
34 echo "[OOPS] submodule git-rev-parse returned nothing"
41 git-commit -m "super commit 1" &&
43 GIT_CONFIG=.gitmodules git-config submodule.example.url git://example.com/lib.git
46 test_expect_success
'status should fail for unmapped paths' '
47 if git-submodule status
49 echo "[OOPS] submodule status succeeded"
51 elif ! GIT_CONFIG=.gitmodules git-config submodule.example.path lib
53 echo "[OOPS] git-config failed to update .gitmodules"
58 test_expect_success
'status should only print one line' '
59 lines=$(git-submodule status | wc -l) &&
63 test_expect_success
'status should initially be "missing"' '
64 git-submodule status | grep "^-$rev1"
67 test_expect_success
'init should register submodule url in .git/config' '
69 url=$(git-config submodule.example.url) &&
70 if test "$url" != "git://example.com/lib.git"
72 echo "[OOPS] init succeeded but submodule url is wrong"
74 elif ! git-config submodule.example.url ./.subrepo
76 echo "[OOPS] init succeeded but update of url failed"
81 test_expect_success
'update should fail when path is used by a file' '
83 if git-submodule update
85 echo "[OOPS] update should have failed"
87 elif test "$(cat lib)" != "hello"
89 echo "[OOPS] update failed but lib file was molested"
96 test_expect_success
'update should fail when path is used by a nonempty directory' '
98 echo "hello" >lib/a &&
99 if git-submodule update
101 echo "[OOPS] update should have failed"
103 elif test "$(cat lib/a)" != "hello"
105 echo "[OOPS] update failed but lib/a was molested"
112 test_expect_success
'update should work when path is an empty dir' '
115 git-submodule update &&
116 head=$(cd lib && git-rev-parse HEAD) &&
119 echo "[OOPS] Failed to obtain submodule head"
121 elif test "$head" != "$rev1"
123 echo "[OOPS] Submodule head is $head but should have been $rev1"
128 test_expect_success
'status should be "up-to-date" after update' '
129 git-submodule status | grep "^ $rev1"
132 test_expect_success
'status should be "modified" after submodule commit' '
136 git-commit -m "submodule commit 2" &&
137 rev2=$(git-rev-parse HEAD) &&
141 echo "[OOPS] submodule git-rev-parse returned nothing"
144 git-submodule status | grep "^+$rev2"
147 test_expect_success
'the --cached sha1 should be rev1' '
148 git-submodule --cached status | grep "^+$rev1"
151 test_expect_success
'update should checkout rev1' '
152 git-submodule update &&
153 head=$(cd lib && git-rev-parse HEAD) &&
156 echo "[OOPS] submodule git-rev-parse returned nothing"
158 elif test "$head" != "$rev1"
160 echo "[OOPS] init did not checkout correct head"
165 test_expect_success
'status should be "up-to-date" after update' '
166 git-submodule status | grep "^ $rev1"