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