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 | |
Johannes Schindelin | 01dc813 | 2020-11-18 23:44:39 +0000 | [diff] [blame] | 12 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
Johannes Schindelin | 334afbc | 2020-11-18 23:44:19 +0000 | [diff] [blame] | 13 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
| 14 | |
Lars Hjemli | 88961ef | 2007-06-02 03:27:42 +0200 | [diff] [blame] | 15 | . ./test-lib.sh |
| 16 | |
Taylor Blau | 0d3beb7 | 2022-07-29 15:21:40 -0400 | [diff] [blame] | 17 | test_expect_success 'setup - enable local submodules' ' |
| 18 | git config --global protocol.file.allow always |
| 19 | ' |
| 20 | |
Ævar Arnfjörð Bjarmason | 89bc7b5 | 2022-09-01 01:17:43 +0200 | [diff] [blame] | 21 | test_expect_success 'submodule usage: -h' ' |
| 22 | git submodule -h >out 2>err && |
| 23 | grep "^usage: git submodule" out && |
| 24 | test_must_be_empty err |
| 25 | ' |
| 26 | |
| 27 | test_expect_success 'submodule usage: --recursive' ' |
| 28 | test_expect_code 1 git submodule --recursive >out 2>err && |
| 29 | grep "^usage: git submodule" err && |
| 30 | test_must_be_empty out |
| 31 | ' |
| 32 | |
| 33 | test_expect_success 'submodule usage: status --' ' |
| 34 | test_expect_code 1 git submodule -- && |
| 35 | test_expect_code 1 git submodule --end-of-options |
| 36 | ' |
| 37 | |
| 38 | for opt in '--quiet' '--cached' |
| 39 | do |
| 40 | test_expect_success "submodule usage: status $opt" ' |
| 41 | git submodule $opt && |
| 42 | git submodule status $opt && |
| 43 | git submodule $opt status |
| 44 | ' |
| 45 | done |
| 46 | |
Stefan Beller | f6a5279 | 2016-05-05 12:52:32 -0700 | [diff] [blame] | 47 | test_expect_success 'submodule deinit works on empty repository' ' |
| 48 | git submodule deinit --all |
| 49 | ' |
| 50 | |
Jonathan Nieder | fe454b1 | 2010-04-10 00:38:37 -0500 | [diff] [blame] | 51 | test_expect_success 'setup - initial commit' ' |
| 52 | >t && |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 53 | git add t && |
| 54 | git commit -m "initial commit" && |
Jonathan Nieder | fe454b1 | 2010-04-10 00:38:37 -0500 | [diff] [blame] | 55 | git branch initial |
| 56 | ' |
| 57 | |
Stefan Beller | d92028a | 2016-04-28 13:02:45 -0700 | [diff] [blame] | 58 | test_expect_success 'submodule init aborts on missing .gitmodules file' ' |
| 59 | test_when_finished "git update-index --remove sub" && |
| 60 | git update-index --add --cacheinfo 160000,$(git rev-parse HEAD),sub && |
| 61 | # missing the .gitmodules file here |
| 62 | test_must_fail git submodule init 2>actual && |
| 63 | test_i18ngrep "No url found for submodule path" actual |
| 64 | ' |
| 65 | |
Stefan Beller | 08fdbdb | 2016-04-28 13:02:46 -0700 | [diff] [blame] | 66 | test_expect_success 'submodule update aborts on missing .gitmodules file' ' |
| 67 | test_when_finished "git update-index --remove sub" && |
| 68 | git update-index --add --cacheinfo 160000,$(git rev-parse HEAD),sub && |
| 69 | # missing the .gitmodules file here |
| 70 | git submodule update sub 2>actual && |
| 71 | test_i18ngrep "Submodule path .sub. not initialized" actual |
| 72 | ' |
| 73 | |
Jeff King | 627fde1 | 2017-04-24 20:57:47 -0400 | [diff] [blame] | 74 | test_expect_success 'submodule update aborts on missing gitmodules url' ' |
| 75 | test_when_finished "git update-index --remove sub" && |
| 76 | git update-index --add --cacheinfo 160000,$(git rev-parse HEAD),sub && |
| 77 | test_when_finished "rm -f .gitmodules" && |
| 78 | git config -f .gitmodules submodule.s.path sub && |
| 79 | test_must_fail git submodule init |
| 80 | ' |
| 81 | |
Kyle Meyer | e138111 | 2019-04-09 19:07:35 -0400 | [diff] [blame] | 82 | test_expect_success 'add aborts on repository with no commits' ' |
| 83 | cat >expect <<-\EOF && |
Atharva Raykar | 0008d12 | 2021-07-10 13:17:59 +0530 | [diff] [blame] | 84 | fatal: '"'repo-no-commits'"' does not have a commit checked out |
Kyle Meyer | e138111 | 2019-04-09 19:07:35 -0400 | [diff] [blame] | 85 | EOF |
| 86 | git init repo-no-commits && |
| 87 | test_must_fail git submodule add ../a ./repo-no-commits 2>actual && |
Ævar Arnfjörð Bjarmason | 1108cea | 2021-02-11 02:53:53 +0100 | [diff] [blame] | 88 | test_cmp expect actual |
Kyle Meyer | e138111 | 2019-04-09 19:07:35 -0400 | [diff] [blame] | 89 | ' |
| 90 | |
Peter Kaestle | f38c924 | 2020-02-03 00:32:44 +0100 | [diff] [blame] | 91 | test_expect_success 'status should ignore inner git repo when not added' ' |
| 92 | rm -fr inner && |
| 93 | mkdir inner && |
| 94 | ( |
| 95 | cd inner && |
| 96 | git init && |
| 97 | >t && |
| 98 | git add t && |
| 99 | git commit -m "initial" |
| 100 | ) && |
| 101 | test_must_fail git submodule status inner 2>output.err && |
| 102 | rm -fr inner && |
| 103 | test_i18ngrep "^error: .*did not match any file(s) known to git" output.err |
| 104 | ' |
| 105 | |
Jonathan Nieder | fe454b1 | 2010-04-10 00:38:37 -0500 | [diff] [blame] | 106 | test_expect_success 'setup - repository in init subdirectory' ' |
Junio C Hamano | a2d93ae | 2008-01-15 03:13:55 -0800 | [diff] [blame] | 107 | mkdir init && |
Jonathan Nieder | fe454b1 | 2010-04-10 00:38:37 -0500 | [diff] [blame] | 108 | ( |
| 109 | cd init && |
| 110 | git init && |
| 111 | echo a >a && |
| 112 | git add a && |
| 113 | git commit -m "submodule commit 1" && |
| 114 | git tag -a -m "rev-1" rev-1 |
| 115 | ) |
Jonathan Nieder | fe454b1 | 2010-04-10 00:38:37 -0500 | [diff] [blame] | 116 | ' |
| 117 | |
| 118 | test_expect_success 'setup - commit with gitlink' ' |
Lars Hjemli | 88961ef | 2007-06-02 03:27:42 +0200 | [diff] [blame] | 119 | echo a >a && |
| 120 | echo z >z && |
Junio C Hamano | a2d93ae | 2008-01-15 03:13:55 -0800 | [diff] [blame] | 121 | git add a init z && |
Jonathan Nieder | fe454b1 | 2010-04-10 00:38:37 -0500 | [diff] [blame] | 122 | git commit -m "super commit 1" |
| 123 | ' |
| 124 | |
| 125 | test_expect_success 'setup - hide init subdirectory' ' |
| 126 | mv init .subrepo |
| 127 | ' |
| 128 | |
Jonathan Nieder | a76c944 | 2010-04-10 00:39:04 -0500 | [diff] [blame] | 129 | test_expect_success 'setup - repository to add submodules to' ' |
Ævar Arnfjörð Bjarmason | 31991b0 | 2010-07-05 17:33:03 +0000 | [diff] [blame] | 130 | git init addtest && |
| 131 | git init addtest-ignore |
Michael J Gruber | ac8463d | 2009-03-03 16:08:20 +0100 | [diff] [blame] | 132 | ' |
| 133 | |
Jonathan Nieder | a76c944 | 2010-04-10 00:39:04 -0500 | [diff] [blame] | 134 | # The 'submodule add' tests need some repository to add as a submodule. |
Jeff King | dd008b3 | 2011-07-30 09:05:54 -0600 | [diff] [blame] | 135 | # The trash directory is a good one as any. We need to canonicalize |
| 136 | # the name, though, as some tests compare it to the absolute path git |
| 137 | # generates, which will expand symbolic links. |
| 138 | submodurl=$(pwd -P) |
Jonathan Nieder | a76c944 | 2010-04-10 00:39:04 -0500 | [diff] [blame] | 139 | |
| 140 | listbranches() { |
| 141 | git for-each-ref --format='%(refname)' 'refs/heads/*' |
| 142 | } |
| 143 | |
| 144 | inspect() { |
| 145 | dir=$1 && |
| 146 | dotdot="${2:-..}" && |
| 147 | |
| 148 | ( |
| 149 | cd "$dir" && |
| 150 | listbranches >"$dotdot/heads" && |
| 151 | { git symbolic-ref HEAD || :; } >"$dotdot/head" && |
Jonathan Nieder | ce8b54d | 2010-04-10 00:39:41 -0500 | [diff] [blame] | 152 | git rev-parse HEAD >"$dotdot/head-sha1" && |
Jonathan Nieder | a76c944 | 2010-04-10 00:39:04 -0500 | [diff] [blame] | 153 | git update-index --refresh && |
| 154 | git diff-files --exit-code && |
| 155 | git clean -n -d -x >"$dotdot/untracked" |
| 156 | ) |
| 157 | } |
| 158 | |
Michael J Gruber | ac8463d | 2009-03-03 16:08:20 +0100 | [diff] [blame] | 159 | test_expect_success 'submodule add' ' |
Johannes Schindelin | 01dc813 | 2020-11-18 23:44:39 +0000 | [diff] [blame] | 160 | echo "refs/heads/main" >expect && |
Jonathan Nieder | a76c944 | 2010-04-10 00:39:04 -0500 | [diff] [blame] | 161 | |
Michael J Gruber | ac8463d | 2009-03-03 16:08:20 +0100 | [diff] [blame] | 162 | ( |
| 163 | cd addtest && |
Jens Lehmann | 7e60407 | 2011-07-26 23:39:03 +0200 | [diff] [blame] | 164 | git submodule add -q "$submodurl" submod >actual && |
Junio C Hamano | ca8d148 | 2013-06-09 11:29:20 -0700 | [diff] [blame] | 165 | test_must_be_empty actual && |
Jens Lehmann | ea115a0 | 2012-03-04 22:14:30 +0100 | [diff] [blame] | 166 | echo "gitdir: ../.git/modules/submod" >expect && |
| 167 | test_cmp expect submod/.git && |
Jens Lehmann | d75219b | 2012-03-04 22:15:08 +0100 | [diff] [blame] | 168 | ( |
| 169 | cd submod && |
| 170 | git config core.worktree >actual && |
| 171 | echo "../../../submod" >expect && |
| 172 | test_cmp expect actual && |
| 173 | rm -f actual expect |
| 174 | ) && |
Michael J Gruber | ac8463d | 2009-03-03 16:08:20 +0100 | [diff] [blame] | 175 | git submodule init |
Jonathan Nieder | a76c944 | 2010-04-10 00:39:04 -0500 | [diff] [blame] | 176 | ) && |
| 177 | |
| 178 | rm -f heads head untracked && |
| 179 | inspect addtest/submod ../.. && |
| 180 | test_cmp expect heads && |
| 181 | test_cmp expect head && |
SZEDER Gábor | 1c5e94f | 2018-08-19 23:57:25 +0200 | [diff] [blame] | 182 | test_must_be_empty untracked |
Michael J Gruber | ac8463d | 2009-03-03 16:08:20 +0100 | [diff] [blame] | 183 | ' |
| 184 | |
Ævar Arnfjörð Bjarmason | 59378e3 | 2022-09-01 01:17:44 +0200 | [diff] [blame] | 185 | test_expect_success !WINDOWS 'submodule add (absolute path)' ' |
| 186 | test_when_finished "git reset --hard" && |
| 187 | git submodule add "$submodurl" "$submodurl/add-abs" |
| 188 | ' |
| 189 | |
Stefan Beller | 83f5fa5 | 2018-06-18 16:41:48 -0700 | [diff] [blame] | 190 | test_expect_success 'setup parent and one repository' ' |
| 191 | test_create_repo parent && |
| 192 | test_commit -C parent one |
| 193 | ' |
Casey Fitzpatrick | 6d33e1c | 2018-05-03 06:53:45 -0400 | [diff] [blame] | 194 | |
| 195 | test_expect_success 'redirected submodule add does not show progress' ' |
| 196 | git -C addtest submodule add "file://$submodurl/parent" submod-redirected \ |
| 197 | 2>err && |
| 198 | ! grep % err && |
| 199 | test_i18ngrep ! "Checking connectivity" err |
| 200 | ' |
| 201 | |
| 202 | test_expect_success 'redirected submodule add --progress does show progress' ' |
| 203 | git -C addtest submodule add --progress "file://$submodurl/parent" \ |
| 204 | submod-redirected-progress 2>err && \ |
| 205 | grep % err |
| 206 | ' |
| 207 | |
Jens Lehmann | d27b876 | 2010-07-17 17:11:43 +0200 | [diff] [blame] | 208 | test_expect_success 'submodule add to .gitignored path fails' ' |
Ævar Arnfjörð Bjarmason | 31991b0 | 2010-07-05 17:33:03 +0000 | [diff] [blame] | 209 | ( |
| 210 | cd addtest-ignore && |
Jens Lehmann | d27b876 | 2010-07-17 17:11:43 +0200 | [diff] [blame] | 211 | cat <<-\EOF >expect && |
Kyle Meyer | c816385 | 2020-01-07 19:31:21 -0500 | [diff] [blame] | 212 | The following paths are ignored by one of your .gitignore files: |
Jens Lehmann | d27b876 | 2010-07-17 17:11:43 +0200 | [diff] [blame] | 213 | submod |
Junio C Hamano | daef1b3 | 2020-02-14 12:54:19 -0800 | [diff] [blame] | 214 | hint: Use -f if you really want to add them. |
| 215 | hint: Turn this message off by running |
| 216 | hint: "git config advice.addIgnoredFile false" |
Jens Lehmann | d27b876 | 2010-07-17 17:11:43 +0200 | [diff] [blame] | 217 | EOF |
Ævar Arnfjörð Bjarmason | 31991b0 | 2010-07-05 17:33:03 +0000 | [diff] [blame] | 218 | # Does not use test_commit due to the ignore |
| 219 | echo "*" > .gitignore && |
| 220 | git add --force .gitignore && |
| 221 | git commit -m"Ignore everything" && |
Jens Lehmann | d27b876 | 2010-07-17 17:11:43 +0200 | [diff] [blame] | 222 | ! git submodule add "$submodurl" submod >actual 2>&1 && |
Ævar Arnfjörð Bjarmason | 1108cea | 2021-02-11 02:53:53 +0100 | [diff] [blame] | 223 | test_cmp expect actual |
Jens Lehmann | d27b876 | 2010-07-17 17:11:43 +0200 | [diff] [blame] | 224 | ) |
| 225 | ' |
Ævar Arnfjörð Bjarmason | 31991b0 | 2010-07-05 17:33:03 +0000 | [diff] [blame] | 226 | |
Jens Lehmann | d27b876 | 2010-07-17 17:11:43 +0200 | [diff] [blame] | 227 | test_expect_success 'submodule add to .gitignored path with --force' ' |
| 228 | ( |
| 229 | cd addtest-ignore && |
| 230 | git submodule add --force "$submodurl" submod |
| 231 | ) |
Ævar Arnfjörð Bjarmason | 31991b0 | 2010-07-05 17:33:03 +0000 | [diff] [blame] | 232 | ' |
| 233 | |
Atharva Raykar | 84069fc | 2021-07-06 23:49:34 +0530 | [diff] [blame] | 234 | test_expect_success 'submodule add to path with tracked content fails' ' |
| 235 | ( |
| 236 | cd addtest && |
Atharva Raykar | 0008d12 | 2021-07-10 13:17:59 +0530 | [diff] [blame] | 237 | echo "fatal: '\''dir-tracked'\'' already exists in the index" >expect && |
Atharva Raykar | 84069fc | 2021-07-06 23:49:34 +0530 | [diff] [blame] | 238 | mkdir dir-tracked && |
| 239 | test_commit foo dir-tracked/bar && |
| 240 | test_must_fail git submodule add "$submodurl" dir-tracked >actual 2>&1 && |
| 241 | test_cmp expect actual |
| 242 | ) |
| 243 | ' |
| 244 | |
Stefan Beller | 619acfc | 2016-10-06 12:37:24 -0700 | [diff] [blame] | 245 | test_expect_success 'submodule add to reconfigure existing submodule with --force' ' |
| 246 | ( |
| 247 | cd addtest-ignore && |
Eric Sunshine | adc7331 | 2018-07-01 20:23:51 -0400 | [diff] [blame] | 248 | bogus_url="$(pwd)/bogus-url" && |
| 249 | git submodule add --force "$bogus_url" submod && |
| 250 | git submodule add --force -b initial "$submodurl" submod-branch && |
| 251 | test "$bogus_url" = "$(git config -f .gitmodules submodule.submod.url)" && |
| 252 | test "$bogus_url" = "$(git config submodule.submod.url)" && |
Stefan Beller | 619acfc | 2016-10-06 12:37:24 -0700 | [diff] [blame] | 253 | # Restore the url |
Eric Sunshine | adc7331 | 2018-07-01 20:23:51 -0400 | [diff] [blame] | 254 | git submodule add --force "$submodurl" submod && |
Stefan Beller | 619acfc | 2016-10-06 12:37:24 -0700 | [diff] [blame] | 255 | test "$submodurl" = "$(git config -f .gitmodules submodule.submod.url)" && |
| 256 | test "$submodurl" = "$(git config submodule.submod.url)" |
| 257 | ) |
| 258 | ' |
| 259 | |
Kyle Meyer | c816385 | 2020-01-07 19:31:21 -0500 | [diff] [blame] | 260 | test_expect_success 'submodule add relays add --dry-run stderr' ' |
| 261 | test_when_finished "rm -rf addtest/.git/index.lock" && |
| 262 | ( |
| 263 | cd addtest && |
| 264 | : >.git/index.lock && |
| 265 | ! git submodule add "$submodurl" sub-while-locked 2>output.err && |
| 266 | test_i18ngrep "^fatal: .*index\.lock" output.err && |
| 267 | test_path_is_missing sub-while-locked |
| 268 | ) |
| 269 | ' |
| 270 | |
Ben Jackson | ea10b60 | 2009-04-18 20:42:07 -0700 | [diff] [blame] | 271 | test_expect_success 'submodule add --branch' ' |
Jonathan Nieder | a76c944 | 2010-04-10 00:39:04 -0500 | [diff] [blame] | 272 | echo "refs/heads/initial" >expect-head && |
| 273 | cat <<-\EOF >expect-heads && |
| 274 | refs/heads/initial |
Johannes Schindelin | 01dc813 | 2020-11-18 23:44:39 +0000 | [diff] [blame] | 275 | refs/heads/main |
Jonathan Nieder | a76c944 | 2010-04-10 00:39:04 -0500 | [diff] [blame] | 276 | EOF |
Jonathan Nieder | a76c944 | 2010-04-10 00:39:04 -0500 | [diff] [blame] | 277 | |
Ben Jackson | ea10b60 | 2009-04-18 20:42:07 -0700 | [diff] [blame] | 278 | ( |
| 279 | cd addtest && |
| 280 | git submodule add -b initial "$submodurl" submod-branch && |
W. Trevor King | b928922 | 2012-12-19 11:03:33 -0500 | [diff] [blame] | 281 | test "initial" = "$(git config -f .gitmodules submodule.submod-branch.branch)" && |
Jonathan Nieder | a76c944 | 2010-04-10 00:39:04 -0500 | [diff] [blame] | 282 | git submodule init |
| 283 | ) && |
| 284 | |
| 285 | rm -f heads head untracked && |
| 286 | inspect addtest/submod-branch ../.. && |
| 287 | test_cmp expect-heads heads && |
| 288 | test_cmp expect-head head && |
SZEDER Gábor | 1c5e94f | 2018-08-19 23:57:25 +0200 | [diff] [blame] | 289 | test_must_be_empty untracked |
Ben Jackson | ea10b60 | 2009-04-18 20:42:07 -0700 | [diff] [blame] | 290 | ' |
| 291 | |
Michael J Gruber | db75ada | 2009-03-03 16:08:21 +0100 | [diff] [blame] | 292 | test_expect_success 'submodule add with ./ in path' ' |
Johannes Schindelin | 01dc813 | 2020-11-18 23:44:39 +0000 | [diff] [blame] | 293 | echo "refs/heads/main" >expect && |
Jonathan Nieder | a76c944 | 2010-04-10 00:39:04 -0500 | [diff] [blame] | 294 | |
Michael J Gruber | ac8463d | 2009-03-03 16:08:20 +0100 | [diff] [blame] | 295 | ( |
| 296 | cd addtest && |
| 297 | git submodule add "$submodurl" ././dotsubmod/./frotz/./ && |
| 298 | git submodule init |
Jonathan Nieder | a76c944 | 2010-04-10 00:39:04 -0500 | [diff] [blame] | 299 | ) && |
| 300 | |
| 301 | rm -f heads head untracked && |
| 302 | inspect addtest/dotsubmod/frotz ../../.. && |
| 303 | test_cmp expect heads && |
| 304 | test_cmp expect head && |
SZEDER Gábor | 1c5e94f | 2018-08-19 23:57:25 +0200 | [diff] [blame] | 305 | test_must_be_empty untracked |
Michael J Gruber | ac8463d | 2009-03-03 16:08:20 +0100 | [diff] [blame] | 306 | ' |
| 307 | |
Patrick Steinhardt | 8196e72 | 2015-01-30 16:14:03 +0100 | [diff] [blame] | 308 | test_expect_success 'submodule add with /././ in path' ' |
Johannes Schindelin | 01dc813 | 2020-11-18 23:44:39 +0000 | [diff] [blame] | 309 | echo "refs/heads/main" >expect && |
Patrick Steinhardt | 8196e72 | 2015-01-30 16:14:03 +0100 | [diff] [blame] | 310 | |
| 311 | ( |
| 312 | cd addtest && |
| 313 | git submodule add "$submodurl" dotslashdotsubmod/././frotz/./ && |
| 314 | git submodule init |
| 315 | ) && |
| 316 | |
| 317 | rm -f heads head untracked && |
| 318 | inspect addtest/dotslashdotsubmod/frotz ../../.. && |
| 319 | test_cmp expect heads && |
| 320 | test_cmp expect head && |
SZEDER Gábor | 1c5e94f | 2018-08-19 23:57:25 +0200 | [diff] [blame] | 321 | test_must_be_empty untracked |
Patrick Steinhardt | 8196e72 | 2015-01-30 16:14:03 +0100 | [diff] [blame] | 322 | ' |
| 323 | |
Michael J Gruber | db75ada | 2009-03-03 16:08:21 +0100 | [diff] [blame] | 324 | test_expect_success 'submodule add with // in path' ' |
Johannes Schindelin | 01dc813 | 2020-11-18 23:44:39 +0000 | [diff] [blame] | 325 | echo "refs/heads/main" >expect && |
Jonathan Nieder | a76c944 | 2010-04-10 00:39:04 -0500 | [diff] [blame] | 326 | |
Michael J Gruber | ac8463d | 2009-03-03 16:08:20 +0100 | [diff] [blame] | 327 | ( |
| 328 | cd addtest && |
| 329 | git submodule add "$submodurl" slashslashsubmod///frotz// && |
| 330 | git submodule init |
Jonathan Nieder | a76c944 | 2010-04-10 00:39:04 -0500 | [diff] [blame] | 331 | ) && |
| 332 | |
| 333 | rm -f heads head untracked && |
| 334 | inspect addtest/slashslashsubmod/frotz ../../.. && |
| 335 | test_cmp expect heads && |
| 336 | test_cmp expect head && |
SZEDER Gábor | 1c5e94f | 2018-08-19 23:57:25 +0200 | [diff] [blame] | 337 | test_must_be_empty untracked |
Michael J Gruber | ac8463d | 2009-03-03 16:08:20 +0100 | [diff] [blame] | 338 | ' |
| 339 | |
Michael J Gruber | db75ada | 2009-03-03 16:08:21 +0100 | [diff] [blame] | 340 | test_expect_success 'submodule add with /.. in path' ' |
Johannes Schindelin | 01dc813 | 2020-11-18 23:44:39 +0000 | [diff] [blame] | 341 | echo "refs/heads/main" >expect && |
Jonathan Nieder | a76c944 | 2010-04-10 00:39:04 -0500 | [diff] [blame] | 342 | |
Michael J Gruber | ac8463d | 2009-03-03 16:08:20 +0100 | [diff] [blame] | 343 | ( |
| 344 | cd addtest && |
| 345 | git submodule add "$submodurl" dotdotsubmod/../realsubmod/frotz/.. && |
| 346 | git submodule init |
Jonathan Nieder | a76c944 | 2010-04-10 00:39:04 -0500 | [diff] [blame] | 347 | ) && |
| 348 | |
| 349 | rm -f heads head untracked && |
| 350 | inspect addtest/realsubmod ../.. && |
| 351 | test_cmp expect heads && |
| 352 | test_cmp expect head && |
SZEDER Gábor | 1c5e94f | 2018-08-19 23:57:25 +0200 | [diff] [blame] | 353 | test_must_be_empty untracked |
Michael J Gruber | ac8463d | 2009-03-03 16:08:20 +0100 | [diff] [blame] | 354 | ' |
| 355 | |
Michael J Gruber | db75ada | 2009-03-03 16:08:21 +0100 | [diff] [blame] | 356 | test_expect_success 'submodule add with ./, /.. and // in path' ' |
Johannes Schindelin | 01dc813 | 2020-11-18 23:44:39 +0000 | [diff] [blame] | 357 | echo "refs/heads/main" >expect && |
Jonathan Nieder | a76c944 | 2010-04-10 00:39:04 -0500 | [diff] [blame] | 358 | |
Michael J Gruber | ac8463d | 2009-03-03 16:08:20 +0100 | [diff] [blame] | 359 | ( |
| 360 | cd addtest && |
| 361 | git submodule add "$submodurl" dot/dotslashsubmod/./../..////realsubmod2/a/b/c/d/../../../../frotz//.. && |
| 362 | git submodule init |
Jonathan Nieder | a76c944 | 2010-04-10 00:39:04 -0500 | [diff] [blame] | 363 | ) && |
| 364 | |
| 365 | rm -f heads head untracked && |
| 366 | inspect addtest/realsubmod2 ../.. && |
| 367 | test_cmp expect heads && |
| 368 | test_cmp expect head && |
SZEDER Gábor | 1c5e94f | 2018-08-19 23:57:25 +0200 | [diff] [blame] | 369 | test_must_be_empty untracked |
Michael J Gruber | ac8463d | 2009-03-03 16:08:20 +0100 | [diff] [blame] | 370 | ' |
| 371 | |
Ramsay Jones | 7f1b225 | 2017-04-30 18:29:30 +0100 | [diff] [blame] | 372 | test_expect_success !CYGWIN 'submodule add with \\ in path' ' |
Brandon Williams | cf9e55f | 2017-04-07 10:23:06 -0700 | [diff] [blame] | 373 | test_when_finished "rm -rf parent sub\\with\\backslash" && |
| 374 | |
| 375 | # Initialize a repo with a backslash in its name |
| 376 | git init sub\\with\\backslash && |
| 377 | touch sub\\with\\backslash/empty.file && |
| 378 | git -C sub\\with\\backslash add empty.file && |
| 379 | git -C sub\\with\\backslash commit -m "Added empty.file" && |
| 380 | |
| 381 | # Add that repository as a submodule |
| 382 | git init parent && |
| 383 | git -C parent submodule add ../sub\\with\\backslash |
| 384 | ' |
| 385 | |
John Keeping | 091a6eb | 2013-06-16 15:18:18 +0100 | [diff] [blame] | 386 | test_expect_success 'submodule add in subdirectory' ' |
Johannes Schindelin | 01dc813 | 2020-11-18 23:44:39 +0000 | [diff] [blame] | 387 | echo "refs/heads/main" >expect && |
John Keeping | 091a6eb | 2013-06-16 15:18:18 +0100 | [diff] [blame] | 388 | |
| 389 | mkdir addtest/sub && |
| 390 | ( |
| 391 | cd addtest/sub && |
| 392 | git submodule add "$submodurl" ../realsubmod3 && |
| 393 | git submodule init |
| 394 | ) && |
| 395 | |
| 396 | rm -f heads head untracked && |
| 397 | inspect addtest/realsubmod3 ../.. && |
| 398 | test_cmp expect heads && |
| 399 | test_cmp expect head && |
SZEDER Gábor | 1c5e94f | 2018-08-19 23:57:25 +0200 | [diff] [blame] | 400 | test_must_be_empty untracked |
John Keeping | 091a6eb | 2013-06-16 15:18:18 +0100 | [diff] [blame] | 401 | ' |
| 402 | |
| 403 | test_expect_success 'submodule add in subdirectory with relative path should fail' ' |
| 404 | ( |
| 405 | cd addtest/sub && |
| 406 | test_must_fail git submodule add ../../ submod3 2>../../output.err |
| 407 | ) && |
| 408 | test_i18ngrep toplevel output.err |
| 409 | ' |
| 410 | |
Jonathan Nieder | ce8b54d | 2010-04-10 00:39:41 -0500 | [diff] [blame] | 411 | test_expect_success 'setup - add an example entry to .gitmodules' ' |
Jeff King | f7e8714 | 2014-03-20 19:17:01 -0400 | [diff] [blame] | 412 | git config --file=.gitmodules submodule.example.url git://example.com/init.git |
Jonathan Nieder | ce8b54d | 2010-04-10 00:39:41 -0500 | [diff] [blame] | 413 | ' |
| 414 | |
Lars Hjemli | 941987a | 2007-06-11 21:12:24 +0200 | [diff] [blame] | 415 | test_expect_success 'status should fail for unmapped paths' ' |
Jonathan Nieder | ce8b54d | 2010-04-10 00:39:41 -0500 | [diff] [blame] | 416 | test_must_fail git submodule status |
| 417 | ' |
| 418 | |
| 419 | test_expect_success 'setup - map path in .gitmodules' ' |
| 420 | cat <<\EOF >expect && |
| 421 | [submodule "example"] |
| 422 | url = git://example.com/init.git |
| 423 | path = init |
| 424 | EOF |
| 425 | |
Jeff King | f7e8714 | 2014-03-20 19:17:01 -0400 | [diff] [blame] | 426 | git config --file=.gitmodules submodule.example.path init && |
Jonathan Nieder | ce8b54d | 2010-04-10 00:39:41 -0500 | [diff] [blame] | 427 | |
| 428 | test_cmp expect .gitmodules |
Lars Hjemli | 88961ef | 2007-06-02 03:27:42 +0200 | [diff] [blame] | 429 | ' |
| 430 | |
| 431 | test_expect_success 'status should only print one line' ' |
Jonathan Nieder | ce8b54d | 2010-04-10 00:39:41 -0500 | [diff] [blame] | 432 | git submodule status >lines && |
Stefano Lattarini | 3fb0459 | 2012-04-11 13:24:01 +0200 | [diff] [blame] | 433 | test_line_count = 1 lines |
Jonathan Nieder | ce8b54d | 2010-04-10 00:39:41 -0500 | [diff] [blame] | 434 | ' |
| 435 | |
Manish Goregaokar | 1f3aea2 | 2019-11-25 04:15:44 +0000 | [diff] [blame] | 436 | test_expect_success 'status from subdirectory should have the same SHA1' ' |
| 437 | test_when_finished "rmdir addtest/subdir" && |
| 438 | ( |
| 439 | cd addtest && |
| 440 | mkdir subdir && |
| 441 | git submodule status >output && |
| 442 | awk "{print \$1}" <output >expect && |
| 443 | cd subdir && |
| 444 | git submodule status >../output && |
| 445 | awk "{print \$1}" <../output >../actual && |
| 446 | test_cmp ../expect ../actual && |
| 447 | git -C ../submod checkout HEAD^ && |
| 448 | git submodule status >../output && |
| 449 | awk "{print \$1}" <../output >../actual2 && |
| 450 | cd .. && |
| 451 | git submodule status >output && |
| 452 | awk "{print \$1}" <output >expect2 && |
| 453 | test_cmp expect2 actual2 && |
| 454 | ! test_cmp actual actual2 |
| 455 | ) |
| 456 | ' |
| 457 | |
Jonathan Nieder | ce8b54d | 2010-04-10 00:39:41 -0500 | [diff] [blame] | 458 | test_expect_success 'setup - fetch commit name from submodule' ' |
| 459 | rev1=$(cd .subrepo && git rev-parse HEAD) && |
| 460 | printf "rev1: %s\n" "$rev1" && |
| 461 | test -n "$rev1" |
Lars Hjemli | 88961ef | 2007-06-02 03:27:42 +0200 | [diff] [blame] | 462 | ' |
| 463 | |
| 464 | test_expect_success 'status should initially be "missing"' ' |
Jonathan Nieder | ce8b54d | 2010-04-10 00:39:41 -0500 | [diff] [blame] | 465 | git submodule status >lines && |
| 466 | grep "^-$rev1" lines |
Lars Hjemli | 88961ef | 2007-06-02 03:27:42 +0200 | [diff] [blame] | 467 | ' |
| 468 | |
Lars Hjemli | 211b7f1 | 2007-06-06 11:13:02 +0200 | [diff] [blame] | 469 | test_expect_success 'init should register submodule url in .git/config' ' |
Jonathan Nieder | ce8b54d | 2010-04-10 00:39:41 -0500 | [diff] [blame] | 470 | echo git://example.com/init.git >expect && |
| 471 | |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 472 | git submodule init && |
Jonathan Nieder | ce8b54d | 2010-04-10 00:39:41 -0500 | [diff] [blame] | 473 | git config submodule.example.url >url && |
| 474 | git config submodule.example.url ./.subrepo && |
| 475 | |
| 476 | test_cmp expect url |
Lars Hjemli | 211b7f1 | 2007-06-06 11:13:02 +0200 | [diff] [blame] | 477 | ' |
| 478 | |
Peter Kaestle | 3b2885e | 2020-01-24 11:34:04 +0100 | [diff] [blame] | 479 | test_expect_success 'status should still be "missing" after initializing' ' |
Peter Kaestle | ace912b | 2020-01-24 11:34:03 +0100 | [diff] [blame] | 480 | rm -fr init && |
| 481 | mkdir init && |
| 482 | git submodule status >lines && |
| 483 | rm -fr init && |
| 484 | grep "^-$rev1" lines |
| 485 | ' |
| 486 | |
Heiko Voigt | be9d0a3 | 2012-08-14 22:35:27 +0200 | [diff] [blame] | 487 | test_failure_with_unknown_submodule () { |
| 488 | test_must_fail git submodule $1 no-such-submodule 2>output.err && |
Nguyễn Thái Ngọc Duy | a80897c | 2018-07-21 09:49:30 +0200 | [diff] [blame] | 489 | test_i18ngrep "^error: .*no-such-submodule" output.err |
Heiko Voigt | be9d0a3 | 2012-08-14 22:35:27 +0200 | [diff] [blame] | 490 | } |
| 491 | |
| 492 | test_expect_success 'init should fail with unknown submodule' ' |
| 493 | test_failure_with_unknown_submodule init |
| 494 | ' |
| 495 | |
| 496 | test_expect_success 'update should fail with unknown submodule' ' |
| 497 | test_failure_with_unknown_submodule update |
| 498 | ' |
| 499 | |
| 500 | test_expect_success 'status should fail with unknown submodule' ' |
| 501 | test_failure_with_unknown_submodule status |
| 502 | ' |
| 503 | |
| 504 | test_expect_success 'sync should fail with unknown submodule' ' |
| 505 | test_failure_with_unknown_submodule sync |
| 506 | ' |
| 507 | |
Lars Hjemli | 211b7f1 | 2007-06-06 11:13:02 +0200 | [diff] [blame] | 508 | 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] | 509 | echo hello >expect && |
| 510 | |
Junio C Hamano | a2d93ae | 2008-01-15 03:13:55 -0800 | [diff] [blame] | 511 | echo "hello" >init && |
Jonathan Nieder | ce8b54d | 2010-04-10 00:39:41 -0500 | [diff] [blame] | 512 | test_must_fail git submodule update && |
| 513 | |
| 514 | test_cmp expect init |
Lars Hjemli | 88961ef | 2007-06-02 03:27:42 +0200 | [diff] [blame] | 515 | ' |
| 516 | |
Lars Hjemli | 211b7f1 | 2007-06-06 11:13:02 +0200 | [diff] [blame] | 517 | 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] | 518 | echo hello >expect && |
| 519 | |
| 520 | rm -fr init && |
Junio C Hamano | a2d93ae | 2008-01-15 03:13:55 -0800 | [diff] [blame] | 521 | mkdir init && |
| 522 | echo "hello" >init/a && |
Jonathan Nieder | ce8b54d | 2010-04-10 00:39:41 -0500 | [diff] [blame] | 523 | |
| 524 | test_must_fail git submodule update && |
| 525 | |
| 526 | test_cmp expect init/a |
Lars Hjemli | 88961ef | 2007-06-02 03:27:42 +0200 | [diff] [blame] | 527 | ' |
| 528 | |
Lars Hjemli | 211b7f1 | 2007-06-06 11:13:02 +0200 | [diff] [blame] | 529 | test_expect_success 'update should work when path is an empty dir' ' |
Jonathan Nieder | ce8b54d | 2010-04-10 00:39:41 -0500 | [diff] [blame] | 530 | rm -fr init && |
| 531 | rm -f head-sha1 && |
| 532 | echo "$rev1" >expect && |
| 533 | |
Junio C Hamano | a2d93ae | 2008-01-15 03:13:55 -0800 | [diff] [blame] | 534 | mkdir init && |
Jens Lehmann | 7e60407 | 2011-07-26 23:39:03 +0200 | [diff] [blame] | 535 | git submodule update -q >update.out && |
Junio C Hamano | ca8d148 | 2013-06-09 11:29:20 -0700 | [diff] [blame] | 536 | test_must_be_empty update.out && |
Jonathan Nieder | ce8b54d | 2010-04-10 00:39:41 -0500 | [diff] [blame] | 537 | |
| 538 | inspect init && |
| 539 | test_cmp expect head-sha1 |
Lars Hjemli | 88961ef | 2007-06-02 03:27:42 +0200 | [diff] [blame] | 540 | ' |
| 541 | |
Lars Hjemli | 211b7f1 | 2007-06-06 11:13:02 +0200 | [diff] [blame] | 542 | test_expect_success 'status should be "up-to-date" after update' ' |
Jonathan Nieder | ce8b54d | 2010-04-10 00:39:41 -0500 | [diff] [blame] | 543 | git submodule status >list && |
| 544 | grep "^ $rev1" list |
Lars Hjemli | 88961ef | 2007-06-02 03:27:42 +0200 | [diff] [blame] | 545 | ' |
| 546 | |
John Keeping | 091a6eb | 2013-06-16 15:18:18 +0100 | [diff] [blame] | 547 | test_expect_success 'status "up-to-date" from subdirectory' ' |
| 548 | mkdir -p sub && |
| 549 | ( |
| 550 | cd sub && |
| 551 | git submodule status >../list |
| 552 | ) && |
| 553 | grep "^ $rev1" list && |
| 554 | grep "\\.\\./init" list |
| 555 | ' |
| 556 | |
| 557 | test_expect_success 'status "up-to-date" from subdirectory with path' ' |
| 558 | mkdir -p sub && |
| 559 | ( |
| 560 | cd sub && |
| 561 | git submodule status ../init >../list |
| 562 | ) && |
| 563 | grep "^ $rev1" list && |
| 564 | grep "\\.\\./init" list |
| 565 | ' |
| 566 | |
Lars Hjemli | 88961ef | 2007-06-02 03:27:42 +0200 | [diff] [blame] | 567 | test_expect_success 'status should be "modified" after submodule commit' ' |
Jonathan Nieder | ce8b54d | 2010-04-10 00:39:41 -0500 | [diff] [blame] | 568 | ( |
| 569 | cd init && |
| 570 | echo b >b && |
| 571 | git add b && |
| 572 | git commit -m "submodule commit 2" |
| 573 | ) && |
| 574 | |
| 575 | rev2=$(cd init && git rev-parse HEAD) && |
| 576 | test -n "$rev2" && |
| 577 | git submodule status >list && |
| 578 | |
| 579 | grep "^+$rev2" list |
Lars Hjemli | 88961ef | 2007-06-02 03:27:42 +0200 | [diff] [blame] | 580 | ' |
| 581 | |
Ævar Arnfjörð Bjarmason | 44874cb | 2022-11-08 15:10:33 +0100 | [diff] [blame] | 582 | test_expect_success '"submodule --cached" command forms should be identical' ' |
| 583 | git submodule status --cached >expect && |
| 584 | |
| 585 | git submodule --cached >actual && |
| 586 | test_cmp expect actual && |
| 587 | |
| 588 | git submodule --cached status >actual && |
| 589 | test_cmp expect actual |
| 590 | ' |
| 591 | |
Lars Hjemli | 88961ef | 2007-06-02 03:27:42 +0200 | [diff] [blame] | 592 | test_expect_success 'the --cached sha1 should be rev1' ' |
Jonathan Nieder | ce8b54d | 2010-04-10 00:39:41 -0500 | [diff] [blame] | 593 | git submodule --cached status >list && |
| 594 | grep "^+$rev1" list |
Lars Hjemli | 88961ef | 2007-06-02 03:27:42 +0200 | [diff] [blame] | 595 | ' |
| 596 | |
Sven Verdoolaege | 5701115 | 2007-09-08 12:30:22 +0200 | [diff] [blame] | 597 | 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] | 598 | git diff >diff && |
| 599 | grep "^+Subproject commit $rev2" diff |
Sven Verdoolaege | 5701115 | 2007-09-08 12:30:22 +0200 | [diff] [blame] | 600 | ' |
| 601 | |
Lars Hjemli | 88961ef | 2007-06-02 03:27:42 +0200 | [diff] [blame] | 602 | test_expect_success 'update should checkout rev1' ' |
Jonathan Nieder | ce8b54d | 2010-04-10 00:39:41 -0500 | [diff] [blame] | 603 | rm -f head-sha1 && |
| 604 | echo "$rev1" >expect && |
| 605 | |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 606 | git submodule update init && |
Jonathan Nieder | ce8b54d | 2010-04-10 00:39:41 -0500 | [diff] [blame] | 607 | inspect init && |
| 608 | |
| 609 | test_cmp expect head-sha1 |
Lars Hjemli | 88961ef | 2007-06-02 03:27:42 +0200 | [diff] [blame] | 610 | ' |
| 611 | |
| 612 | test_expect_success 'status should be "up-to-date" after update' ' |
Jonathan Nieder | ce8b54d | 2010-04-10 00:39:41 -0500 | [diff] [blame] | 613 | git submodule status >list && |
| 614 | grep "^ $rev1" list |
Lars Hjemli | 88961ef | 2007-06-02 03:27:42 +0200 | [diff] [blame] | 615 | ' |
| 616 | |
Sven Verdoolaege | 0cf7375 | 2007-07-17 20:28:28 +0200 | [diff] [blame] | 617 | test_expect_success 'checkout superproject with subproject already present' ' |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 618 | git checkout initial && |
Johannes Schindelin | 01dc813 | 2020-11-18 23:44:39 +0000 | [diff] [blame] | 619 | git checkout main |
Sven Verdoolaege | 0cf7375 | 2007-07-17 20:28:28 +0200 | [diff] [blame] | 620 | ' |
| 621 | |
Sven Verdoolaege | e06c5a6 | 2007-08-15 19:22:09 +0200 | [diff] [blame] | 622 | test_expect_success 'apply submodule diff' ' |
| 623 | git branch second && |
| 624 | ( |
Junio C Hamano | a2d93ae | 2008-01-15 03:13:55 -0800 | [diff] [blame] | 625 | cd init && |
Sven Verdoolaege | e06c5a6 | 2007-08-15 19:22:09 +0200 | [diff] [blame] | 626 | echo s >s && |
| 627 | git add s && |
| 628 | git commit -m "change subproject" |
| 629 | ) && |
Junio C Hamano | a2d93ae | 2008-01-15 03:13:55 -0800 | [diff] [blame] | 630 | git update-index --add init && |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 631 | git commit -m "change init" && |
| 632 | git format-patch -1 --stdout >P.diff && |
Sven Verdoolaege | e06c5a6 | 2007-08-15 19:22:09 +0200 | [diff] [blame] | 633 | git checkout second && |
| 634 | git apply --index P.diff && |
Jonathan Nieder | ce8b54d | 2010-04-10 00:39:41 -0500 | [diff] [blame] | 635 | |
Johannes Schindelin | 01dc813 | 2020-11-18 23:44:39 +0000 | [diff] [blame] | 636 | git diff --cached main >staged && |
SZEDER Gábor | 1c5e94f | 2018-08-19 23:57:25 +0200 | [diff] [blame] | 637 | test_must_be_empty staged |
Sven Verdoolaege | e06c5a6 | 2007-08-15 19:22:09 +0200 | [diff] [blame] | 638 | ' |
| 639 | |
Johannes Schindelin | be4d2c8 | 2008-05-16 11:23:03 +0100 | [diff] [blame] | 640 | test_expect_success 'update --init' ' |
Johannes Schindelin | be4d2c8 | 2008-05-16 11:23:03 +0100 | [diff] [blame] | 641 | mv init init2 && |
| 642 | git config -f .gitmodules submodule.example.url "$(pwd)/init2" && |
Jonathan Nieder | ce8b54d | 2010-04-10 00:39:41 -0500 | [diff] [blame] | 643 | git config --remove-section submodule.example && |
| 644 | test_must_fail git config submodule.example.url && |
| 645 | |
Stefan Beller | 8c6b549 | 2016-02-29 18:07:14 -0800 | [diff] [blame] | 646 | git submodule update init 2> update.out && |
Ævar Arnfjörð Bjarmason | 1c2ef66 | 2011-05-21 18:44:08 +0000 | [diff] [blame] | 647 | test_i18ngrep "not initialized" update.out && |
Fredrik Gustafsson | abc0682 | 2011-08-15 23:17:46 +0200 | [diff] [blame] | 648 | test_must_fail git rev-parse --resolve-git-dir init/.git && |
Jonathan Nieder | ce8b54d | 2010-04-10 00:39:41 -0500 | [diff] [blame] | 649 | |
Johannes Schindelin | be4d2c8 | 2008-05-16 11:23:03 +0100 | [diff] [blame] | 650 | git submodule update --init init && |
Fredrik Gustafsson | abc0682 | 2011-08-15 23:17:46 +0200 | [diff] [blame] | 651 | git rev-parse --resolve-git-dir init/.git |
Johannes Schindelin | be4d2c8 | 2008-05-16 11:23:03 +0100 | [diff] [blame] | 652 | ' |
| 653 | |
John Keeping | 091a6eb | 2013-06-16 15:18:18 +0100 | [diff] [blame] | 654 | test_expect_success 'update --init from subdirectory' ' |
| 655 | mv init init2 && |
| 656 | git config -f .gitmodules submodule.example.url "$(pwd)/init2" && |
| 657 | git config --remove-section submodule.example && |
| 658 | test_must_fail git config submodule.example.url && |
| 659 | |
| 660 | mkdir -p sub && |
| 661 | ( |
| 662 | cd sub && |
Stefan Beller | 8c6b549 | 2016-02-29 18:07:14 -0800 | [diff] [blame] | 663 | git submodule update ../init 2>update.out && |
John Keeping | 091a6eb | 2013-06-16 15:18:18 +0100 | [diff] [blame] | 664 | test_i18ngrep "not initialized" update.out && |
| 665 | test_must_fail git rev-parse --resolve-git-dir ../init/.git && |
| 666 | |
| 667 | git submodule update --init ../init |
| 668 | ) && |
| 669 | git rev-parse --resolve-git-dir init/.git |
| 670 | ' |
| 671 | |
Johannes Schindelin | 2ce53f9 | 2009-01-02 19:08:40 +0100 | [diff] [blame] | 672 | test_expect_success 'do not add files from a submodule' ' |
| 673 | |
| 674 | git reset --hard && |
| 675 | test_must_fail git add init/a |
| 676 | |
| 677 | ' |
| 678 | |
John Keeping | 2c63d6e | 2013-09-12 20:25:01 +0100 | [diff] [blame] | 679 | test_expect_success 'gracefully add/reset submodule with a trailing slash' ' |
Johannes Schindelin | 2ce53f9 | 2009-01-02 19:08:40 +0100 | [diff] [blame] | 680 | |
| 681 | git reset --hard && |
| 682 | git commit -m "commit subproject" init && |
| 683 | (cd init && |
| 684 | echo b > a) && |
| 685 | git add init/ && |
| 686 | git diff --exit-code --cached init && |
| 687 | commit=$(cd init && |
| 688 | git commit -m update a >/dev/null && |
| 689 | git rev-parse HEAD) && |
| 690 | git add init/ && |
| 691 | test_must_fail git diff --exit-code --cached init && |
| 692 | test $commit = $(git ls-files --stage | |
John Keeping | 2c63d6e | 2013-09-12 20:25:01 +0100 | [diff] [blame] | 693 | sed -n "s/^160000 \([^ ]*\).*/\1/p") && |
| 694 | git reset init/ && |
| 695 | git diff --exit-code --cached init |
Johannes Schindelin | 2ce53f9 | 2009-01-02 19:08:40 +0100 | [diff] [blame] | 696 | |
| 697 | ' |
| 698 | |
Johannes Schindelin | f3670a5 | 2009-02-07 14:43:03 +0100 | [diff] [blame] | 699 | test_expect_success 'ls-files gracefully handles trailing slash' ' |
| 700 | |
| 701 | test "init" = "$(git ls-files init/)" |
| 702 | |
| 703 | ' |
| 704 | |
Peter Collingbourne | c5e558a | 2010-01-11 02:59:54 +0000 | [diff] [blame] | 705 | test_expect_success 'moving to a commit without submodule does not leave empty dir' ' |
| 706 | rm -rf init && |
| 707 | mkdir init && |
| 708 | git reset --hard && |
| 709 | git checkout initial && |
| 710 | test ! -d init && |
| 711 | git checkout second |
| 712 | ' |
| 713 | |
Ramkumar Ramachandra | af9c9f9 | 2012-09-22 16:57:59 +0530 | [diff] [blame] | 714 | test_expect_success 'submodule <invalid-subcommand> fails' ' |
| 715 | test_must_fail git submodule no-such-subcommand |
Johannes Schindelin | 496917b | 2009-02-07 14:43:15 +0100 | [diff] [blame] | 716 | ' |
| 717 | |
Jens Lehmann | 1414e57 | 2009-09-22 17:10:12 +0200 | [diff] [blame] | 718 | test_expect_success 'add submodules without specifying an explicit path' ' |
| 719 | mkdir repo && |
Jonathan Nieder | 18a8269 | 2010-09-06 20:42:54 -0500 | [diff] [blame] | 720 | ( |
| 721 | cd repo && |
| 722 | git init && |
| 723 | echo r >r && |
| 724 | git add r && |
| 725 | git commit -m "repo commit 1" |
Jens Lehmann | fd4ec4f | 2010-09-06 20:39:54 +0200 | [diff] [blame] | 726 | ) && |
Jens Lehmann | 1414e57 | 2009-09-22 17:10:12 +0200 | [diff] [blame] | 727 | git clone --bare repo/ bare.git && |
Jens Lehmann | 69e7236 | 2010-12-05 00:27:35 +0100 | [diff] [blame] | 728 | ( |
| 729 | cd addtest && |
| 730 | git submodule add "$submodurl/repo" && |
| 731 | git config -f .gitmodules submodule.repo.path repo && |
| 732 | git submodule add "$submodurl/bare.git" && |
| 733 | git config -f .gitmodules submodule.bare.path bare |
| 734 | ) |
| 735 | ' |
| 736 | |
| 737 | test_expect_success 'add should fail when path is used by a file' ' |
| 738 | ( |
| 739 | cd addtest && |
| 740 | touch file && |
| 741 | test_must_fail git submodule add "$submodurl/repo" file |
| 742 | ) |
| 743 | ' |
| 744 | |
| 745 | test_expect_success 'add should fail when path is used by an existing directory' ' |
| 746 | ( |
| 747 | cd addtest && |
| 748 | mkdir empty-dir && |
| 749 | test_must_fail git submodule add "$submodurl/repo" empty-dir |
| 750 | ) |
Jens Lehmann | 1414e57 | 2009-09-22 17:10:12 +0200 | [diff] [blame] | 751 | ' |
| 752 | |
Jens Lehmann | 4d68932 | 2011-06-06 21:58:04 +0200 | [diff] [blame] | 753 | 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] | 754 | ( |
| 755 | cd addtest && |
Jens Lehmann | 4d68932 | 2011-06-06 21:58:04 +0200 | [diff] [blame] | 756 | git submodule add ../repo relative && |
| 757 | test "$(git config -f .gitmodules submodule.relative.url)" = ../repo && |
| 758 | git submodule sync relative && |
| 759 | test "$(git config submodule.relative.url)" = "$submodurl/repo" |
Jens Lehmann | 8537f0e | 2011-06-06 21:57:01 +0200 | [diff] [blame] | 760 | ) |
| 761 | ' |
| 762 | |
Thomas Rast | ea640cc | 2011-01-10 11:37:26 +0100 | [diff] [blame] | 763 | test_expect_success 'set up for relative path tests' ' |
| 764 | mkdir reltest && |
| 765 | ( |
| 766 | cd reltest && |
| 767 | git init && |
| 768 | mkdir sub && |
| 769 | ( |
| 770 | cd sub && |
| 771 | git init && |
| 772 | test_commit foo |
| 773 | ) && |
| 774 | git add sub && |
| 775 | git config -f .gitmodules submodule.sub.path sub && |
| 776 | git config -f .gitmodules submodule.sub.url ../subrepo && |
Jon Seymour | 712693e | 2012-06-03 19:46:47 +1000 | [diff] [blame] | 777 | cp .git/config pristine-.git-config && |
| 778 | cp .gitmodules pristine-.gitmodules |
Thomas Rast | ea640cc | 2011-01-10 11:37:26 +0100 | [diff] [blame] | 779 | ) |
| 780 | ' |
| 781 | |
Jon Seymour | 712693e | 2012-06-03 19:46:47 +1000 | [diff] [blame] | 782 | test_expect_success '../subrepo works with URL - ssh://hostname/repo' ' |
Thomas Rast | ea640cc | 2011-01-10 11:37:26 +0100 | [diff] [blame] | 783 | ( |
| 784 | cd reltest && |
| 785 | cp pristine-.git-config .git/config && |
Jon Seymour | 712693e | 2012-06-03 19:46:47 +1000 | [diff] [blame] | 786 | cp pristine-.gitmodules .gitmodules && |
Thomas Rast | ea640cc | 2011-01-10 11:37:26 +0100 | [diff] [blame] | 787 | git config remote.origin.url ssh://hostname/repo && |
| 788 | git submodule init && |
| 789 | test "$(git config submodule.sub.url)" = ssh://hostname/subrepo |
| 790 | ) |
| 791 | ' |
| 792 | |
Jon Seymour | 712693e | 2012-06-03 19:46:47 +1000 | [diff] [blame] | 793 | test_expect_success '../subrepo works with port-qualified URL - ssh://hostname:22/repo' ' |
| 794 | ( |
| 795 | cd reltest && |
| 796 | cp pristine-.git-config .git/config && |
| 797 | cp pristine-.gitmodules .gitmodules && |
| 798 | git config remote.origin.url ssh://hostname:22/repo && |
| 799 | git submodule init && |
| 800 | test "$(git config submodule.sub.url)" = ssh://hostname:22/subrepo |
| 801 | ) |
| 802 | ' |
| 803 | |
Johannes Sixt | c517e73 | 2012-06-14 14:10:27 +0200 | [diff] [blame] | 804 | # About the choice of the path in the next test: |
| 805 | # - double-slash side-steps path mangling issues on Windows |
| 806 | # - it is still an absolute local path |
| 807 | # - there cannot be a server with a blank in its name just in case the |
| 808 | # path is used erroneously to access a //server/share style path |
| 809 | test_expect_success '../subrepo path works with local path - //somewhere else/repo' ' |
Jon Seymour | 712693e | 2012-06-03 19:46:47 +1000 | [diff] [blame] | 810 | ( |
| 811 | cd reltest && |
| 812 | cp pristine-.git-config .git/config && |
| 813 | cp pristine-.gitmodules .gitmodules && |
Johannes Sixt | c517e73 | 2012-06-14 14:10:27 +0200 | [diff] [blame] | 814 | git config remote.origin.url "//somewhere else/repo" && |
Jon Seymour | 712693e | 2012-06-03 19:46:47 +1000 | [diff] [blame] | 815 | git submodule init && |
Johannes Sixt | c517e73 | 2012-06-14 14:10:27 +0200 | [diff] [blame] | 816 | test "$(git config submodule.sub.url)" = "//somewhere else/subrepo" |
Jon Seymour | 712693e | 2012-06-03 19:46:47 +1000 | [diff] [blame] | 817 | ) |
| 818 | ' |
| 819 | |
| 820 | test_expect_success '../subrepo works with file URL - file:///tmp/repo' ' |
| 821 | ( |
| 822 | cd reltest && |
| 823 | cp pristine-.git-config .git/config && |
| 824 | cp pristine-.gitmodules .gitmodules && |
| 825 | git config remote.origin.url file:///tmp/repo && |
| 826 | git submodule init && |
| 827 | test "$(git config submodule.sub.url)" = file:///tmp/subrepo |
| 828 | ) |
| 829 | ' |
| 830 | |
| 831 | test_expect_success '../subrepo works with helper URL- helper:://hostname/repo' ' |
| 832 | ( |
| 833 | cd reltest && |
| 834 | cp pristine-.git-config .git/config && |
| 835 | cp pristine-.gitmodules .gitmodules && |
| 836 | git config remote.origin.url helper:://hostname/repo && |
| 837 | git submodule init && |
| 838 | test "$(git config submodule.sub.url)" = helper:://hostname/subrepo |
| 839 | ) |
| 840 | ' |
| 841 | |
| 842 | test_expect_success '../subrepo works with scp-style URL - user@host:repo' ' |
Thomas Rast | ea640cc | 2011-01-10 11:37:26 +0100 | [diff] [blame] | 843 | ( |
| 844 | cd reltest && |
| 845 | cp pristine-.git-config .git/config && |
| 846 | git config remote.origin.url user@host:repo && |
| 847 | git submodule init && |
| 848 | test "$(git config submodule.sub.url)" = user@host:subrepo |
| 849 | ) |
| 850 | ' |
| 851 | |
Jon Seymour | 712693e | 2012-06-03 19:46:47 +1000 | [diff] [blame] | 852 | test_expect_success '../subrepo works with scp-style URL - user@host:path/to/repo' ' |
| 853 | ( |
| 854 | cd reltest && |
| 855 | cp pristine-.git-config .git/config && |
| 856 | cp pristine-.gitmodules .gitmodules && |
| 857 | git config remote.origin.url user@host:path/to/repo && |
| 858 | git submodule init && |
| 859 | test "$(git config submodule.sub.url)" = user@host:path/to/subrepo |
| 860 | ) |
| 861 | ' |
| 862 | |
Jon Seymour | 758615e | 2012-06-06 21:57:30 +1000 | [diff] [blame] | 863 | test_expect_success '../subrepo works with relative local path - foo' ' |
Jon Seymour | 49301c6 | 2012-06-03 19:46:48 +1000 | [diff] [blame] | 864 | ( |
| 865 | cd reltest && |
| 866 | cp pristine-.git-config .git/config && |
| 867 | cp pristine-.gitmodules .gitmodules && |
| 868 | git config remote.origin.url foo && |
| 869 | # actual: fails with an error |
| 870 | git submodule init && |
| 871 | test "$(git config submodule.sub.url)" = subrepo |
| 872 | ) |
| 873 | ' |
| 874 | |
Jon Seymour | 712693e | 2012-06-03 19:46:47 +1000 | [diff] [blame] | 875 | test_expect_success '../subrepo works with relative local path - foo/bar' ' |
| 876 | ( |
| 877 | cd reltest && |
| 878 | cp pristine-.git-config .git/config && |
| 879 | cp pristine-.gitmodules .gitmodules && |
| 880 | git config remote.origin.url foo/bar && |
| 881 | git submodule init && |
| 882 | test "$(git config submodule.sub.url)" = foo/subrepo |
| 883 | ) |
| 884 | ' |
| 885 | |
Jon Seymour | 758615e | 2012-06-06 21:57:30 +1000 | [diff] [blame] | 886 | test_expect_success '../subrepo works with relative local path - ./foo' ' |
Jon Seymour | 49301c6 | 2012-06-03 19:46:48 +1000 | [diff] [blame] | 887 | ( |
| 888 | cd reltest && |
| 889 | cp pristine-.git-config .git/config && |
| 890 | cp pristine-.gitmodules .gitmodules && |
| 891 | git config remote.origin.url ./foo && |
| 892 | git submodule init && |
| 893 | test "$(git config submodule.sub.url)" = subrepo |
| 894 | ) |
| 895 | ' |
| 896 | |
Jon Seymour | 758615e | 2012-06-06 21:57:30 +1000 | [diff] [blame] | 897 | test_expect_success '../subrepo works with relative local path - ./foo/bar' ' |
Jon Seymour | 49301c6 | 2012-06-03 19:46:48 +1000 | [diff] [blame] | 898 | ( |
| 899 | cd reltest && |
| 900 | cp pristine-.git-config .git/config && |
| 901 | cp pristine-.gitmodules .gitmodules && |
| 902 | git config remote.origin.url ./foo/bar && |
| 903 | git submodule init && |
| 904 | test "$(git config submodule.sub.url)" = foo/subrepo |
| 905 | ) |
| 906 | ' |
| 907 | |
Jon Seymour | 712693e | 2012-06-03 19:46:47 +1000 | [diff] [blame] | 908 | test_expect_success '../subrepo works with relative local path - ../foo' ' |
| 909 | ( |
| 910 | cd reltest && |
| 911 | cp pristine-.git-config .git/config && |
| 912 | cp pristine-.gitmodules .gitmodules && |
| 913 | git config remote.origin.url ../foo && |
| 914 | git submodule init && |
| 915 | test "$(git config submodule.sub.url)" = ../subrepo |
| 916 | ) |
| 917 | ' |
| 918 | |
| 919 | test_expect_success '../subrepo works with relative local path - ../foo/bar' ' |
| 920 | ( |
| 921 | cd reltest && |
| 922 | cp pristine-.git-config .git/config && |
| 923 | cp pristine-.gitmodules .gitmodules && |
| 924 | git config remote.origin.url ../foo/bar && |
| 925 | git submodule init && |
| 926 | test "$(git config submodule.sub.url)" = ../foo/subrepo |
| 927 | ) |
| 928 | ' |
| 929 | |
| 930 | test_expect_success '../bar/a/b/c works with relative local path - ../foo/bar.git' ' |
| 931 | ( |
| 932 | cd reltest && |
| 933 | cp pristine-.git-config .git/config && |
| 934 | cp pristine-.gitmodules .gitmodules && |
| 935 | mkdir -p a/b/c && |
Kyle Meyer | e138111 | 2019-04-09 19:07:35 -0400 | [diff] [blame] | 936 | (cd a/b/c && git init && test_commit msg) && |
Jon Seymour | 712693e | 2012-06-03 19:46:47 +1000 | [diff] [blame] | 937 | git config remote.origin.url ../foo/bar.git && |
| 938 | git submodule add ../bar/a/b/c ./a/b/c && |
| 939 | git submodule init && |
| 940 | test "$(git config submodule.a/b/c.url)" = ../foo/bar/a/b/c |
| 941 | ) |
| 942 | ' |
| 943 | |
Jens Lehmann | d75219b | 2012-03-04 22:15:08 +0100 | [diff] [blame] | 944 | test_expect_success 'moving the superproject does not break submodules' ' |
| 945 | ( |
| 946 | cd addtest && |
| 947 | git submodule status >expect |
Jeff King | 99094a7 | 2015-03-20 06:07:15 -0400 | [diff] [blame] | 948 | ) && |
Jens Lehmann | d75219b | 2012-03-04 22:15:08 +0100 | [diff] [blame] | 949 | mv addtest addtest2 && |
| 950 | ( |
| 951 | cd addtest2 && |
| 952 | git submodule status >actual && |
| 953 | test_cmp expect actual |
| 954 | ) |
| 955 | ' |
| 956 | |
René Scharfe | 74b6bda | 2018-03-28 23:14:08 +0200 | [diff] [blame] | 957 | test_expect_success 'moving the submodule does not break the superproject' ' |
| 958 | ( |
| 959 | cd addtest2 && |
| 960 | git submodule status |
| 961 | ) >actual && |
| 962 | sed -e "s/^ \([^ ]* repo\) .*/-\1/" <actual >expect && |
| 963 | mv addtest2/repo addtest2/repo.bak && |
| 964 | test_when_finished "mv addtest2/repo.bak addtest2/repo" && |
| 965 | ( |
| 966 | cd addtest2 && |
| 967 | git submodule status |
| 968 | ) >actual && |
| 969 | test_cmp expect actual |
| 970 | ' |
| 971 | |
Jens Lehmann | 73b0898 | 2012-09-30 01:05:58 +0200 | [diff] [blame] | 972 | test_expect_success 'submodule add --name allows to replace a submodule with another at the same path' ' |
| 973 | ( |
| 974 | cd addtest2 && |
| 975 | ( |
| 976 | cd repo && |
| 977 | echo "$submodurl/repo" >expect && |
| 978 | git config remote.origin.url >actual && |
| 979 | test_cmp expect actual && |
| 980 | echo "gitdir: ../.git/modules/repo" >expect && |
| 981 | test_cmp expect .git |
| 982 | ) && |
| 983 | rm -rf repo && |
| 984 | git rm repo && |
| 985 | 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] | 986 | test_must_be_empty actual && |
Jens Lehmann | 73b0898 | 2012-09-30 01:05:58 +0200 | [diff] [blame] | 987 | echo "gitdir: ../.git/modules/submod" >expect && |
| 988 | test_cmp expect submod/.git && |
| 989 | ( |
| 990 | cd repo && |
| 991 | echo "$submodurl/bare.git" >expect && |
| 992 | git config remote.origin.url >actual && |
| 993 | test_cmp expect actual && |
| 994 | echo "gitdir: ../.git/modules/repo_new" >expect && |
| 995 | test_cmp expect .git |
| 996 | ) && |
| 997 | echo "repo" >expect && |
Jens Lehmann | 95c1641 | 2013-08-06 21:15:25 +0200 | [diff] [blame] | 998 | test_must_fail git config -f .gitmodules submodule.repo.path && |
Jens Lehmann | 73b0898 | 2012-09-30 01:05:58 +0200 | [diff] [blame] | 999 | git config -f .gitmodules submodule.repo_new.path >actual && |
Andrei Rybak | 64d1022 | 2020-03-22 22:14:22 +0100 | [diff] [blame] | 1000 | test_cmp expect actual && |
Jens Lehmann | 73b0898 | 2012-09-30 01:05:58 +0200 | [diff] [blame] | 1001 | echo "$submodurl/repo" >expect && |
Jens Lehmann | 95c1641 | 2013-08-06 21:15:25 +0200 | [diff] [blame] | 1002 | test_must_fail git config -f .gitmodules submodule.repo.url && |
Jens Lehmann | 73b0898 | 2012-09-30 01:05:58 +0200 | [diff] [blame] | 1003 | echo "$submodurl/bare.git" >expect && |
| 1004 | git config -f .gitmodules submodule.repo_new.url >actual && |
| 1005 | test_cmp expect actual && |
| 1006 | echo "$submodurl/repo" >expect && |
| 1007 | git config submodule.repo.url >actual && |
| 1008 | test_cmp expect actual && |
| 1009 | echo "$submodurl/bare.git" >expect && |
| 1010 | git config submodule.repo_new.url >actual && |
| 1011 | test_cmp expect actual |
| 1012 | ) |
| 1013 | ' |
| 1014 | |
Stefan Beller | f8eaa0b | 2016-03-31 17:17:28 -0700 | [diff] [blame] | 1015 | test_expect_success 'recursive relative submodules stay relative' ' |
Stefan Beller | 3fea121 | 2016-03-31 14:04:36 -0700 | [diff] [blame] | 1016 | test_when_finished "rm -rf super clone2 subsub sub3" && |
| 1017 | mkdir subsub && |
| 1018 | ( |
| 1019 | cd subsub && |
| 1020 | git init && |
| 1021 | >t && |
| 1022 | git add t && |
| 1023 | git commit -m "initial commit" |
| 1024 | ) && |
| 1025 | mkdir sub3 && |
| 1026 | ( |
| 1027 | cd sub3 && |
| 1028 | git init && |
| 1029 | >t && |
| 1030 | git add t && |
| 1031 | git commit -m "initial commit" && |
| 1032 | git submodule add ../subsub dirdir/subsub && |
| 1033 | git commit -m "add submodule subsub" |
| 1034 | ) && |
| 1035 | mkdir super && |
| 1036 | ( |
| 1037 | cd super && |
| 1038 | git init && |
| 1039 | >t && |
| 1040 | git add t && |
| 1041 | git commit -m "initial commit" && |
| 1042 | git submodule add ../sub3 && |
| 1043 | git commit -m "add submodule sub" |
| 1044 | ) && |
| 1045 | git clone super clone2 && |
| 1046 | ( |
| 1047 | cd clone2 && |
| 1048 | git submodule update --init --recursive && |
| 1049 | echo "gitdir: ../.git/modules/sub3" >./sub3/.git_expect && |
| 1050 | echo "gitdir: ../../../.git/modules/sub3/modules/dirdir/subsub" >./sub3/dirdir/subsub/.git_expect |
| 1051 | ) && |
| 1052 | test_cmp clone2/sub3/.git_expect clone2/sub3/.git && |
| 1053 | test_cmp clone2/sub3/dirdir/subsub/.git_expect clone2/sub3/dirdir/subsub/.git |
| 1054 | ' |
| 1055 | |
Jens Lehmann | 4b7c286 | 2012-09-30 23:01:29 +0200 | [diff] [blame] | 1056 | test_expect_success 'submodule add with an existing name fails unless forced' ' |
| 1057 | ( |
| 1058 | cd addtest2 && |
| 1059 | rm -rf repo && |
| 1060 | git rm repo && |
| 1061 | test_must_fail git submodule add -q --name repo_new "$submodurl/repo.git" repo && |
| 1062 | test ! -d repo && |
Jens Lehmann | 95c1641 | 2013-08-06 21:15:25 +0200 | [diff] [blame] | 1063 | test_must_fail git config -f .gitmodules submodule.repo_new.path && |
| 1064 | test_must_fail git config -f .gitmodules submodule.repo_new.url && |
Jens Lehmann | 4b7c286 | 2012-09-30 23:01:29 +0200 | [diff] [blame] | 1065 | echo "$submodurl/bare.git" >expect && |
| 1066 | git config submodule.repo_new.url >actual && |
| 1067 | test_cmp expect actual && |
| 1068 | git submodule add -f -q --name repo_new "$submodurl/repo.git" repo && |
| 1069 | test -d repo && |
| 1070 | echo "repo" >expect && |
| 1071 | git config -f .gitmodules submodule.repo_new.path >actual && |
Andrei Rybak | 64d1022 | 2020-03-22 22:14:22 +0100 | [diff] [blame] | 1072 | test_cmp expect actual && |
Jens Lehmann | 4b7c286 | 2012-09-30 23:01:29 +0200 | [diff] [blame] | 1073 | echo "$submodurl/repo.git" >expect && |
| 1074 | git config -f .gitmodules submodule.repo_new.url >actual && |
| 1075 | test_cmp expect actual && |
| 1076 | echo "$submodurl/repo.git" >expect && |
| 1077 | git config submodule.repo_new.url >actual && |
| 1078 | test_cmp expect actual |
| 1079 | ) |
| 1080 | ' |
| 1081 | |
Jens Lehmann | cf41982 | 2013-03-04 22:20:24 +0100 | [diff] [blame] | 1082 | test_expect_success 'set up a second submodule' ' |
| 1083 | git submodule add ./init2 example2 && |
| 1084 | git commit -m "submodule example2 added" |
| 1085 | ' |
| 1086 | |
Stefan Beller | 84ba959 | 2016-03-22 16:42:14 -0700 | [diff] [blame] | 1087 | test_expect_success 'submodule deinit works on repository without submodules' ' |
| 1088 | test_when_finished "rm -rf newdirectory" && |
| 1089 | mkdir newdirectory && |
| 1090 | ( |
| 1091 | cd newdirectory && |
| 1092 | git init && |
| 1093 | >file && |
| 1094 | git add file && |
Stefan Beller | 14544dd | 2016-05-02 15:24:02 -0700 | [diff] [blame] | 1095 | git commit -m "repo should not be empty" && |
Stefan Beller | f6a5279 | 2016-05-05 12:52:32 -0700 | [diff] [blame] | 1096 | git submodule deinit . && |
| 1097 | git submodule deinit --all |
Stefan Beller | 84ba959 | 2016-03-22 16:42:14 -0700 | [diff] [blame] | 1098 | ) |
| 1099 | ' |
| 1100 | |
Jens Lehmann | cf41982 | 2013-03-04 22:20:24 +0100 | [diff] [blame] | 1101 | test_expect_success 'submodule deinit should remove the whole submodule section from .git/config' ' |
| 1102 | git config submodule.example.foo bar && |
| 1103 | git config submodule.example2.frotz nitfol && |
| 1104 | git submodule deinit init && |
| 1105 | test -z "$(git config --get-regexp "submodule\.example\.")" && |
| 1106 | test -n "$(git config --get-regexp "submodule\.example2\.")" && |
| 1107 | test -f example2/.git && |
| 1108 | rmdir init |
| 1109 | ' |
| 1110 | |
Stefan Beller | 8eda5ef | 2018-12-14 15:59:45 -0800 | [diff] [blame] | 1111 | test_expect_success 'submodule deinit should unset core.worktree' ' |
| 1112 | test_path_is_file .git/modules/example/config && |
| 1113 | test_must_fail git config -f .git/modules/example/config core.worktree |
| 1114 | ' |
| 1115 | |
John Keeping | 091a6eb | 2013-06-16 15:18:18 +0100 | [diff] [blame] | 1116 | test_expect_success 'submodule deinit from subdirectory' ' |
| 1117 | git submodule update --init && |
| 1118 | git config submodule.example.foo bar && |
| 1119 | mkdir -p sub && |
| 1120 | ( |
| 1121 | cd sub && |
| 1122 | git submodule deinit ../init >../output |
| 1123 | ) && |
Vasco Almeida | 1edbaac | 2016-06-17 20:21:07 +0000 | [diff] [blame] | 1124 | test_i18ngrep "\\.\\./init" output && |
John Keeping | 091a6eb | 2013-06-16 15:18:18 +0100 | [diff] [blame] | 1125 | test -z "$(git config --get-regexp "submodule\.example\.")" && |
| 1126 | test -n "$(git config --get-regexp "submodule\.example2\.")" && |
| 1127 | test -f example2/.git && |
| 1128 | rmdir init |
| 1129 | ' |
| 1130 | |
Jens Lehmann | cf41982 | 2013-03-04 22:20:24 +0100 | [diff] [blame] | 1131 | test_expect_success 'submodule deinit . deinits all initialized submodules' ' |
| 1132 | git submodule update --init && |
| 1133 | git config submodule.example.foo bar && |
| 1134 | git config submodule.example2.frotz nitfol && |
| 1135 | test_must_fail git submodule deinit && |
Jens Lehmann | 7b294bf | 2013-04-01 21:02:00 +0200 | [diff] [blame] | 1136 | git submodule deinit . >actual && |
Jens Lehmann | cf41982 | 2013-03-04 22:20:24 +0100 | [diff] [blame] | 1137 | test -z "$(git config --get-regexp "submodule\.example\.")" && |
| 1138 | test -z "$(git config --get-regexp "submodule\.example2\.")" && |
Jens Lehmann | 7b294bf | 2013-04-01 21:02:00 +0200 | [diff] [blame] | 1139 | test_i18ngrep "Cleared directory .init" actual && |
| 1140 | test_i18ngrep "Cleared directory .example2" actual && |
Jens Lehmann | cf41982 | 2013-03-04 22:20:24 +0100 | [diff] [blame] | 1141 | rmdir init example2 |
| 1142 | ' |
| 1143 | |
Stefan Beller | f6a5279 | 2016-05-05 12:52:32 -0700 | [diff] [blame] | 1144 | test_expect_success 'submodule deinit --all deinits all initialized submodules' ' |
| 1145 | git submodule update --init && |
| 1146 | git config submodule.example.foo bar && |
| 1147 | git config submodule.example2.frotz nitfol && |
| 1148 | test_must_fail git submodule deinit && |
| 1149 | git submodule deinit --all >actual && |
| 1150 | test -z "$(git config --get-regexp "submodule\.example\.")" && |
| 1151 | test -z "$(git config --get-regexp "submodule\.example2\.")" && |
| 1152 | test_i18ngrep "Cleared directory .init" actual && |
| 1153 | test_i18ngrep "Cleared directory .example2" actual && |
| 1154 | rmdir init example2 |
| 1155 | ' |
| 1156 | |
Jens Lehmann | cf41982 | 2013-03-04 22:20:24 +0100 | [diff] [blame] | 1157 | test_expect_success 'submodule deinit deinits a submodule when its work tree is missing or empty' ' |
| 1158 | git submodule update --init && |
| 1159 | rm -rf init example2/* example2/.git && |
Jens Lehmann | 7b294bf | 2013-04-01 21:02:00 +0200 | [diff] [blame] | 1160 | git submodule deinit init example2 >actual && |
Jens Lehmann | cf41982 | 2013-03-04 22:20:24 +0100 | [diff] [blame] | 1161 | test -z "$(git config --get-regexp "submodule\.example\.")" && |
| 1162 | test -z "$(git config --get-regexp "submodule\.example2\.")" && |
Jens Lehmann | 7b294bf | 2013-04-01 21:02:00 +0200 | [diff] [blame] | 1163 | test_i18ngrep ! "Cleared directory .init" actual && |
| 1164 | test_i18ngrep "Cleared directory .example2" actual && |
Jens Lehmann | cf41982 | 2013-03-04 22:20:24 +0100 | [diff] [blame] | 1165 | rmdir init |
| 1166 | ' |
| 1167 | |
| 1168 | test_expect_success 'submodule deinit fails when the submodule contains modifications unless forced' ' |
| 1169 | git submodule update --init && |
| 1170 | echo X >>init/s && |
| 1171 | test_must_fail git submodule deinit init && |
| 1172 | test -n "$(git config --get-regexp "submodule\.example\.")" && |
| 1173 | test -f example2/.git && |
Jens Lehmann | 7b294bf | 2013-04-01 21:02:00 +0200 | [diff] [blame] | 1174 | git submodule deinit -f init >actual && |
Jens Lehmann | cf41982 | 2013-03-04 22:20:24 +0100 | [diff] [blame] | 1175 | test -z "$(git config --get-regexp "submodule\.example\.")" && |
Jens Lehmann | 7b294bf | 2013-04-01 21:02:00 +0200 | [diff] [blame] | 1176 | test_i18ngrep "Cleared directory .init" actual && |
Jens Lehmann | cf41982 | 2013-03-04 22:20:24 +0100 | [diff] [blame] | 1177 | rmdir init |
| 1178 | ' |
| 1179 | |
| 1180 | test_expect_success 'submodule deinit fails when the submodule contains untracked files unless forced' ' |
| 1181 | git submodule update --init && |
| 1182 | echo X >>init/untracked && |
| 1183 | test_must_fail git submodule deinit init && |
| 1184 | test -n "$(git config --get-regexp "submodule\.example\.")" && |
| 1185 | test -f example2/.git && |
Jens Lehmann | 7b294bf | 2013-04-01 21:02:00 +0200 | [diff] [blame] | 1186 | git submodule deinit -f init >actual && |
Jens Lehmann | cf41982 | 2013-03-04 22:20:24 +0100 | [diff] [blame] | 1187 | test -z "$(git config --get-regexp "submodule\.example\.")" && |
Jens Lehmann | 7b294bf | 2013-04-01 21:02:00 +0200 | [diff] [blame] | 1188 | test_i18ngrep "Cleared directory .init" actual && |
Jens Lehmann | cf41982 | 2013-03-04 22:20:24 +0100 | [diff] [blame] | 1189 | rmdir init |
| 1190 | ' |
| 1191 | |
| 1192 | test_expect_success 'submodule deinit fails when the submodule HEAD does not match unless forced' ' |
| 1193 | git submodule update --init && |
| 1194 | ( |
| 1195 | cd init && |
| 1196 | git checkout HEAD^ |
| 1197 | ) && |
| 1198 | test_must_fail git submodule deinit init && |
| 1199 | test -n "$(git config --get-regexp "submodule\.example\.")" && |
| 1200 | test -f example2/.git && |
Jens Lehmann | 7b294bf | 2013-04-01 21:02:00 +0200 | [diff] [blame] | 1201 | git submodule deinit -f init >actual && |
Jens Lehmann | cf41982 | 2013-03-04 22:20:24 +0100 | [diff] [blame] | 1202 | test -z "$(git config --get-regexp "submodule\.example\.")" && |
Jens Lehmann | 7b294bf | 2013-04-01 21:02:00 +0200 | [diff] [blame] | 1203 | test_i18ngrep "Cleared directory .init" actual && |
Jens Lehmann | cf41982 | 2013-03-04 22:20:24 +0100 | [diff] [blame] | 1204 | rmdir init |
| 1205 | ' |
| 1206 | |
| 1207 | test_expect_success 'submodule deinit is silent when used on an uninitialized submodule' ' |
| 1208 | git submodule update --init && |
| 1209 | git submodule deinit init >actual && |
| 1210 | test_i18ngrep "Submodule .example. (.*) unregistered for path .init" actual && |
Jens Lehmann | 7b294bf | 2013-04-01 21:02:00 +0200 | [diff] [blame] | 1211 | test_i18ngrep "Cleared directory .init" actual && |
Jens Lehmann | cf41982 | 2013-03-04 22:20:24 +0100 | [diff] [blame] | 1212 | git submodule deinit init >actual && |
| 1213 | test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual && |
Jens Lehmann | 7b294bf | 2013-04-01 21:02:00 +0200 | [diff] [blame] | 1214 | test_i18ngrep "Cleared directory .init" actual && |
Jens Lehmann | cf41982 | 2013-03-04 22:20:24 +0100 | [diff] [blame] | 1215 | git submodule deinit . >actual && |
| 1216 | test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual && |
| 1217 | test_i18ngrep "Submodule .example2. (.*) unregistered for path .example2" actual && |
Jens Lehmann | 7b294bf | 2013-04-01 21:02:00 +0200 | [diff] [blame] | 1218 | test_i18ngrep "Cleared directory .init" actual && |
Jens Lehmann | cf41982 | 2013-03-04 22:20:24 +0100 | [diff] [blame] | 1219 | git submodule deinit . >actual && |
| 1220 | test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual && |
| 1221 | test_i18ngrep ! "Submodule .example2. (.*) unregistered for path .example2" actual && |
Jens Lehmann | 7b294bf | 2013-04-01 21:02:00 +0200 | [diff] [blame] | 1222 | test_i18ngrep "Cleared directory .init" actual && |
Stefan Beller | f6a5279 | 2016-05-05 12:52:32 -0700 | [diff] [blame] | 1223 | git submodule deinit --all >actual && |
| 1224 | test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual && |
| 1225 | test_i18ngrep ! "Submodule .example2. (.*) unregistered for path .example2" actual && |
| 1226 | test_i18ngrep "Cleared directory .init" actual && |
Jens Lehmann | cf41982 | 2013-03-04 22:20:24 +0100 | [diff] [blame] | 1227 | rmdir init example2 |
| 1228 | ' |
| 1229 | |
Mugdha Pattnaik | 0adc8ba | 2021-11-19 10:56:27 +0000 | [diff] [blame] | 1230 | test_expect_success 'submodule deinit absorbs .git directory if .git is a directory' ' |
Jens Lehmann | cf41982 | 2013-03-04 22:20:24 +0100 | [diff] [blame] | 1231 | git submodule update --init && |
| 1232 | ( |
| 1233 | cd init && |
| 1234 | rm .git && |
Mugdha Pattnaik | 0adc8ba | 2021-11-19 10:56:27 +0000 | [diff] [blame] | 1235 | mv ../.git/modules/example .git && |
Jens Lehmann | cf41982 | 2013-03-04 22:20:24 +0100 | [diff] [blame] | 1236 | GIT_WORK_TREE=. git config --unset core.worktree |
| 1237 | ) && |
Mugdha Pattnaik | 0adc8ba | 2021-11-19 10:56:27 +0000 | [diff] [blame] | 1238 | git submodule deinit init && |
| 1239 | test_path_is_missing init/.git && |
| 1240 | test -z "$(git config --get-regexp "submodule\.example\.")" |
Jens Lehmann | cf41982 | 2013-03-04 22:20:24 +0100 | [diff] [blame] | 1241 | ' |
| 1242 | |
Torsten Bögershausen | bed9470 | 2013-06-20 16:58:48 +0200 | [diff] [blame] | 1243 | test_expect_success 'submodule with UTF-8 name' ' |
| 1244 | svname=$(printf "\303\245 \303\244\303\266") && |
| 1245 | mkdir "$svname" && |
Fredrik Gustafsson | 7467124 | 2013-06-14 02:26:02 +0200 | [diff] [blame] | 1246 | ( |
Torsten Bögershausen | bed9470 | 2013-06-20 16:58:48 +0200 | [diff] [blame] | 1247 | cd "$svname" && |
Fredrik Gustafsson | 7467124 | 2013-06-14 02:26:02 +0200 | [diff] [blame] | 1248 | git init && |
Torsten Bögershausen | bed9470 | 2013-06-20 16:58:48 +0200 | [diff] [blame] | 1249 | >sub && |
| 1250 | git add sub && |
Fredrik Gustafsson | 7467124 | 2013-06-14 02:26:02 +0200 | [diff] [blame] | 1251 | git commit -m "init sub" |
Torsten Bögershausen | bed9470 | 2013-06-20 16:58:48 +0200 | [diff] [blame] | 1252 | ) && |
Torsten Bögershausen | bed9470 | 2013-06-20 16:58:48 +0200 | [diff] [blame] | 1253 | git submodule add ./"$svname" && |
| 1254 | git submodule >&2 && |
| 1255 | test -n "$(git submodule | grep "$svname")" |
Fredrik Gustafsson | 7467124 | 2013-06-14 02:26:02 +0200 | [diff] [blame] | 1256 | ' |
Junio C Hamano | 2bb7afa | 2013-07-15 10:28:48 -0700 | [diff] [blame] | 1257 | |
Fredrik Gustafsson | 275cd18 | 2013-07-02 23:42:56 +0200 | [diff] [blame] | 1258 | test_expect_success 'submodule add clone shallow submodule' ' |
| 1259 | mkdir super && |
Jeff King | 99094a7 | 2015-03-20 06:07:15 -0400 | [diff] [blame] | 1260 | pwd=$(pwd) && |
Fredrik Gustafsson | 275cd18 | 2013-07-02 23:42:56 +0200 | [diff] [blame] | 1261 | ( |
| 1262 | cd super && |
| 1263 | git init && |
| 1264 | git submodule add --depth=1 file://"$pwd"/example2 submodule && |
| 1265 | ( |
| 1266 | cd submodule && |
| 1267 | test 1 = $(git log --oneline | wc -l) |
| 1268 | ) |
| 1269 | ) |
| 1270 | ' |
| 1271 | |
Brandon Williams | 3e7eaed | 2017-03-17 15:38:02 -0700 | [diff] [blame] | 1272 | test_expect_success 'setup superproject with submodules' ' |
| 1273 | git init sub1 && |
| 1274 | test_commit -C sub1 test && |
| 1275 | test_commit -C sub1 test2 && |
| 1276 | git init multisuper && |
| 1277 | git -C multisuper submodule add ../sub1 sub0 && |
| 1278 | git -C multisuper submodule add ../sub1 sub1 && |
| 1279 | git -C multisuper submodule add ../sub1 sub2 && |
| 1280 | git -C multisuper submodule add ../sub1 sub3 && |
| 1281 | git -C multisuper commit -m "add some submodules" |
| 1282 | ' |
| 1283 | |
| 1284 | cat >expect <<-EOF |
| 1285 | -sub0 |
| 1286 | sub1 (test2) |
| 1287 | sub2 (test2) |
| 1288 | sub3 (test2) |
| 1289 | EOF |
| 1290 | |
| 1291 | test_expect_success 'submodule update --init with a specification' ' |
| 1292 | test_when_finished "rm -rf multisuper_clone" && |
| 1293 | pwd=$(pwd) && |
| 1294 | git clone file://"$pwd"/multisuper multisuper_clone && |
| 1295 | git -C multisuper_clone submodule update --init . ":(exclude)sub0" && |
brian m. carlson | c0b65ea | 2020-07-29 23:14:03 +0000 | [diff] [blame] | 1296 | git -C multisuper_clone submodule status | sed "s/$OID_REGEX //" >actual && |
Brandon Williams | 3e7eaed | 2017-03-17 15:38:02 -0700 | [diff] [blame] | 1297 | test_cmp expect actual |
| 1298 | ' |
| 1299 | |
| 1300 | test_expect_success 'submodule update --init with submodule.active set' ' |
| 1301 | test_when_finished "rm -rf multisuper_clone" && |
| 1302 | pwd=$(pwd) && |
| 1303 | git clone file://"$pwd"/multisuper multisuper_clone && |
| 1304 | git -C multisuper_clone config submodule.active "." && |
| 1305 | git -C multisuper_clone config --add submodule.active ":(exclude)sub0" && |
| 1306 | git -C multisuper_clone submodule update --init && |
brian m. carlson | c0b65ea | 2020-07-29 23:14:03 +0000 | [diff] [blame] | 1307 | git -C multisuper_clone submodule status | sed "s/$OID_REGEX //" >actual && |
Brandon Williams | 3e7eaed | 2017-03-17 15:38:02 -0700 | [diff] [blame] | 1308 | test_cmp expect actual |
| 1309 | ' |
| 1310 | |
| 1311 | test_expect_success 'submodule update and setting submodule.<name>.active' ' |
| 1312 | test_when_finished "rm -rf multisuper_clone" && |
| 1313 | pwd=$(pwd) && |
| 1314 | git clone file://"$pwd"/multisuper multisuper_clone && |
| 1315 | git -C multisuper_clone config --bool submodule.sub0.active "true" && |
| 1316 | git -C multisuper_clone config --bool submodule.sub1.active "false" && |
| 1317 | git -C multisuper_clone config --bool submodule.sub2.active "true" && |
| 1318 | |
| 1319 | cat >expect <<-\EOF && |
| 1320 | sub0 (test2) |
| 1321 | -sub1 |
| 1322 | sub2 (test2) |
| 1323 | -sub3 |
| 1324 | EOF |
| 1325 | git -C multisuper_clone submodule update && |
brian m. carlson | c0b65ea | 2020-07-29 23:14:03 +0000 | [diff] [blame] | 1326 | git -C multisuper_clone submodule status | sed "s/$OID_REGEX //" >actual && |
Brandon Williams | 3e7eaed | 2017-03-17 15:38:02 -0700 | [diff] [blame] | 1327 | test_cmp expect actual |
| 1328 | ' |
Fredrik Gustafsson | 275cd18 | 2013-07-02 23:42:56 +0200 | [diff] [blame] | 1329 | |
Stefan Beller | e0a862f | 2018-10-16 10:27:03 -0700 | [diff] [blame] | 1330 | test_expect_success 'clone active submodule without submodule url set' ' |
| 1331 | test_when_finished "rm -rf test/test" && |
| 1332 | mkdir test && |
| 1333 | # another dir breaks accidental relative paths still being correct |
| 1334 | git clone file://"$pwd"/multisuper test/test && |
| 1335 | ( |
| 1336 | cd test/test && |
| 1337 | git config submodule.active "." && |
| 1338 | |
| 1339 | # do not pass --init flag, as the submodule is already active: |
| 1340 | git submodule update && |
| 1341 | git submodule status >actual_raw && |
| 1342 | |
brian m. carlson | c0b65ea | 2020-07-29 23:14:03 +0000 | [diff] [blame] | 1343 | cut -d" " -f3- actual_raw >actual && |
Stefan Beller | e0a862f | 2018-10-16 10:27:03 -0700 | [diff] [blame] | 1344 | cat >expect <<-\EOF && |
brian m. carlson | c0b65ea | 2020-07-29 23:14:03 +0000 | [diff] [blame] | 1345 | sub0 (test2) |
| 1346 | sub1 (test2) |
| 1347 | sub2 (test2) |
| 1348 | sub3 (test2) |
Stefan Beller | e0a862f | 2018-10-16 10:27:03 -0700 | [diff] [blame] | 1349 | EOF |
| 1350 | test_cmp expect actual |
| 1351 | ) |
| 1352 | ' |
| 1353 | |
Brandon Williams | bb62e0a | 2017-03-17 15:38:03 -0700 | [diff] [blame] | 1354 | test_expect_success 'clone --recurse-submodules with a pathspec works' ' |
| 1355 | test_when_finished "rm -rf multisuper_clone" && |
| 1356 | cat >expected <<-\EOF && |
| 1357 | sub0 (test2) |
| 1358 | -sub1 |
| 1359 | -sub2 |
| 1360 | -sub3 |
| 1361 | EOF |
| 1362 | |
| 1363 | git clone --recurse-submodules="sub0" multisuper multisuper_clone && |
brian m. carlson | c0b65ea | 2020-07-29 23:14:03 +0000 | [diff] [blame] | 1364 | git -C multisuper_clone submodule status | sed "s/$OID_REGEX //" >actual && |
Stefan Beller | 9c5b2fa | 2017-10-06 12:00:06 -0700 | [diff] [blame] | 1365 | test_cmp expected actual |
Brandon Williams | bb62e0a | 2017-03-17 15:38:03 -0700 | [diff] [blame] | 1366 | ' |
| 1367 | |
| 1368 | test_expect_success 'clone with multiple --recurse-submodules options' ' |
| 1369 | test_when_finished "rm -rf multisuper_clone" && |
| 1370 | cat >expect <<-\EOF && |
| 1371 | -sub0 |
| 1372 | sub1 (test2) |
| 1373 | -sub2 |
| 1374 | sub3 (test2) |
| 1375 | EOF |
| 1376 | |
| 1377 | git clone --recurse-submodules="." \ |
| 1378 | --recurse-submodules=":(exclude)sub0" \ |
| 1379 | --recurse-submodules=":(exclude)sub2" \ |
| 1380 | multisuper multisuper_clone && |
brian m. carlson | c0b65ea | 2020-07-29 23:14:03 +0000 | [diff] [blame] | 1381 | git -C multisuper_clone submodule status | sed "s/$OID_REGEX //" >actual && |
Brandon Williams | bb62e0a | 2017-03-17 15:38:03 -0700 | [diff] [blame] | 1382 | test_cmp expect actual |
| 1383 | ' |
| 1384 | |
| 1385 | test_expect_success 'clone and subsequent updates correctly auto-initialize submodules' ' |
| 1386 | test_when_finished "rm -rf multisuper_clone" && |
| 1387 | cat <<-\EOF >expect && |
| 1388 | -sub0 |
| 1389 | sub1 (test2) |
| 1390 | -sub2 |
| 1391 | sub3 (test2) |
| 1392 | EOF |
| 1393 | |
| 1394 | cat <<-\EOF >expect2 && |
| 1395 | -sub0 |
| 1396 | sub1 (test2) |
| 1397 | -sub2 |
| 1398 | sub3 (test2) |
| 1399 | -sub4 |
| 1400 | sub5 (test2) |
| 1401 | EOF |
| 1402 | |
| 1403 | git clone --recurse-submodules="." \ |
| 1404 | --recurse-submodules=":(exclude)sub0" \ |
| 1405 | --recurse-submodules=":(exclude)sub2" \ |
| 1406 | --recurse-submodules=":(exclude)sub4" \ |
| 1407 | multisuper multisuper_clone && |
| 1408 | |
brian m. carlson | c0b65ea | 2020-07-29 23:14:03 +0000 | [diff] [blame] | 1409 | git -C multisuper_clone submodule status | sed "s/$OID_REGEX //" >actual && |
Brandon Williams | bb62e0a | 2017-03-17 15:38:03 -0700 | [diff] [blame] | 1410 | test_cmp expect actual && |
| 1411 | |
| 1412 | git -C multisuper submodule add ../sub1 sub4 && |
| 1413 | git -C multisuper submodule add ../sub1 sub5 && |
| 1414 | git -C multisuper commit -m "add more submodules" && |
| 1415 | # obtain the new superproject |
| 1416 | git -C multisuper_clone pull && |
| 1417 | git -C multisuper_clone submodule update --init && |
brian m. carlson | c0b65ea | 2020-07-29 23:14:03 +0000 | [diff] [blame] | 1418 | git -C multisuper_clone submodule status | sed "s/$OID_REGEX //" >actual && |
Brandon Williams | bb62e0a | 2017-03-17 15:38:03 -0700 | [diff] [blame] | 1419 | test_cmp expect2 actual |
| 1420 | ' |
| 1421 | |
Brandon Williams | 1f8d711 | 2017-03-17 15:38:04 -0700 | [diff] [blame] | 1422 | test_expect_success 'init properly sets the config' ' |
| 1423 | test_when_finished "rm -rf multisuper_clone" && |
| 1424 | git clone --recurse-submodules="." \ |
| 1425 | --recurse-submodules=":(exclude)sub0" \ |
| 1426 | multisuper multisuper_clone && |
| 1427 | |
| 1428 | git -C multisuper_clone submodule init -- sub0 sub1 && |
| 1429 | git -C multisuper_clone config --get submodule.sub0.active && |
| 1430 | test_must_fail git -C multisuper_clone config --get submodule.sub1.active |
| 1431 | ' |
| 1432 | |
Brandon Williams | 03c004c | 2017-08-03 15:25:44 -0700 | [diff] [blame] | 1433 | test_expect_success 'recursive clone respects -q' ' |
| 1434 | test_when_finished "rm -rf multisuper_clone" && |
| 1435 | git clone -q --recurse-submodules multisuper multisuper_clone >actual && |
| 1436 | test_must_be_empty actual |
| 1437 | ' |
| 1438 | |
Lars Hjemli | 88961ef | 2007-06-02 03:27:42 +0200 | [diff] [blame] | 1439 | test_done |