Lars Hjemli | 88961ef | 2007-06-02 03:27:42 +0200 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # |
| 3 | # Copyright (c) 2007 Lars Hjemli |
| 4 | # |
| 5 | |
| 6 | test_description='Basic porcelain support for submodules |
| 7 | |
| 8 | This test tries to verify basic sanity of the init, update and status |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 9 | subcommands of git submodule. |
Lars Hjemli | 88961ef | 2007-06-02 03:27:42 +0200 | [diff] [blame] | 10 | ' |
| 11 | |
| 12 | . ./test-lib.sh |
| 13 | |
Jonathan Nieder | fe454b1 | 2010-04-10 00:38:37 -0500 | [diff] [blame] | 14 | test_expect_success 'setup - initial commit' ' |
| 15 | >t && |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 16 | git add t && |
| 17 | git commit -m "initial commit" && |
Jonathan Nieder | fe454b1 | 2010-04-10 00:38:37 -0500 | [diff] [blame] | 18 | git branch initial |
| 19 | ' |
| 20 | |
Jharrod LaFon | 4b05440 | 2013-08-19 09:26:56 -0700 | [diff] [blame] | 21 | test_expect_success 'configuration parsing' ' |
| 22 | test_when_finished "rm -f .gitmodules" && |
| 23 | cat >.gitmodules <<-\EOF && |
| 24 | [submodule "s"] |
| 25 | path |
| 26 | ignore |
| 27 | EOF |
| 28 | test_must_fail git status |
| 29 | ' |
| 30 | |
Jonathan Nieder | fe454b1 | 2010-04-10 00:38:37 -0500 | [diff] [blame] | 31 | test_expect_success 'setup - repository in init subdirectory' ' |
Junio C Hamano | a2d93ae | 2008-01-15 03:13:55 -0800 | [diff] [blame] | 32 | mkdir init && |
Jonathan Nieder | fe454b1 | 2010-04-10 00:38:37 -0500 | [diff] [blame] | 33 | ( |
| 34 | cd init && |
| 35 | git init && |
| 36 | echo a >a && |
| 37 | git add a && |
| 38 | git commit -m "submodule commit 1" && |
| 39 | git tag -a -m "rev-1" rev-1 |
| 40 | ) |
Jonathan Nieder | fe454b1 | 2010-04-10 00:38:37 -0500 | [diff] [blame] | 41 | ' |
| 42 | |
| 43 | test_expect_success 'setup - commit with gitlink' ' |
Lars Hjemli | 88961ef | 2007-06-02 03:27:42 +0200 | [diff] [blame] | 44 | echo a >a && |
| 45 | echo z >z && |
Junio C Hamano | a2d93ae | 2008-01-15 03:13:55 -0800 | [diff] [blame] | 46 | git add a init z && |
Jonathan Nieder | fe454b1 | 2010-04-10 00:38:37 -0500 | [diff] [blame] | 47 | git commit -m "super commit 1" |
| 48 | ' |
| 49 | |
| 50 | test_expect_success 'setup - hide init subdirectory' ' |
| 51 | mv init .subrepo |
| 52 | ' |
| 53 | |
Jonathan Nieder | a76c944 | 2010-04-10 00:39:04 -0500 | [diff] [blame] | 54 | test_expect_success 'setup - repository to add submodules to' ' |
Ævar Arnfjörð Bjarmason | 31991b0 | 2010-07-05 17:33:03 +0000 | [diff] [blame] | 55 | git init addtest && |
| 56 | git init addtest-ignore |
Michael J Gruber | ac8463d | 2009-03-03 16:08:20 +0100 | [diff] [blame] | 57 | ' |
| 58 | |
Jonathan Nieder | a76c944 | 2010-04-10 00:39:04 -0500 | [diff] [blame] | 59 | # The 'submodule add' tests need some repository to add as a submodule. |
Jeff King | dd008b3 | 2011-07-30 09:05:54 -0600 | [diff] [blame] | 60 | # The trash directory is a good one as any. We need to canonicalize |
| 61 | # the name, though, as some tests compare it to the absolute path git |
| 62 | # generates, which will expand symbolic links. |
| 63 | submodurl=$(pwd -P) |
Jonathan Nieder | a76c944 | 2010-04-10 00:39:04 -0500 | [diff] [blame] | 64 | |
| 65 | listbranches() { |
| 66 | git for-each-ref --format='%(refname)' 'refs/heads/*' |
| 67 | } |
| 68 | |
| 69 | inspect() { |
| 70 | dir=$1 && |
| 71 | dotdot="${2:-..}" && |
| 72 | |
| 73 | ( |
| 74 | cd "$dir" && |
| 75 | listbranches >"$dotdot/heads" && |
| 76 | { git symbolic-ref HEAD || :; } >"$dotdot/head" && |
Jonathan Nieder | ce8b54d | 2010-04-10 00:39:41 -0500 | [diff] [blame] | 77 | git rev-parse HEAD >"$dotdot/head-sha1" && |
Jonathan Nieder | a76c944 | 2010-04-10 00:39:04 -0500 | [diff] [blame] | 78 | git update-index --refresh && |
| 79 | git diff-files --exit-code && |
| 80 | git clean -n -d -x >"$dotdot/untracked" |
| 81 | ) |
| 82 | } |
| 83 | |
Michael J Gruber | ac8463d | 2009-03-03 16:08:20 +0100 | [diff] [blame] | 84 | test_expect_success 'submodule add' ' |
Jonathan Nieder | a76c944 | 2010-04-10 00:39:04 -0500 | [diff] [blame] | 85 | echo "refs/heads/master" >expect && |
| 86 | >empty && |
| 87 | |
Michael J Gruber | ac8463d | 2009-03-03 16:08:20 +0100 | [diff] [blame] | 88 | ( |
| 89 | cd addtest && |
Jens Lehmann | 7e60407 | 2011-07-26 23:39:03 +0200 | [diff] [blame] | 90 | git submodule add -q "$submodurl" submod >actual && |
Junio C Hamano | ca8d148 | 2013-06-09 11:29:20 -0700 | [diff] [blame] | 91 | test_must_be_empty actual && |
Jens Lehmann | ea115a0 | 2012-03-04 22:14:30 +0100 | [diff] [blame] | 92 | echo "gitdir: ../.git/modules/submod" >expect && |
| 93 | test_cmp expect submod/.git && |
Jens Lehmann | d75219b | 2012-03-04 22:15:08 +0100 | [diff] [blame] | 94 | ( |
| 95 | cd submod && |
| 96 | git config core.worktree >actual && |
| 97 | echo "../../../submod" >expect && |
| 98 | test_cmp expect actual && |
| 99 | rm -f actual expect |
| 100 | ) && |
Michael J Gruber | ac8463d | 2009-03-03 16:08:20 +0100 | [diff] [blame] | 101 | git submodule init |
Jonathan Nieder | a76c944 | 2010-04-10 00:39:04 -0500 | [diff] [blame] | 102 | ) && |
| 103 | |
| 104 | rm -f heads head untracked && |
| 105 | inspect addtest/submod ../.. && |
| 106 | test_cmp expect heads && |
| 107 | test_cmp expect head && |
| 108 | test_cmp empty untracked |
Michael J Gruber | ac8463d | 2009-03-03 16:08:20 +0100 | [diff] [blame] | 109 | ' |
| 110 | |
Jens Lehmann | d27b876 | 2010-07-17 17:11:43 +0200 | [diff] [blame] | 111 | test_expect_success 'submodule add to .gitignored path fails' ' |
Ævar Arnfjörð Bjarmason | 31991b0 | 2010-07-05 17:33:03 +0000 | [diff] [blame] | 112 | ( |
| 113 | cd addtest-ignore && |
Jens Lehmann | d27b876 | 2010-07-17 17:11:43 +0200 | [diff] [blame] | 114 | cat <<-\EOF >expect && |
| 115 | The following path is ignored by one of your .gitignore files: |
| 116 | submod |
| 117 | Use -f if you really want to add it. |
| 118 | EOF |
Ævar Arnfjörð Bjarmason | 31991b0 | 2010-07-05 17:33:03 +0000 | [diff] [blame] | 119 | # Does not use test_commit due to the ignore |
| 120 | echo "*" > .gitignore && |
| 121 | git add --force .gitignore && |
| 122 | git commit -m"Ignore everything" && |
Jens Lehmann | d27b876 | 2010-07-17 17:11:43 +0200 | [diff] [blame] | 123 | ! git submodule add "$submodurl" submod >actual 2>&1 && |
Ævar Arnfjörð Bjarmason | 3a4c3ed | 2011-05-21 18:44:07 +0000 | [diff] [blame] | 124 | test_i18ncmp expect actual |
Jens Lehmann | d27b876 | 2010-07-17 17:11:43 +0200 | [diff] [blame] | 125 | ) |
| 126 | ' |
Ævar Arnfjörð Bjarmason | 31991b0 | 2010-07-05 17:33:03 +0000 | [diff] [blame] | 127 | |
Jens Lehmann | d27b876 | 2010-07-17 17:11:43 +0200 | [diff] [blame] | 128 | test_expect_success 'submodule add to .gitignored path with --force' ' |
| 129 | ( |
| 130 | cd addtest-ignore && |
| 131 | git submodule add --force "$submodurl" submod |
| 132 | ) |
Ævar Arnfjörð Bjarmason | 31991b0 | 2010-07-05 17:33:03 +0000 | [diff] [blame] | 133 | ' |
| 134 | |
Ben Jackson | ea10b60 | 2009-04-18 20:42:07 -0700 | [diff] [blame] | 135 | test_expect_success 'submodule add --branch' ' |
Jonathan Nieder | a76c944 | 2010-04-10 00:39:04 -0500 | [diff] [blame] | 136 | echo "refs/heads/initial" >expect-head && |
| 137 | cat <<-\EOF >expect-heads && |
| 138 | refs/heads/initial |
| 139 | refs/heads/master |
| 140 | EOF |
| 141 | >empty && |
| 142 | |
Ben Jackson | ea10b60 | 2009-04-18 20:42:07 -0700 | [diff] [blame] | 143 | ( |
| 144 | cd addtest && |
| 145 | git submodule add -b initial "$submodurl" submod-branch && |
W. Trevor King | b928922 | 2012-12-19 11:03:33 -0500 | [diff] [blame] | 146 | test "initial" = "$(git config -f .gitmodules submodule.submod-branch.branch)" && |
Jonathan Nieder | a76c944 | 2010-04-10 00:39:04 -0500 | [diff] [blame] | 147 | git submodule init |
| 148 | ) && |
| 149 | |
| 150 | rm -f heads head untracked && |
| 151 | inspect addtest/submod-branch ../.. && |
| 152 | test_cmp expect-heads heads && |
| 153 | test_cmp expect-head head && |
| 154 | test_cmp empty untracked |
Ben Jackson | ea10b60 | 2009-04-18 20:42:07 -0700 | [diff] [blame] | 155 | ' |
| 156 | |
Michael J Gruber | db75ada | 2009-03-03 16:08:21 +0100 | [diff] [blame] | 157 | test_expect_success 'submodule add with ./ in path' ' |
Jonathan Nieder | a76c944 | 2010-04-10 00:39:04 -0500 | [diff] [blame] | 158 | echo "refs/heads/master" >expect && |
| 159 | >empty && |
| 160 | |
Michael J Gruber | ac8463d | 2009-03-03 16:08:20 +0100 | [diff] [blame] | 161 | ( |
| 162 | cd addtest && |
| 163 | git submodule add "$submodurl" ././dotsubmod/./frotz/./ && |
| 164 | git submodule init |
Jonathan Nieder | a76c944 | 2010-04-10 00:39:04 -0500 | [diff] [blame] | 165 | ) && |
| 166 | |
| 167 | rm -f heads head untracked && |
| 168 | inspect addtest/dotsubmod/frotz ../../.. && |
| 169 | test_cmp expect heads && |
| 170 | test_cmp expect head && |
| 171 | test_cmp empty untracked |
Michael J Gruber | ac8463d | 2009-03-03 16:08:20 +0100 | [diff] [blame] | 172 | ' |
| 173 | |
Patrick Steinhardt | 8196e72 | 2015-01-30 16:14:03 +0100 | [diff] [blame] | 174 | test_expect_success 'submodule add with /././ in path' ' |
| 175 | echo "refs/heads/master" >expect && |
| 176 | >empty && |
| 177 | |
| 178 | ( |
| 179 | cd addtest && |
| 180 | git submodule add "$submodurl" dotslashdotsubmod/././frotz/./ && |
| 181 | git submodule init |
| 182 | ) && |
| 183 | |
| 184 | rm -f heads head untracked && |
| 185 | inspect addtest/dotslashdotsubmod/frotz ../../.. && |
| 186 | test_cmp expect heads && |
| 187 | test_cmp expect head && |
| 188 | test_cmp empty untracked |
| 189 | ' |
| 190 | |
Michael J Gruber | db75ada | 2009-03-03 16:08:21 +0100 | [diff] [blame] | 191 | test_expect_success 'submodule add with // in path' ' |
Jonathan Nieder | a76c944 | 2010-04-10 00:39:04 -0500 | [diff] [blame] | 192 | echo "refs/heads/master" >expect && |
| 193 | >empty && |
| 194 | |
Michael J Gruber | ac8463d | 2009-03-03 16:08:20 +0100 | [diff] [blame] | 195 | ( |
| 196 | cd addtest && |
| 197 | git submodule add "$submodurl" slashslashsubmod///frotz// && |
| 198 | git submodule init |
Jonathan Nieder | a76c944 | 2010-04-10 00:39:04 -0500 | [diff] [blame] | 199 | ) && |
| 200 | |
| 201 | rm -f heads head untracked && |
| 202 | inspect addtest/slashslashsubmod/frotz ../../.. && |
| 203 | test_cmp expect heads && |
| 204 | test_cmp expect head && |
| 205 | test_cmp empty untracked |
Michael J Gruber | ac8463d | 2009-03-03 16:08:20 +0100 | [diff] [blame] | 206 | ' |
| 207 | |
Michael J Gruber | db75ada | 2009-03-03 16:08:21 +0100 | [diff] [blame] | 208 | test_expect_success 'submodule add with /.. in path' ' |
Jonathan Nieder | a76c944 | 2010-04-10 00:39:04 -0500 | [diff] [blame] | 209 | echo "refs/heads/master" >expect && |
| 210 | >empty && |
| 211 | |
Michael J Gruber | ac8463d | 2009-03-03 16:08:20 +0100 | [diff] [blame] | 212 | ( |
| 213 | cd addtest && |
| 214 | git submodule add "$submodurl" dotdotsubmod/../realsubmod/frotz/.. && |
| 215 | git submodule init |
Jonathan Nieder | a76c944 | 2010-04-10 00:39:04 -0500 | [diff] [blame] | 216 | ) && |
| 217 | |
| 218 | rm -f heads head untracked && |
| 219 | inspect addtest/realsubmod ../.. && |
| 220 | test_cmp expect heads && |
| 221 | test_cmp expect head && |
| 222 | test_cmp empty untracked |
Michael J Gruber | ac8463d | 2009-03-03 16:08:20 +0100 | [diff] [blame] | 223 | ' |
| 224 | |
Michael J Gruber | db75ada | 2009-03-03 16:08:21 +0100 | [diff] [blame] | 225 | test_expect_success 'submodule add with ./, /.. and // in path' ' |
Jonathan Nieder | a76c944 | 2010-04-10 00:39:04 -0500 | [diff] [blame] | 226 | echo "refs/heads/master" >expect && |
| 227 | >empty && |
| 228 | |
Michael J Gruber | ac8463d | 2009-03-03 16:08:20 +0100 | [diff] [blame] | 229 | ( |
| 230 | cd addtest && |
| 231 | git submodule add "$submodurl" dot/dotslashsubmod/./../..////realsubmod2/a/b/c/d/../../../../frotz//.. && |
| 232 | git submodule init |
Jonathan Nieder | a76c944 | 2010-04-10 00:39:04 -0500 | [diff] [blame] | 233 | ) && |
| 234 | |
| 235 | rm -f heads head untracked && |
| 236 | inspect addtest/realsubmod2 ../.. && |
| 237 | test_cmp expect heads && |
| 238 | test_cmp expect head && |
| 239 | test_cmp empty untracked |
Michael J Gruber | ac8463d | 2009-03-03 16:08:20 +0100 | [diff] [blame] | 240 | ' |
| 241 | |
John Keeping | 091a6eb | 2013-06-16 15:18:18 +0100 | [diff] [blame] | 242 | test_expect_success 'submodule add in subdirectory' ' |
| 243 | echo "refs/heads/master" >expect && |
| 244 | >empty && |
| 245 | |
| 246 | mkdir addtest/sub && |
| 247 | ( |
| 248 | cd addtest/sub && |
| 249 | git submodule add "$submodurl" ../realsubmod3 && |
| 250 | git submodule init |
| 251 | ) && |
| 252 | |
| 253 | rm -f heads head untracked && |
| 254 | inspect addtest/realsubmod3 ../.. && |
| 255 | test_cmp expect heads && |
| 256 | test_cmp expect head && |
| 257 | test_cmp empty untracked |
| 258 | ' |
| 259 | |
| 260 | test_expect_success 'submodule add in subdirectory with relative path should fail' ' |
| 261 | ( |
| 262 | cd addtest/sub && |
| 263 | test_must_fail git submodule add ../../ submod3 2>../../output.err |
| 264 | ) && |
| 265 | test_i18ngrep toplevel output.err |
| 266 | ' |
| 267 | |
Jonathan Nieder | ce8b54d | 2010-04-10 00:39:41 -0500 | [diff] [blame] | 268 | test_expect_success 'setup - add an example entry to .gitmodules' ' |
Jeff King | f7e8714 | 2014-03-20 19:17:01 -0400 | [diff] [blame] | 269 | git config --file=.gitmodules submodule.example.url git://example.com/init.git |
Jonathan Nieder | ce8b54d | 2010-04-10 00:39:41 -0500 | [diff] [blame] | 270 | ' |
| 271 | |
Lars Hjemli | 941987a | 2007-06-11 21:12:24 +0200 | [diff] [blame] | 272 | test_expect_success 'status should fail for unmapped paths' ' |
Jonathan Nieder | ce8b54d | 2010-04-10 00:39:41 -0500 | [diff] [blame] | 273 | test_must_fail git submodule status |
| 274 | ' |
| 275 | |
| 276 | test_expect_success 'setup - map path in .gitmodules' ' |
| 277 | cat <<\EOF >expect && |
| 278 | [submodule "example"] |
| 279 | url = git://example.com/init.git |
| 280 | path = init |
| 281 | EOF |
| 282 | |
Jeff King | f7e8714 | 2014-03-20 19:17:01 -0400 | [diff] [blame] | 283 | git config --file=.gitmodules submodule.example.path init && |
Jonathan Nieder | ce8b54d | 2010-04-10 00:39:41 -0500 | [diff] [blame] | 284 | |
| 285 | test_cmp expect .gitmodules |
Lars Hjemli | 88961ef | 2007-06-02 03:27:42 +0200 | [diff] [blame] | 286 | ' |
| 287 | |
| 288 | test_expect_success 'status should only print one line' ' |
Jonathan Nieder | ce8b54d | 2010-04-10 00:39:41 -0500 | [diff] [blame] | 289 | git submodule status >lines && |
Stefano Lattarini | 3fb0459 | 2012-04-11 13:24:01 +0200 | [diff] [blame] | 290 | test_line_count = 1 lines |
Jonathan Nieder | ce8b54d | 2010-04-10 00:39:41 -0500 | [diff] [blame] | 291 | ' |
| 292 | |
| 293 | test_expect_success 'setup - fetch commit name from submodule' ' |
| 294 | rev1=$(cd .subrepo && git rev-parse HEAD) && |
| 295 | printf "rev1: %s\n" "$rev1" && |
| 296 | test -n "$rev1" |
Lars Hjemli | 88961ef | 2007-06-02 03:27:42 +0200 | [diff] [blame] | 297 | ' |
| 298 | |
| 299 | test_expect_success 'status should initially be "missing"' ' |
Jonathan Nieder | ce8b54d | 2010-04-10 00:39:41 -0500 | [diff] [blame] | 300 | git submodule status >lines && |
| 301 | grep "^-$rev1" lines |
Lars Hjemli | 88961ef | 2007-06-02 03:27:42 +0200 | [diff] [blame] | 302 | ' |
| 303 | |
Lars Hjemli | 211b7f1 | 2007-06-06 11:13:02 +0200 | [diff] [blame] | 304 | test_expect_success 'init should register submodule url in .git/config' ' |
Jonathan Nieder | ce8b54d | 2010-04-10 00:39:41 -0500 | [diff] [blame] | 305 | echo git://example.com/init.git >expect && |
| 306 | |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 307 | git submodule init && |
Jonathan Nieder | ce8b54d | 2010-04-10 00:39:41 -0500 | [diff] [blame] | 308 | git config submodule.example.url >url && |
| 309 | git config submodule.example.url ./.subrepo && |
| 310 | |
| 311 | test_cmp expect url |
Lars Hjemli | 211b7f1 | 2007-06-06 11:13:02 +0200 | [diff] [blame] | 312 | ' |
| 313 | |
Heiko Voigt | be9d0a3 | 2012-08-14 22:35:27 +0200 | [diff] [blame] | 314 | test_failure_with_unknown_submodule () { |
| 315 | test_must_fail git submodule $1 no-such-submodule 2>output.err && |
| 316 | grep "^error: .*no-such-submodule" output.err |
| 317 | } |
| 318 | |
| 319 | test_expect_success 'init should fail with unknown submodule' ' |
| 320 | test_failure_with_unknown_submodule init |
| 321 | ' |
| 322 | |
| 323 | test_expect_success 'update should fail with unknown submodule' ' |
| 324 | test_failure_with_unknown_submodule update |
| 325 | ' |
| 326 | |
| 327 | test_expect_success 'status should fail with unknown submodule' ' |
| 328 | test_failure_with_unknown_submodule status |
| 329 | ' |
| 330 | |
| 331 | test_expect_success 'sync should fail with unknown submodule' ' |
| 332 | test_failure_with_unknown_submodule sync |
| 333 | ' |
| 334 | |
Lars Hjemli | 211b7f1 | 2007-06-06 11:13:02 +0200 | [diff] [blame] | 335 | test_expect_success 'update should fail when path is used by a file' ' |
Jonathan Nieder | ce8b54d | 2010-04-10 00:39:41 -0500 | [diff] [blame] | 336 | echo hello >expect && |
| 337 | |
Junio C Hamano | a2d93ae | 2008-01-15 03:13:55 -0800 | [diff] [blame] | 338 | echo "hello" >init && |
Jonathan Nieder | ce8b54d | 2010-04-10 00:39:41 -0500 | [diff] [blame] | 339 | test_must_fail git submodule update && |
| 340 | |
| 341 | test_cmp expect init |
Lars Hjemli | 88961ef | 2007-06-02 03:27:42 +0200 | [diff] [blame] | 342 | ' |
| 343 | |
Lars Hjemli | 211b7f1 | 2007-06-06 11:13:02 +0200 | [diff] [blame] | 344 | test_expect_success 'update should fail when path is used by a nonempty directory' ' |
Jonathan Nieder | ce8b54d | 2010-04-10 00:39:41 -0500 | [diff] [blame] | 345 | echo hello >expect && |
| 346 | |
| 347 | rm -fr init && |
Junio C Hamano | a2d93ae | 2008-01-15 03:13:55 -0800 | [diff] [blame] | 348 | mkdir init && |
| 349 | echo "hello" >init/a && |
Jonathan Nieder | ce8b54d | 2010-04-10 00:39:41 -0500 | [diff] [blame] | 350 | |
| 351 | test_must_fail git submodule update && |
| 352 | |
| 353 | test_cmp expect init/a |
Lars Hjemli | 88961ef | 2007-06-02 03:27:42 +0200 | [diff] [blame] | 354 | ' |
| 355 | |
Lars Hjemli | 211b7f1 | 2007-06-06 11:13:02 +0200 | [diff] [blame] | 356 | test_expect_success 'update should work when path is an empty dir' ' |
Jonathan Nieder | ce8b54d | 2010-04-10 00:39:41 -0500 | [diff] [blame] | 357 | rm -fr init && |
| 358 | rm -f head-sha1 && |
| 359 | echo "$rev1" >expect && |
| 360 | |
Junio C Hamano | a2d93ae | 2008-01-15 03:13:55 -0800 | [diff] [blame] | 361 | mkdir init && |
Jens Lehmann | 7e60407 | 2011-07-26 23:39:03 +0200 | [diff] [blame] | 362 | git submodule update -q >update.out && |
Junio C Hamano | ca8d148 | 2013-06-09 11:29:20 -0700 | [diff] [blame] | 363 | test_must_be_empty update.out && |
Jonathan Nieder | ce8b54d | 2010-04-10 00:39:41 -0500 | [diff] [blame] | 364 | |
| 365 | inspect init && |
| 366 | test_cmp expect head-sha1 |
Lars Hjemli | 88961ef | 2007-06-02 03:27:42 +0200 | [diff] [blame] | 367 | ' |
| 368 | |
Lars Hjemli | 211b7f1 | 2007-06-06 11:13:02 +0200 | [diff] [blame] | 369 | test_expect_success 'status should be "up-to-date" after update' ' |
Jonathan Nieder | ce8b54d | 2010-04-10 00:39:41 -0500 | [diff] [blame] | 370 | git submodule status >list && |
| 371 | grep "^ $rev1" list |
Lars Hjemli | 88961ef | 2007-06-02 03:27:42 +0200 | [diff] [blame] | 372 | ' |
| 373 | |
John Keeping | 091a6eb | 2013-06-16 15:18:18 +0100 | [diff] [blame] | 374 | test_expect_success 'status "up-to-date" from subdirectory' ' |
| 375 | mkdir -p sub && |
| 376 | ( |
| 377 | cd sub && |
| 378 | git submodule status >../list |
| 379 | ) && |
| 380 | grep "^ $rev1" list && |
| 381 | grep "\\.\\./init" list |
| 382 | ' |
| 383 | |
| 384 | test_expect_success 'status "up-to-date" from subdirectory with path' ' |
| 385 | mkdir -p sub && |
| 386 | ( |
| 387 | cd sub && |
| 388 | git submodule status ../init >../list |
| 389 | ) && |
| 390 | grep "^ $rev1" list && |
| 391 | grep "\\.\\./init" list |
| 392 | ' |
| 393 | |
Lars Hjemli | 88961ef | 2007-06-02 03:27:42 +0200 | [diff] [blame] | 394 | test_expect_success 'status should be "modified" after submodule commit' ' |
Jonathan Nieder | ce8b54d | 2010-04-10 00:39:41 -0500 | [diff] [blame] | 395 | ( |
| 396 | cd init && |
| 397 | echo b >b && |
| 398 | git add b && |
| 399 | git commit -m "submodule commit 2" |
| 400 | ) && |
| 401 | |
| 402 | rev2=$(cd init && git rev-parse HEAD) && |
| 403 | test -n "$rev2" && |
| 404 | git submodule status >list && |
| 405 | |
| 406 | grep "^+$rev2" list |
Lars Hjemli | 88961ef | 2007-06-02 03:27:42 +0200 | [diff] [blame] | 407 | ' |
| 408 | |
| 409 | test_expect_success 'the --cached sha1 should be rev1' ' |
Jonathan Nieder | ce8b54d | 2010-04-10 00:39:41 -0500 | [diff] [blame] | 410 | git submodule --cached status >list && |
| 411 | grep "^+$rev1" list |
Lars Hjemli | 88961ef | 2007-06-02 03:27:42 +0200 | [diff] [blame] | 412 | ' |
| 413 | |
Sven Verdoolaege | 5701115 | 2007-09-08 12:30:22 +0200 | [diff] [blame] | 414 | test_expect_success 'git diff should report the SHA1 of the new submodule commit' ' |
Jonathan Nieder | ce8b54d | 2010-04-10 00:39:41 -0500 | [diff] [blame] | 415 | git diff >diff && |
| 416 | grep "^+Subproject commit $rev2" diff |
Sven Verdoolaege | 5701115 | 2007-09-08 12:30:22 +0200 | [diff] [blame] | 417 | ' |
| 418 | |
Lars Hjemli | 88961ef | 2007-06-02 03:27:42 +0200 | [diff] [blame] | 419 | test_expect_success 'update should checkout rev1' ' |
Jonathan Nieder | ce8b54d | 2010-04-10 00:39:41 -0500 | [diff] [blame] | 420 | rm -f head-sha1 && |
| 421 | echo "$rev1" >expect && |
| 422 | |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 423 | git submodule update init && |
Jonathan Nieder | ce8b54d | 2010-04-10 00:39:41 -0500 | [diff] [blame] | 424 | inspect init && |
| 425 | |
| 426 | test_cmp expect head-sha1 |
Lars Hjemli | 88961ef | 2007-06-02 03:27:42 +0200 | [diff] [blame] | 427 | ' |
| 428 | |
| 429 | test_expect_success 'status should be "up-to-date" after update' ' |
Jonathan Nieder | ce8b54d | 2010-04-10 00:39:41 -0500 | [diff] [blame] | 430 | git submodule status >list && |
| 431 | grep "^ $rev1" list |
Lars Hjemli | 88961ef | 2007-06-02 03:27:42 +0200 | [diff] [blame] | 432 | ' |
| 433 | |
Sven Verdoolaege | 0cf7375 | 2007-07-17 20:28:28 +0200 | [diff] [blame] | 434 | test_expect_success 'checkout superproject with subproject already present' ' |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 435 | git checkout initial && |
| 436 | git checkout master |
Sven Verdoolaege | 0cf7375 | 2007-07-17 20:28:28 +0200 | [diff] [blame] | 437 | ' |
| 438 | |
Sven Verdoolaege | e06c5a6 | 2007-08-15 19:22:09 +0200 | [diff] [blame] | 439 | test_expect_success 'apply submodule diff' ' |
Jonathan Nieder | ce8b54d | 2010-04-10 00:39:41 -0500 | [diff] [blame] | 440 | >empty && |
| 441 | |
Sven Verdoolaege | e06c5a6 | 2007-08-15 19:22:09 +0200 | [diff] [blame] | 442 | git branch second && |
| 443 | ( |
Junio C Hamano | a2d93ae | 2008-01-15 03:13:55 -0800 | [diff] [blame] | 444 | cd init && |
Sven Verdoolaege | e06c5a6 | 2007-08-15 19:22:09 +0200 | [diff] [blame] | 445 | echo s >s && |
| 446 | git add s && |
| 447 | git commit -m "change subproject" |
| 448 | ) && |
Junio C Hamano | a2d93ae | 2008-01-15 03:13:55 -0800 | [diff] [blame] | 449 | git update-index --add init && |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 450 | git commit -m "change init" && |
| 451 | git format-patch -1 --stdout >P.diff && |
Sven Verdoolaege | e06c5a6 | 2007-08-15 19:22:09 +0200 | [diff] [blame] | 452 | git checkout second && |
| 453 | git apply --index P.diff && |
Jonathan Nieder | ce8b54d | 2010-04-10 00:39:41 -0500 | [diff] [blame] | 454 | |
| 455 | git diff --cached master >staged && |
| 456 | test_cmp empty staged |
Sven Verdoolaege | e06c5a6 | 2007-08-15 19:22:09 +0200 | [diff] [blame] | 457 | ' |
| 458 | |
Johannes Schindelin | be4d2c8 | 2008-05-16 11:23:03 +0100 | [diff] [blame] | 459 | test_expect_success 'update --init' ' |
Johannes Schindelin | be4d2c8 | 2008-05-16 11:23:03 +0100 | [diff] [blame] | 460 | mv init init2 && |
| 461 | git config -f .gitmodules submodule.example.url "$(pwd)/init2" && |
Jonathan Nieder | ce8b54d | 2010-04-10 00:39:41 -0500 | [diff] [blame] | 462 | git config --remove-section submodule.example && |
| 463 | test_must_fail git config submodule.example.url && |
| 464 | |
Johannes Schindelin | be4d2c8 | 2008-05-16 11:23:03 +0100 | [diff] [blame] | 465 | git submodule update init > update.out && |
Jonathan Nieder | ce8b54d | 2010-04-10 00:39:41 -0500 | [diff] [blame] | 466 | cat update.out && |
Ævar Arnfjörð Bjarmason | 1c2ef66 | 2011-05-21 18:44:08 +0000 | [diff] [blame] | 467 | test_i18ngrep "not initialized" update.out && |
Fredrik Gustafsson | abc0682 | 2011-08-15 23:17:46 +0200 | [diff] [blame] | 468 | test_must_fail git rev-parse --resolve-git-dir init/.git && |
Jonathan Nieder | ce8b54d | 2010-04-10 00:39:41 -0500 | [diff] [blame] | 469 | |
Johannes Schindelin | be4d2c8 | 2008-05-16 11:23:03 +0100 | [diff] [blame] | 470 | git submodule update --init init && |
Fredrik Gustafsson | abc0682 | 2011-08-15 23:17:46 +0200 | [diff] [blame] | 471 | git rev-parse --resolve-git-dir init/.git |
Johannes Schindelin | be4d2c8 | 2008-05-16 11:23:03 +0100 | [diff] [blame] | 472 | ' |
| 473 | |
John Keeping | 091a6eb | 2013-06-16 15:18:18 +0100 | [diff] [blame] | 474 | test_expect_success 'update --init from subdirectory' ' |
| 475 | mv init init2 && |
| 476 | git config -f .gitmodules submodule.example.url "$(pwd)/init2" && |
| 477 | git config --remove-section submodule.example && |
| 478 | test_must_fail git config submodule.example.url && |
| 479 | |
| 480 | mkdir -p sub && |
| 481 | ( |
| 482 | cd sub && |
| 483 | git submodule update ../init >update.out && |
| 484 | cat update.out && |
| 485 | test_i18ngrep "not initialized" update.out && |
| 486 | test_must_fail git rev-parse --resolve-git-dir ../init/.git && |
| 487 | |
| 488 | git submodule update --init ../init |
| 489 | ) && |
| 490 | git rev-parse --resolve-git-dir init/.git |
| 491 | ' |
| 492 | |
Johannes Schindelin | 2ce53f9 | 2009-01-02 19:08:40 +0100 | [diff] [blame] | 493 | test_expect_success 'do not add files from a submodule' ' |
| 494 | |
| 495 | git reset --hard && |
| 496 | test_must_fail git add init/a |
| 497 | |
| 498 | ' |
| 499 | |
John Keeping | 2c63d6e | 2013-09-12 20:25:01 +0100 | [diff] [blame] | 500 | test_expect_success 'gracefully add/reset submodule with a trailing slash' ' |
Johannes Schindelin | 2ce53f9 | 2009-01-02 19:08:40 +0100 | [diff] [blame] | 501 | |
| 502 | git reset --hard && |
| 503 | git commit -m "commit subproject" init && |
| 504 | (cd init && |
| 505 | echo b > a) && |
| 506 | git add init/ && |
| 507 | git diff --exit-code --cached init && |
| 508 | commit=$(cd init && |
| 509 | git commit -m update a >/dev/null && |
| 510 | git rev-parse HEAD) && |
| 511 | git add init/ && |
| 512 | test_must_fail git diff --exit-code --cached init && |
| 513 | test $commit = $(git ls-files --stage | |
John Keeping | 2c63d6e | 2013-09-12 20:25:01 +0100 | [diff] [blame] | 514 | sed -n "s/^160000 \([^ ]*\).*/\1/p") && |
| 515 | git reset init/ && |
| 516 | git diff --exit-code --cached init |
Johannes Schindelin | 2ce53f9 | 2009-01-02 19:08:40 +0100 | [diff] [blame] | 517 | |
| 518 | ' |
| 519 | |
Johannes Schindelin | f3670a5 | 2009-02-07 14:43:03 +0100 | [diff] [blame] | 520 | test_expect_success 'ls-files gracefully handles trailing slash' ' |
| 521 | |
| 522 | test "init" = "$(git ls-files init/)" |
| 523 | |
| 524 | ' |
| 525 | |
Peter Collingbourne | c5e558a | 2010-01-11 02:59:54 +0000 | [diff] [blame] | 526 | test_expect_success 'moving to a commit without submodule does not leave empty dir' ' |
| 527 | rm -rf init && |
| 528 | mkdir init && |
| 529 | git reset --hard && |
| 530 | git checkout initial && |
| 531 | test ! -d init && |
| 532 | git checkout second |
| 533 | ' |
| 534 | |
Ramkumar Ramachandra | af9c9f9 | 2012-09-22 16:57:59 +0530 | [diff] [blame] | 535 | test_expect_success 'submodule <invalid-subcommand> fails' ' |
| 536 | test_must_fail git submodule no-such-subcommand |
Johannes Schindelin | 496917b | 2009-02-07 14:43:15 +0100 | [diff] [blame] | 537 | ' |
| 538 | |
Jens Lehmann | 1414e57 | 2009-09-22 17:10:12 +0200 | [diff] [blame] | 539 | test_expect_success 'add submodules without specifying an explicit path' ' |
| 540 | mkdir repo && |
Jonathan Nieder | 18a8269 | 2010-09-06 20:42:54 -0500 | [diff] [blame] | 541 | ( |
| 542 | cd repo && |
| 543 | git init && |
| 544 | echo r >r && |
| 545 | git add r && |
| 546 | git commit -m "repo commit 1" |
Jens Lehmann | fd4ec4f | 2010-09-06 20:39:54 +0200 | [diff] [blame] | 547 | ) && |
Jens Lehmann | 1414e57 | 2009-09-22 17:10:12 +0200 | [diff] [blame] | 548 | git clone --bare repo/ bare.git && |
Jens Lehmann | 69e7236 | 2010-12-05 00:27:35 +0100 | [diff] [blame] | 549 | ( |
| 550 | cd addtest && |
| 551 | git submodule add "$submodurl/repo" && |
| 552 | git config -f .gitmodules submodule.repo.path repo && |
| 553 | git submodule add "$submodurl/bare.git" && |
| 554 | git config -f .gitmodules submodule.bare.path bare |
| 555 | ) |
| 556 | ' |
| 557 | |
| 558 | test_expect_success 'add should fail when path is used by a file' ' |
| 559 | ( |
| 560 | cd addtest && |
| 561 | touch file && |
| 562 | test_must_fail git submodule add "$submodurl/repo" file |
| 563 | ) |
| 564 | ' |
| 565 | |
| 566 | test_expect_success 'add should fail when path is used by an existing directory' ' |
| 567 | ( |
| 568 | cd addtest && |
| 569 | mkdir empty-dir && |
| 570 | test_must_fail git submodule add "$submodurl/repo" empty-dir |
| 571 | ) |
Jens Lehmann | 1414e57 | 2009-09-22 17:10:12 +0200 | [diff] [blame] | 572 | ' |
| 573 | |
Jens Lehmann | 4d68932 | 2011-06-06 21:58:04 +0200 | [diff] [blame] | 574 | test_expect_success 'use superproject as upstream when path is relative and no url is set there' ' |
Jens Lehmann | 8537f0e | 2011-06-06 21:57:01 +0200 | [diff] [blame] | 575 | ( |
| 576 | cd addtest && |
Jens Lehmann | 4d68932 | 2011-06-06 21:58:04 +0200 | [diff] [blame] | 577 | git submodule add ../repo relative && |
| 578 | test "$(git config -f .gitmodules submodule.relative.url)" = ../repo && |
| 579 | git submodule sync relative && |
| 580 | test "$(git config submodule.relative.url)" = "$submodurl/repo" |
Jens Lehmann | 8537f0e | 2011-06-06 21:57:01 +0200 | [diff] [blame] | 581 | ) |
| 582 | ' |
| 583 | |
Thomas Rast | ea640cc | 2011-01-10 11:37:26 +0100 | [diff] [blame] | 584 | test_expect_success 'set up for relative path tests' ' |
| 585 | mkdir reltest && |
| 586 | ( |
| 587 | cd reltest && |
| 588 | git init && |
| 589 | mkdir sub && |
| 590 | ( |
| 591 | cd sub && |
| 592 | git init && |
| 593 | test_commit foo |
| 594 | ) && |
| 595 | git add sub && |
| 596 | git config -f .gitmodules submodule.sub.path sub && |
| 597 | git config -f .gitmodules submodule.sub.url ../subrepo && |
Jon Seymour | 712693e | 2012-06-03 19:46:47 +1000 | [diff] [blame] | 598 | cp .git/config pristine-.git-config && |
| 599 | cp .gitmodules pristine-.gitmodules |
Thomas Rast | ea640cc | 2011-01-10 11:37:26 +0100 | [diff] [blame] | 600 | ) |
| 601 | ' |
| 602 | |
Jon Seymour | 712693e | 2012-06-03 19:46:47 +1000 | [diff] [blame] | 603 | test_expect_success '../subrepo works with URL - ssh://hostname/repo' ' |
Thomas Rast | ea640cc | 2011-01-10 11:37:26 +0100 | [diff] [blame] | 604 | ( |
| 605 | cd reltest && |
| 606 | cp pristine-.git-config .git/config && |
Jon Seymour | 712693e | 2012-06-03 19:46:47 +1000 | [diff] [blame] | 607 | cp pristine-.gitmodules .gitmodules && |
Thomas Rast | ea640cc | 2011-01-10 11:37:26 +0100 | [diff] [blame] | 608 | git config remote.origin.url ssh://hostname/repo && |
| 609 | git submodule init && |
| 610 | test "$(git config submodule.sub.url)" = ssh://hostname/subrepo |
| 611 | ) |
| 612 | ' |
| 613 | |
Jon Seymour | 712693e | 2012-06-03 19:46:47 +1000 | [diff] [blame] | 614 | test_expect_success '../subrepo works with port-qualified URL - ssh://hostname:22/repo' ' |
| 615 | ( |
| 616 | cd reltest && |
| 617 | cp pristine-.git-config .git/config && |
| 618 | cp pristine-.gitmodules .gitmodules && |
| 619 | git config remote.origin.url ssh://hostname:22/repo && |
| 620 | git submodule init && |
| 621 | test "$(git config submodule.sub.url)" = ssh://hostname:22/subrepo |
| 622 | ) |
| 623 | ' |
| 624 | |
Johannes Sixt | c517e73 | 2012-06-14 14:10:27 +0200 | [diff] [blame] | 625 | # About the choice of the path in the next test: |
| 626 | # - double-slash side-steps path mangling issues on Windows |
| 627 | # - it is still an absolute local path |
| 628 | # - there cannot be a server with a blank in its name just in case the |
| 629 | # path is used erroneously to access a //server/share style path |
| 630 | test_expect_success '../subrepo path works with local path - //somewhere else/repo' ' |
Jon Seymour | 712693e | 2012-06-03 19:46:47 +1000 | [diff] [blame] | 631 | ( |
| 632 | cd reltest && |
| 633 | cp pristine-.git-config .git/config && |
| 634 | cp pristine-.gitmodules .gitmodules && |
Johannes Sixt | c517e73 | 2012-06-14 14:10:27 +0200 | [diff] [blame] | 635 | git config remote.origin.url "//somewhere else/repo" && |
Jon Seymour | 712693e | 2012-06-03 19:46:47 +1000 | [diff] [blame] | 636 | git submodule init && |
Johannes Sixt | c517e73 | 2012-06-14 14:10:27 +0200 | [diff] [blame] | 637 | test "$(git config submodule.sub.url)" = "//somewhere else/subrepo" |
Jon Seymour | 712693e | 2012-06-03 19:46:47 +1000 | [diff] [blame] | 638 | ) |
| 639 | ' |
| 640 | |
| 641 | test_expect_success '../subrepo works with file URL - file:///tmp/repo' ' |
| 642 | ( |
| 643 | cd reltest && |
| 644 | cp pristine-.git-config .git/config && |
| 645 | cp pristine-.gitmodules .gitmodules && |
| 646 | git config remote.origin.url file:///tmp/repo && |
| 647 | git submodule init && |
| 648 | test "$(git config submodule.sub.url)" = file:///tmp/subrepo |
| 649 | ) |
| 650 | ' |
| 651 | |
| 652 | test_expect_success '../subrepo works with helper URL- helper:://hostname/repo' ' |
| 653 | ( |
| 654 | cd reltest && |
| 655 | cp pristine-.git-config .git/config && |
| 656 | cp pristine-.gitmodules .gitmodules && |
| 657 | git config remote.origin.url helper:://hostname/repo && |
| 658 | git submodule init && |
| 659 | test "$(git config submodule.sub.url)" = helper:://hostname/subrepo |
| 660 | ) |
| 661 | ' |
| 662 | |
| 663 | test_expect_success '../subrepo works with scp-style URL - user@host:repo' ' |
Thomas Rast | ea640cc | 2011-01-10 11:37:26 +0100 | [diff] [blame] | 664 | ( |
| 665 | cd reltest && |
| 666 | cp pristine-.git-config .git/config && |
| 667 | git config remote.origin.url user@host:repo && |
| 668 | git submodule init && |
| 669 | test "$(git config submodule.sub.url)" = user@host:subrepo |
| 670 | ) |
| 671 | ' |
| 672 | |
Jon Seymour | 712693e | 2012-06-03 19:46:47 +1000 | [diff] [blame] | 673 | test_expect_success '../subrepo works with scp-style URL - user@host:path/to/repo' ' |
| 674 | ( |
| 675 | cd reltest && |
| 676 | cp pristine-.git-config .git/config && |
| 677 | cp pristine-.gitmodules .gitmodules && |
| 678 | git config remote.origin.url user@host:path/to/repo && |
| 679 | git submodule init && |
| 680 | test "$(git config submodule.sub.url)" = user@host:path/to/subrepo |
| 681 | ) |
| 682 | ' |
| 683 | |
Jon Seymour | 758615e | 2012-06-06 21:57:30 +1000 | [diff] [blame] | 684 | test_expect_success '../subrepo works with relative local path - foo' ' |
Jon Seymour | 49301c6 | 2012-06-03 19:46:48 +1000 | [diff] [blame] | 685 | ( |
| 686 | cd reltest && |
| 687 | cp pristine-.git-config .git/config && |
| 688 | cp pristine-.gitmodules .gitmodules && |
| 689 | git config remote.origin.url foo && |
| 690 | # actual: fails with an error |
| 691 | git submodule init && |
| 692 | test "$(git config submodule.sub.url)" = subrepo |
| 693 | ) |
| 694 | ' |
| 695 | |
Jon Seymour | 712693e | 2012-06-03 19:46:47 +1000 | [diff] [blame] | 696 | test_expect_success '../subrepo works with relative local path - foo/bar' ' |
| 697 | ( |
| 698 | cd reltest && |
| 699 | cp pristine-.git-config .git/config && |
| 700 | cp pristine-.gitmodules .gitmodules && |
| 701 | git config remote.origin.url foo/bar && |
| 702 | git submodule init && |
| 703 | test "$(git config submodule.sub.url)" = foo/subrepo |
| 704 | ) |
| 705 | ' |
| 706 | |
Jon Seymour | 758615e | 2012-06-06 21:57:30 +1000 | [diff] [blame] | 707 | test_expect_success '../subrepo works with relative local path - ./foo' ' |
Jon Seymour | 49301c6 | 2012-06-03 19:46:48 +1000 | [diff] [blame] | 708 | ( |
| 709 | cd reltest && |
| 710 | cp pristine-.git-config .git/config && |
| 711 | cp pristine-.gitmodules .gitmodules && |
| 712 | git config remote.origin.url ./foo && |
| 713 | git submodule init && |
| 714 | test "$(git config submodule.sub.url)" = subrepo |
| 715 | ) |
| 716 | ' |
| 717 | |
Jon Seymour | 758615e | 2012-06-06 21:57:30 +1000 | [diff] [blame] | 718 | test_expect_success '../subrepo works with relative local path - ./foo/bar' ' |
Jon Seymour | 49301c6 | 2012-06-03 19:46:48 +1000 | [diff] [blame] | 719 | ( |
| 720 | cd reltest && |
| 721 | cp pristine-.git-config .git/config && |
| 722 | cp pristine-.gitmodules .gitmodules && |
| 723 | git config remote.origin.url ./foo/bar && |
| 724 | git submodule init && |
| 725 | test "$(git config submodule.sub.url)" = foo/subrepo |
| 726 | ) |
| 727 | ' |
| 728 | |
Jon Seymour | 712693e | 2012-06-03 19:46:47 +1000 | [diff] [blame] | 729 | test_expect_success '../subrepo works with relative local path - ../foo' ' |
| 730 | ( |
| 731 | cd reltest && |
| 732 | cp pristine-.git-config .git/config && |
| 733 | cp pristine-.gitmodules .gitmodules && |
| 734 | git config remote.origin.url ../foo && |
| 735 | git submodule init && |
| 736 | test "$(git config submodule.sub.url)" = ../subrepo |
| 737 | ) |
| 738 | ' |
| 739 | |
| 740 | test_expect_success '../subrepo works with relative local path - ../foo/bar' ' |
| 741 | ( |
| 742 | cd reltest && |
| 743 | cp pristine-.git-config .git/config && |
| 744 | cp pristine-.gitmodules .gitmodules && |
| 745 | git config remote.origin.url ../foo/bar && |
| 746 | git submodule init && |
| 747 | test "$(git config submodule.sub.url)" = ../foo/subrepo |
| 748 | ) |
| 749 | ' |
| 750 | |
| 751 | test_expect_success '../bar/a/b/c works with relative local path - ../foo/bar.git' ' |
| 752 | ( |
| 753 | cd reltest && |
| 754 | cp pristine-.git-config .git/config && |
| 755 | cp pristine-.gitmodules .gitmodules && |
| 756 | mkdir -p a/b/c && |
| 757 | (cd a/b/c; git init) && |
| 758 | git config remote.origin.url ../foo/bar.git && |
| 759 | git submodule add ../bar/a/b/c ./a/b/c && |
| 760 | git submodule init && |
| 761 | test "$(git config submodule.a/b/c.url)" = ../foo/bar/a/b/c |
| 762 | ) |
| 763 | ' |
| 764 | |
Jens Lehmann | d75219b | 2012-03-04 22:15:08 +0100 | [diff] [blame] | 765 | test_expect_success 'moving the superproject does not break submodules' ' |
| 766 | ( |
| 767 | cd addtest && |
| 768 | git submodule status >expect |
| 769 | ) |
| 770 | mv addtest addtest2 && |
| 771 | ( |
| 772 | cd addtest2 && |
| 773 | git submodule status >actual && |
| 774 | test_cmp expect actual |
| 775 | ) |
| 776 | ' |
| 777 | |
Jens Lehmann | 73b0898 | 2012-09-30 01:05:58 +0200 | [diff] [blame] | 778 | test_expect_success 'submodule add --name allows to replace a submodule with another at the same path' ' |
| 779 | ( |
| 780 | cd addtest2 && |
| 781 | ( |
| 782 | cd repo && |
| 783 | echo "$submodurl/repo" >expect && |
| 784 | git config remote.origin.url >actual && |
| 785 | test_cmp expect actual && |
| 786 | echo "gitdir: ../.git/modules/repo" >expect && |
| 787 | test_cmp expect .git |
| 788 | ) && |
| 789 | rm -rf repo && |
| 790 | git rm repo && |
| 791 | git submodule add -q --name repo_new "$submodurl/bare.git" repo >actual && |
Junio C Hamano | ca8d148 | 2013-06-09 11:29:20 -0700 | [diff] [blame] | 792 | test_must_be_empty actual && |
Jens Lehmann | 73b0898 | 2012-09-30 01:05:58 +0200 | [diff] [blame] | 793 | echo "gitdir: ../.git/modules/submod" >expect && |
| 794 | test_cmp expect submod/.git && |
| 795 | ( |
| 796 | cd repo && |
| 797 | echo "$submodurl/bare.git" >expect && |
| 798 | git config remote.origin.url >actual && |
| 799 | test_cmp expect actual && |
| 800 | echo "gitdir: ../.git/modules/repo_new" >expect && |
| 801 | test_cmp expect .git |
| 802 | ) && |
| 803 | echo "repo" >expect && |
Jens Lehmann | 95c1641 | 2013-08-06 21:15:25 +0200 | [diff] [blame] | 804 | test_must_fail git config -f .gitmodules submodule.repo.path && |
Jens Lehmann | 73b0898 | 2012-09-30 01:05:58 +0200 | [diff] [blame] | 805 | git config -f .gitmodules submodule.repo_new.path >actual && |
| 806 | test_cmp expect actual&& |
| 807 | echo "$submodurl/repo" >expect && |
Jens Lehmann | 95c1641 | 2013-08-06 21:15:25 +0200 | [diff] [blame] | 808 | test_must_fail git config -f .gitmodules submodule.repo.url && |
Jens Lehmann | 73b0898 | 2012-09-30 01:05:58 +0200 | [diff] [blame] | 809 | echo "$submodurl/bare.git" >expect && |
| 810 | git config -f .gitmodules submodule.repo_new.url >actual && |
| 811 | test_cmp expect actual && |
| 812 | echo "$submodurl/repo" >expect && |
| 813 | git config submodule.repo.url >actual && |
| 814 | test_cmp expect actual && |
| 815 | echo "$submodurl/bare.git" >expect && |
| 816 | git config submodule.repo_new.url >actual && |
| 817 | test_cmp expect actual |
| 818 | ) |
| 819 | ' |
| 820 | |
Jens Lehmann | 4b7c286 | 2012-09-30 23:01:29 +0200 | [diff] [blame] | 821 | test_expect_success 'submodule add with an existing name fails unless forced' ' |
| 822 | ( |
| 823 | cd addtest2 && |
| 824 | rm -rf repo && |
| 825 | git rm repo && |
| 826 | test_must_fail git submodule add -q --name repo_new "$submodurl/repo.git" repo && |
| 827 | test ! -d repo && |
Jens Lehmann | 95c1641 | 2013-08-06 21:15:25 +0200 | [diff] [blame] | 828 | test_must_fail git config -f .gitmodules submodule.repo_new.path && |
| 829 | test_must_fail git config -f .gitmodules submodule.repo_new.url && |
Jens Lehmann | 4b7c286 | 2012-09-30 23:01:29 +0200 | [diff] [blame] | 830 | echo "$submodurl/bare.git" >expect && |
| 831 | git config submodule.repo_new.url >actual && |
| 832 | test_cmp expect actual && |
| 833 | git submodule add -f -q --name repo_new "$submodurl/repo.git" repo && |
| 834 | test -d repo && |
| 835 | echo "repo" >expect && |
| 836 | git config -f .gitmodules submodule.repo_new.path >actual && |
| 837 | test_cmp expect actual&& |
| 838 | echo "$submodurl/repo.git" >expect && |
| 839 | git config -f .gitmodules submodule.repo_new.url >actual && |
| 840 | test_cmp expect actual && |
| 841 | echo "$submodurl/repo.git" >expect && |
| 842 | git config submodule.repo_new.url >actual && |
| 843 | test_cmp expect actual |
| 844 | ) |
| 845 | ' |
| 846 | |
Jens Lehmann | cf41982 | 2013-03-04 22:20:24 +0100 | [diff] [blame] | 847 | test_expect_success 'set up a second submodule' ' |
| 848 | git submodule add ./init2 example2 && |
| 849 | git commit -m "submodule example2 added" |
| 850 | ' |
| 851 | |
| 852 | test_expect_success 'submodule deinit should remove the whole submodule section from .git/config' ' |
| 853 | git config submodule.example.foo bar && |
| 854 | git config submodule.example2.frotz nitfol && |
| 855 | git submodule deinit init && |
| 856 | test -z "$(git config --get-regexp "submodule\.example\.")" && |
| 857 | test -n "$(git config --get-regexp "submodule\.example2\.")" && |
| 858 | test -f example2/.git && |
| 859 | rmdir init |
| 860 | ' |
| 861 | |
John Keeping | 091a6eb | 2013-06-16 15:18:18 +0100 | [diff] [blame] | 862 | test_expect_success 'submodule deinit from subdirectory' ' |
| 863 | git submodule update --init && |
| 864 | git config submodule.example.foo bar && |
| 865 | mkdir -p sub && |
| 866 | ( |
| 867 | cd sub && |
| 868 | git submodule deinit ../init >../output |
| 869 | ) && |
| 870 | grep "\\.\\./init" output && |
| 871 | test -z "$(git config --get-regexp "submodule\.example\.")" && |
| 872 | test -n "$(git config --get-regexp "submodule\.example2\.")" && |
| 873 | test -f example2/.git && |
| 874 | rmdir init |
| 875 | ' |
| 876 | |
Jens Lehmann | cf41982 | 2013-03-04 22:20:24 +0100 | [diff] [blame] | 877 | test_expect_success 'submodule deinit . deinits all initialized submodules' ' |
| 878 | git submodule update --init && |
| 879 | git config submodule.example.foo bar && |
| 880 | git config submodule.example2.frotz nitfol && |
| 881 | test_must_fail git submodule deinit && |
Jens Lehmann | 7b294bf | 2013-04-01 21:02:00 +0200 | [diff] [blame] | 882 | git submodule deinit . >actual && |
Jens Lehmann | cf41982 | 2013-03-04 22:20:24 +0100 | [diff] [blame] | 883 | test -z "$(git config --get-regexp "submodule\.example\.")" && |
| 884 | test -z "$(git config --get-regexp "submodule\.example2\.")" && |
Jens Lehmann | 7b294bf | 2013-04-01 21:02:00 +0200 | [diff] [blame] | 885 | test_i18ngrep "Cleared directory .init" actual && |
| 886 | test_i18ngrep "Cleared directory .example2" actual && |
Jens Lehmann | cf41982 | 2013-03-04 22:20:24 +0100 | [diff] [blame] | 887 | rmdir init example2 |
| 888 | ' |
| 889 | |
| 890 | test_expect_success 'submodule deinit deinits a submodule when its work tree is missing or empty' ' |
| 891 | git submodule update --init && |
| 892 | rm -rf init example2/* example2/.git && |
Jens Lehmann | 7b294bf | 2013-04-01 21:02:00 +0200 | [diff] [blame] | 893 | git submodule deinit init example2 >actual && |
Jens Lehmann | cf41982 | 2013-03-04 22:20:24 +0100 | [diff] [blame] | 894 | test -z "$(git config --get-regexp "submodule\.example\.")" && |
| 895 | test -z "$(git config --get-regexp "submodule\.example2\.")" && |
Jens Lehmann | 7b294bf | 2013-04-01 21:02:00 +0200 | [diff] [blame] | 896 | test_i18ngrep ! "Cleared directory .init" actual && |
| 897 | test_i18ngrep "Cleared directory .example2" actual && |
Jens Lehmann | cf41982 | 2013-03-04 22:20:24 +0100 | [diff] [blame] | 898 | rmdir init |
| 899 | ' |
| 900 | |
| 901 | test_expect_success 'submodule deinit fails when the submodule contains modifications unless forced' ' |
| 902 | git submodule update --init && |
| 903 | echo X >>init/s && |
| 904 | test_must_fail git submodule deinit init && |
| 905 | test -n "$(git config --get-regexp "submodule\.example\.")" && |
| 906 | test -f example2/.git && |
Jens Lehmann | 7b294bf | 2013-04-01 21:02:00 +0200 | [diff] [blame] | 907 | git submodule deinit -f init >actual && |
Jens Lehmann | cf41982 | 2013-03-04 22:20:24 +0100 | [diff] [blame] | 908 | test -z "$(git config --get-regexp "submodule\.example\.")" && |
Jens Lehmann | 7b294bf | 2013-04-01 21:02:00 +0200 | [diff] [blame] | 909 | test_i18ngrep "Cleared directory .init" actual && |
Jens Lehmann | cf41982 | 2013-03-04 22:20:24 +0100 | [diff] [blame] | 910 | rmdir init |
| 911 | ' |
| 912 | |
| 913 | test_expect_success 'submodule deinit fails when the submodule contains untracked files unless forced' ' |
| 914 | git submodule update --init && |
| 915 | echo X >>init/untracked && |
| 916 | test_must_fail git submodule deinit init && |
| 917 | test -n "$(git config --get-regexp "submodule\.example\.")" && |
| 918 | test -f example2/.git && |
Jens Lehmann | 7b294bf | 2013-04-01 21:02:00 +0200 | [diff] [blame] | 919 | git submodule deinit -f init >actual && |
Jens Lehmann | cf41982 | 2013-03-04 22:20:24 +0100 | [diff] [blame] | 920 | test -z "$(git config --get-regexp "submodule\.example\.")" && |
Jens Lehmann | 7b294bf | 2013-04-01 21:02:00 +0200 | [diff] [blame] | 921 | test_i18ngrep "Cleared directory .init" actual && |
Jens Lehmann | cf41982 | 2013-03-04 22:20:24 +0100 | [diff] [blame] | 922 | rmdir init |
| 923 | ' |
| 924 | |
| 925 | test_expect_success 'submodule deinit fails when the submodule HEAD does not match unless forced' ' |
| 926 | git submodule update --init && |
| 927 | ( |
| 928 | cd init && |
| 929 | git checkout HEAD^ |
| 930 | ) && |
| 931 | test_must_fail git submodule deinit init && |
| 932 | test -n "$(git config --get-regexp "submodule\.example\.")" && |
| 933 | test -f example2/.git && |
Jens Lehmann | 7b294bf | 2013-04-01 21:02:00 +0200 | [diff] [blame] | 934 | git submodule deinit -f init >actual && |
Jens Lehmann | cf41982 | 2013-03-04 22:20:24 +0100 | [diff] [blame] | 935 | test -z "$(git config --get-regexp "submodule\.example\.")" && |
Jens Lehmann | 7b294bf | 2013-04-01 21:02:00 +0200 | [diff] [blame] | 936 | test_i18ngrep "Cleared directory .init" actual && |
Jens Lehmann | cf41982 | 2013-03-04 22:20:24 +0100 | [diff] [blame] | 937 | rmdir init |
| 938 | ' |
| 939 | |
| 940 | test_expect_success 'submodule deinit is silent when used on an uninitialized submodule' ' |
| 941 | git submodule update --init && |
| 942 | git submodule deinit init >actual && |
| 943 | test_i18ngrep "Submodule .example. (.*) unregistered for path .init" actual && |
Jens Lehmann | 7b294bf | 2013-04-01 21:02:00 +0200 | [diff] [blame] | 944 | test_i18ngrep "Cleared directory .init" actual && |
Jens Lehmann | cf41982 | 2013-03-04 22:20:24 +0100 | [diff] [blame] | 945 | git submodule deinit init >actual && |
| 946 | test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual && |
Jens Lehmann | 7b294bf | 2013-04-01 21:02:00 +0200 | [diff] [blame] | 947 | test_i18ngrep "Cleared directory .init" actual && |
Jens Lehmann | cf41982 | 2013-03-04 22:20:24 +0100 | [diff] [blame] | 948 | git submodule deinit . >actual && |
| 949 | test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual && |
| 950 | test_i18ngrep "Submodule .example2. (.*) unregistered for path .example2" actual && |
Jens Lehmann | 7b294bf | 2013-04-01 21:02:00 +0200 | [diff] [blame] | 951 | test_i18ngrep "Cleared directory .init" actual && |
Jens Lehmann | cf41982 | 2013-03-04 22:20:24 +0100 | [diff] [blame] | 952 | git submodule deinit . >actual && |
| 953 | test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual && |
| 954 | test_i18ngrep ! "Submodule .example2. (.*) unregistered for path .example2" actual && |
Jens Lehmann | 7b294bf | 2013-04-01 21:02:00 +0200 | [diff] [blame] | 955 | test_i18ngrep "Cleared directory .init" actual && |
Jens Lehmann | cf41982 | 2013-03-04 22:20:24 +0100 | [diff] [blame] | 956 | rmdir init example2 |
| 957 | ' |
| 958 | |
| 959 | test_expect_success 'submodule deinit fails when submodule has a .git directory even when forced' ' |
| 960 | git submodule update --init && |
| 961 | ( |
| 962 | cd init && |
| 963 | rm .git && |
| 964 | cp -R ../.git/modules/example .git && |
| 965 | GIT_WORK_TREE=. git config --unset core.worktree |
| 966 | ) && |
| 967 | test_must_fail git submodule deinit init && |
| 968 | test_must_fail git submodule deinit -f init && |
| 969 | test -d init/.git && |
| 970 | test -n "$(git config --get-regexp "submodule\.example\.")" |
| 971 | ' |
| 972 | |
Torsten Bögershausen | bed9470 | 2013-06-20 16:58:48 +0200 | [diff] [blame] | 973 | test_expect_success 'submodule with UTF-8 name' ' |
| 974 | svname=$(printf "\303\245 \303\244\303\266") && |
| 975 | mkdir "$svname" && |
Fredrik Gustafsson | 7467124 | 2013-06-14 02:26:02 +0200 | [diff] [blame] | 976 | ( |
Torsten Bögershausen | bed9470 | 2013-06-20 16:58:48 +0200 | [diff] [blame] | 977 | cd "$svname" && |
Fredrik Gustafsson | 7467124 | 2013-06-14 02:26:02 +0200 | [diff] [blame] | 978 | git init && |
Torsten Bögershausen | bed9470 | 2013-06-20 16:58:48 +0200 | [diff] [blame] | 979 | >sub && |
| 980 | git add sub && |
Fredrik Gustafsson | 7467124 | 2013-06-14 02:26:02 +0200 | [diff] [blame] | 981 | git commit -m "init sub" |
Torsten Bögershausen | bed9470 | 2013-06-20 16:58:48 +0200 | [diff] [blame] | 982 | ) && |
Torsten Bögershausen | bed9470 | 2013-06-20 16:58:48 +0200 | [diff] [blame] | 983 | git submodule add ./"$svname" && |
| 984 | git submodule >&2 && |
| 985 | test -n "$(git submodule | grep "$svname")" |
Fredrik Gustafsson | 7467124 | 2013-06-14 02:26:02 +0200 | [diff] [blame] | 986 | ' |
Junio C Hamano | 2bb7afa | 2013-07-15 10:28:48 -0700 | [diff] [blame] | 987 | |
Fredrik Gustafsson | 275cd18 | 2013-07-02 23:42:56 +0200 | [diff] [blame] | 988 | test_expect_success 'submodule add clone shallow submodule' ' |
| 989 | mkdir super && |
| 990 | pwd=$(pwd) |
| 991 | ( |
| 992 | cd super && |
| 993 | git init && |
| 994 | git submodule add --depth=1 file://"$pwd"/example2 submodule && |
| 995 | ( |
| 996 | cd submodule && |
| 997 | test 1 = $(git log --oneline | wc -l) |
| 998 | ) |
| 999 | ) |
| 1000 | ' |
| 1001 | |
| 1002 | |
Lars Hjemli | 88961ef | 2007-06-02 03:27:42 +0200 | [diff] [blame] | 1003 | test_done |