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 path 'lib'
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 module.lib.url git://example.com/lib.git
46 test_expect_success 'status should only print one line' '
47 lines=$(git-submodule status | wc -l) &&
51 test_expect_success 'status should initially be "missing"' '
52 git-submodule status | grep "^-$rev1"
55 test_expect_success 'init should register submodule url in .git/config' '
57 url=$(git-config submodule.lib.url) &&
58 if test "$url" != "git://example.com/lib.git"
60 echo "[OOPS] init succeeded but submodule url is wrong"
62 elif ! git-config submodule.lib.url ./.subrepo
64 echo "[OOPS] init succeeded but update of url failed"
69 test_expect_success 'update should fail when path is used by a file' '
71 if git-submodule update
73 echo "[OOPS] update should have failed"
75 elif test -f lib && test "$(cat lib)" != "hello"
77 echo "[OOPS] update failed but lib file was molested"
84 test_expect_success 'update should fail when path is used by a nonempty directory' '
86 echo "hello" >lib/a &&
87 if git-submodule update
89 echo "[OOPS] update should have failed"
91 elif test "$(cat lib/a)" != "hello"
93 echo "[OOPS] update failed but lib/a was molested"
100 test_expect_success 'update should work when path is an empty dir' '
103 git-submodule update &&
104 head=$(cd lib && git-rev-parse HEAD) &&
107 echo "[OOPS] Failed to obtain submodule head"
109 elif test "$head" != "$rev1"
111 echo "[OOPS] Submodule head is $head but should have been $rev1"
116 test_expect_success 'status should be "up-to-date" after update' '
117 git-submodule status | grep "^ $rev1"
120 test_expect_success 'status should be "modified" after submodule commit' '
124 git-commit -m "submodule commit 2" &&
125 rev2=$(git-rev-parse HEAD) &&
129 echo "[OOPS] submodule git-rev-parse returned nothing"
132 git-submodule status | grep "^+$rev2"
135 test_expect_success 'the --cached sha1 should be rev1' '
136 git-submodule --cached status | grep "^+$rev1"
139 test_expect_success 'update should checkout rev1' '
140 git-submodule update &&
141 head=$(cd lib && git-rev-parse HEAD) &&
144 echo "[OOPS] submodule git-rev-parse returned nothing"
146 elif test "$head" != "$rev1"
148 echo "[OOPS] init did not checkout correct head"
153 test_expect_success 'status should be "up-to-date" after update' '
154 git-submodule status | grep "^ $rev1"