3 # Copyright (c) 2008 David Aguilar
6 test_description
='git submodule sync
8 These tests exercise the "git submodule sync" subcommand.
13 test_expect_success setup
'
17 git commit -m upstream &&
19 git clone super submodule &&
21 git submodule add ../submodule sub-submodule &&
23 git commit -m "sub-submodule"
26 git submodule add ../submodule submodule &&
28 git commit -m "submodule"
30 git clone super super-clone &&
31 (cd super-clone && git submodule update --init --recursive) &&
32 git clone super empty-clone &&
33 (cd empty-clone && git submodule init) &&
34 git clone super top-only-clone &&
35 git clone super relative-clone &&
36 (cd relative-clone && git submodule update --init --recursive) &&
37 git clone super recursive-clone &&
38 (cd recursive-clone && git submodule update --init --recursive)
41 test_expect_success
'change submodule' '
43 echo second line >> file &&
45 git commit -a -m "change submodule"
49 test_expect_success
'change submodule url' '
52 git checkout master &&
55 mv submodule moved-submodule &&
56 (cd moved-submodule &&
57 git config -f .gitmodules submodule.sub-submodule.url ../moved-submodule &&
59 git commit -a -m moved-sub-submodule
62 git config -f .gitmodules submodule.submodule.url ../moved-submodule &&
64 git commit -a -m moved-submodule
68 test_expect_success
'"git submodule sync" should update submodule URLs' '
70 git pull --no-recurse-submodules &&
73 test -d "$(cd super-clone/submodule &&
74 git config remote.origin.url
76 test ! -d "$(cd super-clone/submodule/sub-submodule &&
77 git config remote.origin.url
79 (cd super-clone/submodule &&
80 git checkout master &&
84 test -d "$(git config submodule.submodule.url)"
88 test_expect_success
'"git submodule sync --recursive" should update all submodule URLs' '
91 git pull --no-recurse-submodules
93 git submodule sync --recursive
95 test -d "$(cd super-clone/submodule &&
96 git config remote.origin.url
98 test -d "$(cd super-clone/submodule/sub-submodule &&
99 git config remote.origin.url
101 (cd super-clone/submodule/sub-submodule &&
102 git checkout master &&
107 test_expect_success
'"git submodule sync" should update known submodule URLs' '
110 git submodule sync &&
111 test -d "$(git config submodule.submodule.url)"
115 test_expect_success
'"git submodule sync" should not vivify uninteresting submodule' '
116 (cd top-only-clone &&
118 git submodule sync &&
119 test -z "$(git config submodule.submodule.url)" &&
120 git submodule sync submodule &&
121 test -z "$(git config submodule.submodule.url)"
125 test_expect_success
'"git submodule sync" handles origin URL of the form foo' '
126 (cd relative-clone &&
127 git remote set-url origin foo &&
128 git submodule sync &&
130 #actual fails with: "cannot strip off url foo
131 test "$(git config remote.origin.url)" = "../submodule"
136 test_expect_success
'"git submodule sync" handles origin URL of the form foo/bar' '
137 (cd relative-clone &&
138 git remote set-url origin foo/bar &&
139 git submodule sync &&
141 #actual foo/submodule
142 test "$(git config remote.origin.url)" = "../foo/submodule"
144 (cd submodule/sub-submodule &&
145 test "$(git config remote.origin.url)" != "../../foo/submodule"
150 test_expect_success
'"git submodule sync --recursive" propagates changes in origin' '
151 (cd recursive-clone &&
152 git remote set-url origin foo/bar &&
153 git submodule sync --recursive &&
155 #actual foo/submodule
156 test "$(git config remote.origin.url)" = "../foo/submodule"
158 (cd submodule/sub-submodule &&
159 test "$(git config remote.origin.url)" = "../../foo/submodule"
164 test_expect_success
'"git submodule sync" handles origin URL of the form ./foo' '
165 (cd relative-clone &&
166 git remote set-url origin ./foo &&
167 git submodule sync &&
170 test "$(git config remote.origin.url)" = "../submodule"
175 test_expect_success
'"git submodule sync" handles origin URL of the form ./foo/bar' '
176 (cd relative-clone &&
177 git remote set-url origin ./foo/bar &&
178 git submodule sync &&
180 #actual ./foo/submodule
181 test "$(git config remote.origin.url)" = "../foo/submodule"
186 test_expect_success
'"git submodule sync" handles origin URL of the form ../foo' '
187 (cd relative-clone &&
188 git remote set-url origin ../foo &&
189 git submodule sync &&
192 test "$(git config remote.origin.url)" = "../../submodule"
197 test_expect_success
'"git submodule sync" handles origin URL of the form ../foo/bar' '
198 (cd relative-clone &&
199 git remote set-url origin ../foo/bar &&
200 git submodule sync &&
202 #actual ../foo/submodule
203 test "$(git config remote.origin.url)" = "../../foo/submodule"
208 test_expect_success
'"git submodule sync" handles origin URL of the form ../foo/bar with deeply nested submodule' '
209 (cd relative-clone &&
210 git remote set-url origin ../foo/bar &&
215 git add .gitignore &&
217 git commit -m "initial commit" ) &&
218 git submodule add ../bar/a/b/c ./a/b/c &&
219 git submodule sync &&
221 #actual ../foo/bar/a/b/c
222 test "$(git config remote.origin.url)" = "../../../../foo/bar/a/b/c"