Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/git/blob/master/t/t7411-submodule-config.sh # git [Ported from github.com/git/git] Sync with Git 2.56.1 Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `git / t / t7411-submodule-config.sh` 261 lines ยท 7410 bytes Raw Blame History 1 #!/bin/sh 2 # 3 # Copyright (c) 2014 Heiko Voigt 4 # 5 6 test_description='Test submodules config cache infrastructure 7 8 This test verifies that parsing .gitmodules configurations directly 9 from the database and from the worktree works. 10 ' 11 12 TEST_NO_CREATE_REPO=1 13 . ./test-lib.sh 14 15 test_expect_success 'setup' ' 16 git config --global protocol.file.allow always 17 ' 18 test_expect_success 'submodule config cache setup' ' 19 mkdir submodule && 20 (cd submodule && 21 git init && 22 echo a >a && 23 git add . && 24 git commit -ma 25 ) && 26 mkdir super && 27 (cd super && 28 git init && 29 git submodule add ../submodule && 30 git submodule add ../submodule a && 31 git commit -m "add as submodule and as a" && 32 git mv a b && 33 git commit -m "move a to b" 34 ) 35 ' 36 37 test_expect_success 'configuration parsing with error' ' 38 test_when_finished "rm -rf repo" && 39 test_create_repo repo && 40 cat >repo/.gitmodules <<-\EOF && 41 [submodule "s"] 42 path 43 ignore 44 EOF 45 ( 46 cd repo && 47 test_must_fail test-tool submodule-config "" s 2>actual && 48 test_grep "bad config" actual 49 ) 50 ' 51 52 cat >super/expect <actual && 67 test_cmp expect actual 68 ) 69 ' 70 71 test_expect_success 'test parsing and lookup of submodule config by name' ' 72 (cd super && 73 test-tool submodule-config --name \ 74 HEAD^ a \ 75 HEAD a \ 76 HEAD^ submodule \ 77 HEAD submodule \ 78 >actual && 79 test_cmp expect actual 80 ) 81 ' 82 83 cat >super/expect_error <>.gitmodules && 94 git add .gitmodules && 95 mv .gitmodules.bak .gitmodules && 96 git commit -m "add error" && 97 sha1=$(git rev-parse HEAD) && 98 test-tool submodule-config \ 99 HEAD b \ 100 HEAD submodule \ 101 >actual \ 102 2>actual_stderr && 103 test_cmp expect_error actual && 104 test_grep "submodule-blob $sha1:.gitmodules" actual_stderr >/dev/null 105 ) 106 ' 107 108 test_expect_success 'using different treeishs works' ' 109 ( 110 cd super && 111 git tag new_tag && 112 tree=$(git rev-parse HEAD^{tree}) && 113 commit=$(git rev-parse HEAD^{commit}) && 114 test-tool submodule-config $commit b >expect && 115 test-tool submodule-config $tree b >actual.1 && 116 test-tool submodule-config new_tag b >actual.2 && 117 test_cmp expect actual.1 && 118 test_cmp expect actual.2 119 ) 120 ' 121 122 test_expect_success 'error in history in fetchrecursesubmodule lets continue' ' 123 ORIG=$(git -C super rev-parse HEAD) && 124 test_when_finished "git -C super reset --hard $ORIG" && 125 (cd super && 126 git config -f .gitmodules \ 127 submodule.submodule.fetchrecursesubmodules blabla && 128 git add .gitmodules && 129 git config --unset -f .gitmodules \ 130 submodule.submodule.fetchrecursesubmodules && 131 git commit -m "add error in fetchrecursesubmodules" && 132 test-tool submodule-config \ 133 HEAD b \ 134 HEAD submodule \ 135 >actual && 136 test_cmp expect_error actual 137 ) 138 ' 139 140 test_expect_success 'reading submodules config from the working tree' ' 141 (cd super && 142 echo "../submodule" >expect && 143 test-tool submodule config-list submodule.submodule.url >actual && 144 test_cmp expect actual 145 ) 146 ' 147 148 test_expect_success 'unsetting submodules config from the working tree' ' 149 (cd super && 150 test-tool submodule config-unset submodule.submodule.url && 151 test-tool submodule config-list submodule.submodule.url >actual && 152 test_must_be_empty actual 153 ) 154 ' 155 156 157 test_expect_success 'writing submodules config' ' 158 (cd super && 159 echo "new_url" >expect && 160 test-tool submodule config-set submodule.submodule.url "new_url" && 161 test-tool submodule config-list submodule.submodule.url >actual && 162 test_cmp expect actual 163 ) 164 ' 165 166 test_expect_success 'overwriting unstaged submodules config' ' 167 test_when_finished "git -C super checkout .gitmodules" && 168 (cd super && 169 echo "newer_url" >expect && 170 test-tool submodule config-set submodule.submodule.url "newer_url" && 171 test-tool submodule config-list submodule.submodule.url >actual && 172 test_cmp expect actual 173 ) 174 ' 175 176 test_expect_success 'writeable .gitmodules when it is in the working tree' ' 177 test-tool -C super submodule config-writeable 178 ' 179 180 test_expect_success 'writeable .gitmodules when it is nowhere in the repository' ' 181 ORIG=$(git -C super rev-parse HEAD) && 182 test_when_finished "git -C super reset --hard $ORIG" && 183 (cd super && 184 git rm .gitmodules && 185 git commit -m "remove .gitmodules from the current branch" && 186 test-tool submodule config-writeable 187 ) 188 ' 189 190 test_expect_success 'non-writeable .gitmodules when it is in the index but not in the working tree' ' 191 test_when_finished "git -C super checkout .gitmodules" && 192 (cd super && 193 rm -f .gitmodules && 194 test_must_fail test-tool submodule config-writeable 195 ) 196 ' 197 198 test_expect_success 'non-writeable .gitmodules when it is in the current branch but not in the index' ' 199 ORIG=$(git -C super rev-parse HEAD) && 200 test_when_finished "git -C super reset --hard $ORIG" && 201 (cd super && 202 git rm .gitmodules && 203 test_must_fail test-tool submodule config-writeable 204 ) 205 ' 206 207 test_expect_success 'reading submodules config from the index when .gitmodules is not in the working tree' ' 208 ORIG=$(git -C super rev-parse HEAD) && 209 test_when_finished "git -C super reset --hard $ORIG" && 210 (cd super && 211 test-tool submodule config-set submodule.submodule.url "staged_url" && 212 git add .gitmodules && 213 rm -f .gitmodules && 214 echo "staged_url" >expect && 215 test-tool submodule config-list submodule.submodule.url >actual && 216 test_cmp expect actual 217 ) 218 ' 219 220 test_expect_success 'reading submodules config from the current branch when .gitmodules is not in the index' ' 221 ORIG=$(git -C super rev-parse HEAD) && 222 test_when_finished "git -C super reset --hard $ORIG" && 223 (cd super && 224 git rm .gitmodules && 225 echo "../submodule" >expect && 226 test-tool submodule config-list submodule.submodule.url >actual && 227 test_cmp expect actual 228 ) 229 ' 230 231 test_expect_success 'reading nested submodules config' ' 232 (cd super && 233 git init submodule/nested_submodule && 234 echo "a" >submodule/nested_submodule/a && 235 git -C submodule/nested_submodule add a && 236 git -C submodule/nested_submodule commit -m "add a" && 237 git -C submodule submodule add ./nested_submodule && 238 git -C submodule add nested_submodule && 239 git -C submodule commit -m "added nested_submodule" && 240 git add submodule && 241 git commit -m "updated submodule" && 242 echo "./nested_submodule" >expect && 243 test-tool submodule-nested-repo-config \ 244 submodule submodule.nested_submodule.url >actual && 245 test_cmp expect actual 246 ) 247 ' 248 249 test_expect_success 'reading nested submodules config when .gitmodules is not in the working tree' ' 250 test_when_finished "git -C super/submodule checkout .gitmodules" && 251 (cd super && 252 echo "./nested_submodule" >expect && 253 rm submodule/.gitmodules && 254 test-tool submodule-nested-repo-config \ 255 submodule submodule.nested_submodule.url >actual 2>warning && 256 test_must_be_empty warning && 257 test_cmp expect actual 258 ) 259 ' 260 261 test_done