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 ./.subrepo
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 fail when path is used by a file' '
59 echo "[OOPS] init should have failed"
61 elif test -f lib && test "$(cat lib)" != "hello"
63 echo "[OOPS] init failed but lib file was molested"
70 test_expect_success 'init should fail when path is used by a nonempty directory' '
72 echo "hello" >lib/a &&
75 echo "[OOPS] init should have failed"
77 elif test "$(cat lib/a)" != "hello"
79 echo "[OOPS] init failed but lib/a was molested"
86 test_expect_success 'init should work when path is an empty dir' '
90 head=$(cd lib && git-rev-parse HEAD) &&
93 echo "[OOPS] Failed to obtain submodule head"
95 elif test "$head" != "$rev1"
97 echo "[OOPS] Submodule head is $head but should have been $rev1"
102 test_expect_success 'status should be "up-to-date" after init' '
103 git-submodule status | grep "^ $rev1"
106 test_expect_success 'status should be "modified" after submodule commit' '
110 git-commit -m "submodule commit 2" &&
111 rev2=$(git-rev-parse HEAD) &&
115 echo "[OOPS] submodule git-rev-parse returned nothing"
118 git-submodule status | grep "^+$rev2"
121 test_expect_success 'the --cached sha1 should be rev1' '
122 git-submodule --cached status | grep "^+$rev1"
125 test_expect_success 'update should checkout rev1' '
126 git-submodule update &&
127 head=$(cd lib && git-rev-parse HEAD) &&
130 echo "[OOPS] submodule git-rev-parse returned nothing"
132 elif test "$head" != "$rev1"
134 echo "[OOPS] init did not checkout correct head"
139 test_expect_success 'status should be "up-to-date" after update' '
140 git-submodule status | grep "^ $rev1"