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 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
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/init.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 init
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/init.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 init)" != "hello"
93 echo "[OOPS] update failed but init file was molested"
100 test_expect_success 'update should fail when path is used by a nonempty directory' '
102 echo "hello" >init/a &&
103 if git-submodule update
105 echo "[OOPS] update should have failed"
107 elif test "$(cat init/a)" != "hello"
109 echo "[OOPS] update failed but init/a was molested"
116 test_expect_success 'update should work when path is an empty dir' '
119 git-submodule update &&
120 head=$(cd init && 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 'git diff should report the SHA1 of the new submodule commit' '
156 git-diff | grep "^+Subproject commit $rev2"
159 test_expect_success 'update should checkout rev1' '
160 git-submodule update init &&
161 head=$(cd init && git rev-parse HEAD) &&
164 echo "[OOPS] submodule git rev-parse returned nothing"
166 elif test "$head" != "$rev1"
168 echo "[OOPS] init did not checkout correct head"
173 test_expect_success 'status should be "up-to-date" after update' '
174 git-submodule status | grep "^ $rev1"
177 test_expect_success 'checkout superproject with subproject already present' '
178 git-checkout initial &&
182 test_expect_success 'apply submodule diff' '
188 git commit -m "change subproject"
190 git update-index --add init &&
191 git-commit -m "change init" &&
192 git-format-patch -1 --stdout >P.diff &&
193 git checkout second &&
194 git apply --index P.diff &&
195 D=$(git diff --cached master) &&