git
[Ported from github.com/git/git] Sync with Git 2.56.1
Brought by drakestapleton
git / t / t7814-grep-recurse-submodules.sh
| 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='Test grep recurse-submodules feature |
| 4 | |
| 5 | This test verifies the recurse-submodules feature correctly greps across |
| 6 | submodules. |
| 7 | ' |
| 8 | |
| 9 | TEST_CREATE_REPO_NO_TEMPLATE=1 |
| 10 | . ./test-lib.sh |
| 11 | |
| 12 | test_expect_success 'setup directory structure and submodule' ' |
| 13 | echo "(1|2)d(3|4)" >a && |
| 14 | mkdir b && |
| 15 | echo "(3|4)" >b/b && |
| 16 | git add a b && |
| 17 | git commit -m "add a and b" && |
| 18 | test_tick && |
| 19 | git init submodule && |
| 20 | echo "(1|2)d(3|4)" >submodule/a && |
| 21 | git -C submodule add a && |
| 22 | git -C submodule commit -m "add a" && |
| 23 | git submodule add ./submodule && |
| 24 | git commit -m "added submodule" && |
| 25 | test_tick |
| 26 | ' |
| 27 | |
| 28 | test_expect_success 'grep correctly finds patterns in a submodule' ' |
| 29 | cat >expect <<-\EOF && |
| 30 | a:(1|2)d(3|4) |
| 31 | b/b:(3|4) |
| 32 | submodule/a:(1|2)d(3|4) |
| 33 | EOF |
| 34 | |
| 35 | git grep -e "(3|4)" --recurse-submodules >actual && |
| 36 | test_cmp expect actual |
| 37 | ' |
| 38 | |
| 39 | test_expect_success 'grep finds patterns in a submodule via config' ' |
| 40 | test_config submodule.recurse true && |
| 41 | # expect from previous test |
| 42 | git grep -e "(3|4)" >actual && |
| 43 | test_cmp expect actual |
| 44 | ' |
| 45 | |
| 46 | test_expect_success 'grep --no-recurse-submodules overrides config' ' |
| 47 | test_config submodule.recurse true && |
| 48 | cat >expect <<-\EOF && |
| 49 | a:(1|2)d(3|4) |
| 50 | b/b:(3|4) |
| 51 | EOF |
| 52 | |
| 53 | git grep -e "(3|4)" --no-recurse-submodules >actual && |
| 54 | test_cmp expect actual |
| 55 | ' |
| 56 | |
| 57 | test_expect_success 'grep and basic pathspecs' ' |
| 58 | cat >expect <<-\EOF && |
| 59 | submodule/a:(1|2)d(3|4) |
| 60 | EOF |
| 61 | |
| 62 | git grep -e. --recurse-submodules -- submodule >actual && |
| 63 | test_cmp expect actual |
| 64 | ' |
| 65 | |
| 66 | test_expect_success 'grep and nested submodules' ' |
| 67 | git init submodule/sub && |
| 68 | echo "(1|2)d(3|4)" >submodule/sub/a && |
| 69 | git -C submodule/sub add a && |
| 70 | git -C submodule/sub commit -m "add a" && |
| 71 | test_tick && |
| 72 | git -C submodule submodule add ./sub && |
| 73 | git -C submodule add sub && |
| 74 | git -C submodule commit -m "added sub" && |
| 75 | test_tick && |
| 76 | git add submodule && |
| 77 | git commit -m "updated submodule" && |
| 78 | test_tick && |
| 79 | |
| 80 | cat >expect <<-\EOF && |
| 81 | a:(1|2)d(3|4) |
| 82 | b/b:(3|4) |
| 83 | submodule/a:(1|2)d(3|4) |
| 84 | submodule/sub/a:(1|2)d(3|4) |
| 85 | EOF |
| 86 | |
| 87 | git grep -e "(3|4)" --recurse-submodules >actual && |
| 88 | test_cmp expect actual |
| 89 | ' |
| 90 | |
| 91 | test_expect_success 'grep and multiple patterns' ' |
| 92 | cat >expect <<-\EOF && |
| 93 | a:(1|2)d(3|4) |
| 94 | submodule/a:(1|2)d(3|4) |
| 95 | submodule/sub/a:(1|2)d(3|4) |
| 96 | EOF |
| 97 | |
| 98 | git grep -e "(3|4)" --and -e "(1|2)" --recurse-submodules >actual && |
| 99 | test_cmp expect actual |
| 100 | ' |
| 101 | |
| 102 | test_expect_success 'grep and multiple patterns' ' |
| 103 | cat >expect <<-\EOF && |
| 104 | b/b:(3|4) |
| 105 | EOF |
| 106 | |
| 107 | git grep -e "(3|4)" --and --not -e "(1|2)" --recurse-submodules >actual && |
| 108 | test_cmp expect actual |
| 109 | ' |
| 110 | |
| 111 | test_expect_success 'basic grep tree' ' |
| 112 | cat >expect <<-\EOF && |
| 113 | HEAD:a:(1|2)d(3|4) |
| 114 | HEAD:b/b:(3|4) |
| 115 | HEAD:submodule/a:(1|2)d(3|4) |
| 116 | HEAD:submodule/sub/a:(1|2)d(3|4) |
| 117 | EOF |
| 118 | |
| 119 | git grep -e "(3|4)" --recurse-submodules HEAD >actual && |
| 120 | test_cmp expect actual |
| 121 | ' |
| 122 | |
| 123 | test_expect_success 'grep tree HEAD^' ' |
| 124 | cat >expect <<-\EOF && |
| 125 | HEAD^:a:(1|2)d(3|4) |
| 126 | HEAD^:b/b:(3|4) |
| 127 | HEAD^:submodule/a:(1|2)d(3|4) |
| 128 | EOF |
| 129 | |
| 130 | git grep -e "(3|4)" --recurse-submodules HEAD^ >actual && |
| 131 | test_cmp expect actual |
| 132 | ' |
| 133 | |
| 134 | test_expect_success 'grep tree HEAD^^' ' |
| 135 | cat >expect <<-\EOF && |
| 136 | HEAD^^:a:(1|2)d(3|4) |
| 137 | HEAD^^:b/b:(3|4) |
| 138 | EOF |
| 139 | |
| 140 | git grep -e "(3|4)" --recurse-submodules HEAD^^ >actual && |
| 141 | test_cmp expect actual |
| 142 | ' |
| 143 | |
| 144 | test_expect_success 'grep tree and pathspecs' ' |
| 145 | cat >expect <<-\EOF && |
| 146 | HEAD:submodule/a:(1|2)d(3|4) |
| 147 | HEAD:submodule/sub/a:(1|2)d(3|4) |
| 148 | EOF |
| 149 | |
| 150 | git grep -e "(3|4)" --recurse-submodules HEAD -- submodule >actual && |
| 151 | test_cmp expect actual |
| 152 | ' |
| 153 | |
| 154 | test_expect_success 'grep tree and pathspecs' ' |
| 155 | cat >expect <<-\EOF && |
| 156 | HEAD:submodule/a:(1|2)d(3|4) |
| 157 | HEAD:submodule/sub/a:(1|2)d(3|4) |
| 158 | EOF |
| 159 | |
| 160 | git grep -e "(3|4)" --recurse-submodules HEAD -- "submodule*a" >actual && |
| 161 | test_cmp expect actual |
| 162 | ' |
| 163 | |
| 164 | test_expect_success 'grep tree and more pathspecs' ' |
| 165 | cat >expect <<-\EOF && |
| 166 | HEAD:submodule/a:(1|2)d(3|4) |
| 167 | EOF |
| 168 | |
| 169 | git grep -e "(3|4)" --recurse-submodules HEAD -- "submodul?/a" >actual && |
| 170 | test_cmp expect actual |
| 171 | ' |
| 172 | |
| 173 | test_expect_success 'grep tree and more pathspecs' ' |
| 174 | cat >expect <<-\EOF && |
| 175 | HEAD:submodule/sub/a:(1|2)d(3|4) |
| 176 | EOF |
| 177 | |
| 178 | git grep -e "(3|4)" --recurse-submodules HEAD -- "submodul*/sub/a" >actual && |
| 179 | test_cmp expect actual |
| 180 | ' |
| 181 | |
| 182 | test_expect_success !MINGW 'grep recurse submodule colon in name' ' |
| 183 | git init parent && |
| 184 | test_when_finished "rm -rf parent" && |
| 185 | echo "(1|2)d(3|4)" >"parent/fi:le" && |
| 186 | git -C parent add "fi:le" && |
| 187 | git -C parent commit -m "add fi:le" && |
| 188 | test_tick && |
| 189 | |
| 190 | git init "su:b" && |
| 191 | test_when_finished "rm -rf su:b" && |
| 192 | echo "(1|2)d(3|4)" >"su:b/fi:le" && |
| 193 | git -C "su:b" add "fi:le" && |
| 194 | git -C "su:b" commit -m "add fi:le" && |
| 195 | test_tick && |
| 196 | |
| 197 | test_config_global protocol.file.allow always && |
| 198 | git -C parent submodule add "../su:b" "su:b" && |
| 199 | git -C parent commit -m "add submodule" && |
| 200 | test_tick && |
| 201 | |
| 202 | cat >expect <<-\EOF && |
| 203 | fi:le:(1|2)d(3|4) |
| 204 | su:b/fi:le:(1|2)d(3|4) |
| 205 | EOF |
| 206 | git -C parent grep -e "(1|2)d(3|4)" --recurse-submodules >actual && |
| 207 | test_cmp expect actual && |
| 208 | |
| 209 | cat >expect <<-\EOF && |
| 210 | HEAD:fi:le:(1|2)d(3|4) |
| 211 | HEAD:su:b/fi:le:(1|2)d(3|4) |
| 212 | EOF |
| 213 | git -C parent grep -e "(1|2)d(3|4)" --recurse-submodules HEAD >actual && |
| 214 | test_cmp expect actual |
| 215 | ' |
| 216 | |
| 217 | test_expect_success 'grep history with moved submoules' ' |
| 218 | git init parent && |
| 219 | test_when_finished "rm -rf parent" && |
| 220 | echo "(1|2)d(3|4)" >parent/file && |
| 221 | git -C parent add file && |
| 222 | git -C parent commit -m "add file" && |
| 223 | test_tick && |
| 224 | |
| 225 | git init sub && |
| 226 | test_when_finished "rm -rf sub" && |
| 227 | echo "(1|2)d(3|4)" >sub/file && |
| 228 | git -C sub add file && |
| 229 | git -C sub commit -m "add file" && |
| 230 | test_tick && |
| 231 | |
| 232 | test_config_global protocol.file.allow always && |
| 233 | git -C parent submodule add ../sub dir/sub && |
| 234 | git -C parent commit -m "add submodule" && |
| 235 | test_tick && |
| 236 | |
| 237 | cat >expect <<-\EOF && |
| 238 | dir/sub/file:(1|2)d(3|4) |
| 239 | file:(1|2)d(3|4) |
| 240 | EOF |
| 241 | git -C parent grep -e "(1|2)d(3|4)" --recurse-submodules >actual && |
| 242 | test_cmp expect actual && |
| 243 | |
| 244 | git -C parent mv dir/sub sub-moved && |
| 245 | git -C parent commit -m "moved submodule" && |
| 246 | test_tick && |
| 247 | |
| 248 | cat >expect <<-\EOF && |
| 249 | file:(1|2)d(3|4) |
| 250 | sub-moved/file:(1|2)d(3|4) |
| 251 | EOF |
| 252 | git -C parent grep -e "(1|2)d(3|4)" --recurse-submodules >actual && |
| 253 | test_cmp expect actual && |
| 254 | |
| 255 | cat >expect <<-\EOF && |
| 256 | HEAD^:dir/sub/file:(1|2)d(3|4) |
| 257 | HEAD^:file:(1|2)d(3|4) |
| 258 | EOF |
| 259 | git -C parent grep -e "(1|2)d(3|4)" --recurse-submodules HEAD^ >actual && |
| 260 | test_cmp expect actual |
| 261 | ' |
| 262 | |
| 263 | test_expect_success 'grep using relative path' ' |
| 264 | test_when_finished "rm -rf parent sub" && |
| 265 | git init sub && |
| 266 | echo "(1|2)d(3|4)" >sub/file && |
| 267 | git -C sub add file && |
| 268 | git -C sub commit -m "add file" && |
| 269 | test_tick && |
| 270 | |
| 271 | git init parent && |
| 272 | echo "(1|2)d(3|4)" >parent/file && |
| 273 | git -C parent add file && |
| 274 | mkdir parent/src && |
| 275 | echo "(1|2)d(3|4)" >parent/src/file2 && |
| 276 | git -C parent add src/file2 && |
| 277 | test_config_global protocol.file.allow always && |
| 278 | git -C parent submodule add ../sub && |
| 279 | git -C parent commit -m "add files and submodule" && |
| 280 | test_tick && |
| 281 | |
| 282 | # From top works |
| 283 | cat >expect <<-\EOF && |
| 284 | file:(1|2)d(3|4) |
| 285 | src/file2:(1|2)d(3|4) |
| 286 | sub/file:(1|2)d(3|4) |
| 287 | EOF |
| 288 | git -C parent grep --recurse-submodules -e "(1|2)d(3|4)" >actual && |
| 289 | test_cmp expect actual && |
| 290 | |
| 291 | # Relative path to top |
| 292 | cat >expect <<-\EOF && |
| 293 | ../file:(1|2)d(3|4) |
| 294 | file2:(1|2)d(3|4) |
| 295 | ../sub/file:(1|2)d(3|4) |
| 296 | EOF |
| 297 | git -C parent/src grep --recurse-submodules -e "(1|2)d(3|4)" -- .. >actual && |
| 298 | test_cmp expect actual && |
| 299 | |
| 300 | # Relative path to submodule |
| 301 | cat >expect <<-\EOF && |
| 302 | ../sub/file:(1|2)d(3|4) |
| 303 | EOF |
| 304 | git -C parent/src grep --recurse-submodules -e "(1|2)d(3|4)" -- ../sub >actual && |
| 305 | test_cmp expect actual |
| 306 | ' |
| 307 | |
| 308 | test_expect_success 'grep from a subdir' ' |
| 309 | test_when_finished "rm -rf parent sub" && |
| 310 | git init sub && |
| 311 | echo "(1|2)d(3|4)" >sub/file && |
| 312 | git -C sub add file && |
| 313 | git -C sub commit -m "add file" && |
| 314 | test_tick && |
| 315 | |
| 316 | git init parent && |
| 317 | mkdir parent/src && |
| 318 | echo "(1|2)d(3|4)" >parent/src/file && |
| 319 | git -C parent add src/file && |
| 320 | test_config_global protocol.file.allow always && |
| 321 | git -C parent submodule add ../sub src/sub && |
| 322 | git -C parent submodule add ../sub sub && |
| 323 | git -C parent commit -m "add files and submodules" && |
| 324 | test_tick && |
| 325 | |
| 326 | # Verify grep from root works |
| 327 | cat >expect <<-\EOF && |
| 328 | src/file:(1|2)d(3|4) |
| 329 | src/sub/file:(1|2)d(3|4) |
| 330 | sub/file:(1|2)d(3|4) |
| 331 | EOF |
| 332 | git -C parent grep --recurse-submodules -e "(1|2)d(3|4)" >actual && |
| 333 | test_cmp expect actual && |
| 334 | |
| 335 | # Verify grep from a subdir works |
| 336 | cat >expect <<-\EOF && |
| 337 | file:(1|2)d(3|4) |
| 338 | sub/file:(1|2)d(3|4) |
| 339 | EOF |
| 340 | git -C parent/src grep --recurse-submodules -e "(1|2)d(3|4)" >actual && |
| 341 | test_cmp expect actual |
| 342 | ' |
| 343 | |
| 344 | test_incompatible_with_recurse_submodules () |
| 345 | { |
| 346 | test_expect_success "--recurse-submodules and $1 are incompatible" " |
| 347 | test_must_fail git grep -e. --recurse-submodules $1 2>actual && |
| 348 | test_grep 'not supported with --recurse-submodules' actual |
| 349 | " |
| 350 | } |
| 351 | |
| 352 | test_incompatible_with_recurse_submodules --untracked |
| 353 | |
| 354 | test_expect_success 'grep --recurse-submodules --no-index ignores --recurse-submodules' ' |
| 355 | git grep --recurse-submodules --no-index -e "^(.|.)[\d]" >actual && |
| 356 | cat >expect <<-\EOF && |
| 357 | a:(1|2)d(3|4) |
| 358 | submodule/a:(1|2)d(3|4) |
| 359 | submodule/sub/a:(1|2)d(3|4) |
| 360 | EOF |
| 361 | test_cmp expect actual |
| 362 | ' |
| 363 | |
| 364 | test_expect_success 'grep --recurse-submodules should pass the pattern type along' ' |
| 365 | # Fixed |
| 366 | test_must_fail git grep -F --recurse-submodules -e "(.|.)[\d]" && |
| 367 | test_must_fail git -c grep.patternType=fixed grep --recurse-submodules -e "(.|.)[\d]" && |
| 368 | |
| 369 | # Basic |
| 370 | git grep -G --recurse-submodules -e "(.|.)[\d]" >actual && |
| 371 | cat >expect <<-\EOF && |
| 372 | a:(1|2)d(3|4) |
| 373 | submodule/a:(1|2)d(3|4) |
| 374 | submodule/sub/a:(1|2)d(3|4) |
| 375 | EOF |
| 376 | test_cmp expect actual && |
| 377 | git -c grep.patternType=basic grep --recurse-submodules -e "(.|.)[\d]" >actual && |
| 378 | test_cmp expect actual && |
| 379 | |
| 380 | # Extended |
| 381 | git grep -E --recurse-submodules -e "(.|.)[\d]" >actual && |
| 382 | cat >expect <<-\EOF && |
| 383 | .gitmodules:[submodule "submodule"] |
| 384 | .gitmodules: path = submodule |
| 385 | .gitmodules: url = ./submodule |
| 386 | a:(1|2)d(3|4) |
| 387 | submodule/.gitmodules:[submodule "sub"] |
| 388 | submodule/a:(1|2)d(3|4) |
| 389 | submodule/sub/a:(1|2)d(3|4) |
| 390 | EOF |
| 391 | test_cmp expect actual && |
| 392 | git -c grep.patternType=extended grep --recurse-submodules -e "(.|.)[\d]" >actual && |
| 393 | test_cmp expect actual && |
| 394 | git -c grep.extendedRegexp=true grep --recurse-submodules -e "(.|.)[\d]" >actual && |
| 395 | test_cmp expect actual && |
| 396 | |
| 397 | # Perl |
| 398 | if test_have_prereq PCRE |
| 399 | then |
| 400 | git grep -P --recurse-submodules -e "(.|.)[\d]" >actual && |
| 401 | cat >expect <<-\EOF && |
| 402 | a:(1|2)d(3|4) |
| 403 | b/b:(3|4) |
| 404 | submodule/a:(1|2)d(3|4) |
| 405 | submodule/sub/a:(1|2)d(3|4) |
| 406 | EOF |
| 407 | test_cmp expect actual && |
| 408 | git -c grep.patternType=perl grep --recurse-submodules -e "(.|.)[\d]" >actual && |
| 409 | test_cmp expect actual |
| 410 | fi |
| 411 | ' |
| 412 | |
| 413 | test_expect_success 'grep --recurse-submodules with submodules without .gitmodules in the working tree' ' |
| 414 | test_when_finished "git -C submodule checkout .gitmodules" && |
| 415 | rm submodule/.gitmodules && |
| 416 | git grep --recurse-submodules -e "(.|.)[\d]" >actual && |
| 417 | cat >expect <<-\EOF && |
| 418 | a:(1|2)d(3|4) |
| 419 | submodule/a:(1|2)d(3|4) |
| 420 | submodule/sub/a:(1|2)d(3|4) |
| 421 | EOF |
| 422 | test_cmp expect actual |
| 423 | ' |
| 424 | |
| 425 | reset_and_clean () { |
| 426 | git reset --hard && |
| 427 | git clean -fd && |
| 428 | git submodule foreach --recursive 'git reset --hard' && |
| 429 | git submodule foreach --recursive 'git clean -fd' |
| 430 | } |
| 431 | |
| 432 | test_expect_success 'grep --recurse-submodules without --cached considers worktree modifications' ' |
| 433 | reset_and_clean && |
| 434 | echo "A modified line in submodule" >>submodule/a && |
| 435 | echo "submodule/a:A modified line in submodule" >expect && |
| 436 | git grep --recurse-submodules "A modified line in submodule" >actual && |
| 437 | test_cmp expect actual |
| 438 | ' |
| 439 | |
| 440 | test_expect_success 'grep --recurse-submodules with --cached ignores worktree modifications' ' |
| 441 | reset_and_clean && |
| 442 | echo "A modified line in submodule" >>submodule/a && |
| 443 | test_must_fail git grep --recurse-submodules --cached "A modified line in submodule" >actual 2>&1 && |
| 444 | test_must_be_empty actual |
| 445 | ' |
| 446 | |
| 447 | test_expect_failure 'grep --textconv: superproject .gitattributes does not affect submodules' ' |
| 448 | reset_and_clean && |
| 449 | test_config_global diff.d2x.textconv "sed -e \"s/d/x/\"" && |
| 450 | echo "a diff=d2x" >.gitattributes && |
| 451 | |
| 452 | cat >expect <<-\EOF && |
| 453 | a:(1|2)x(3|4) |
| 454 | EOF |
| 455 | git grep --textconv --recurse-submodules x >actual && |
| 456 | test_cmp expect actual |
| 457 | ' |
| 458 | |
| 459 | test_expect_failure 'grep --textconv: superproject .gitattributes (from index) does not affect submodules' ' |
| 460 | reset_and_clean && |
| 461 | test_config_global diff.d2x.textconv "sed -e \"s/d/x/\"" && |
| 462 | echo "a diff=d2x" >.gitattributes && |
| 463 | git add .gitattributes && |
| 464 | rm .gitattributes && |
| 465 | |
| 466 | cat >expect <<-\EOF && |
| 467 | a:(1|2)x(3|4) |
| 468 | EOF |
| 469 | git grep --textconv --recurse-submodules x >actual && |
| 470 | test_cmp expect actual |
| 471 | ' |
| 472 | |
| 473 | test_expect_failure 'grep --textconv: superproject .git/info/attributes does not affect submodules' ' |
| 474 | reset_and_clean && |
| 475 | test_config_global diff.d2x.textconv "sed -e \"s/d/x/\"" && |
| 476 | super_info="$(git rev-parse --git-path info)" && |
| 477 | super_attr="$super_info/attributes" && |
| 478 | test_when_finished "rm -f \"$super_attr\"" && |
| 479 | mkdir "$super_info" && |
| 480 | echo "a diff=d2x" >"$super_attr" && |
| 481 | |
| 482 | cat >expect <<-\EOF && |
| 483 | a:(1|2)x(3|4) |
| 484 | EOF |
| 485 | git grep --textconv --recurse-submodules x >actual && |
| 486 | test_cmp expect actual |
| 487 | ' |
| 488 | |
| 489 | # Note: what currently prevents this test from passing is not that the |
| 490 | # .gitattributes file from "./submodule" is being ignored, but that it is being |
| 491 | # propagated to the nested "./submodule/sub" files. |
| 492 | # |
| 493 | test_expect_failure 'grep --textconv correctly reads submodule .gitattributes' ' |
| 494 | reset_and_clean && |
| 495 | test_config_global diff.d2x.textconv "sed -e \"s/d/x/\"" && |
| 496 | echo "a diff=d2x" >submodule/.gitattributes && |
| 497 | |
| 498 | cat >expect <<-\EOF && |
| 499 | submodule/a:(1|2)x(3|4) |
| 500 | EOF |
| 501 | git grep --textconv --recurse-submodules x >actual && |
| 502 | test_cmp expect actual |
| 503 | ' |
| 504 | |
| 505 | test_expect_failure 'grep --textconv correctly reads submodule .gitattributes (from index)' ' |
| 506 | reset_and_clean && |
| 507 | test_config_global diff.d2x.textconv "sed -e \"s/d/x/\"" && |
| 508 | echo "a diff=d2x" >submodule/.gitattributes && |
| 509 | git -C submodule add .gitattributes && |
| 510 | rm submodule/.gitattributes && |
| 511 | |
| 512 | cat >expect <<-\EOF && |
| 513 | submodule/a:(1|2)x(3|4) |
| 514 | EOF |
| 515 | git grep --textconv --recurse-submodules x >actual && |
| 516 | test_cmp expect actual |
| 517 | ' |
| 518 | |
| 519 | test_expect_failure 'grep --textconv correctly reads submodule .git/info/attributes' ' |
| 520 | reset_and_clean && |
| 521 | test_config_global diff.d2x.textconv "sed -e \"s/d/x/\"" && |
| 522 | |
| 523 | submodule_info="$(git -C submodule rev-parse --path-format=absolute --git-path info)" && |
| 524 | submodule_attr="$submodule_info/attributes" && |
| 525 | test_when_finished "rm -f \"$submodule_attr\"" && |
| 526 | echo "a diff=d2x" >"$submodule_attr" && |
| 527 | |
| 528 | cat >expect <<-\EOF && |
| 529 | submodule/a:(1|2)x(3|4) |
| 530 | EOF |
| 531 | git grep --textconv --recurse-submodules x >actual && |
| 532 | test_cmp expect actual |
| 533 | ' |
| 534 | |
| 535 | test_expect_failure 'grep saves textconv cache in the appropriate repository' ' |
| 536 | reset_and_clean && |
| 537 | test_config_global diff.d2x_cached.textconv "sed -e \"s/d/x/\"" && |
| 538 | test_config_global diff.d2x_cached.cachetextconv true && |
| 539 | echo "a diff=d2x_cached" >submodule/.gitattributes && |
| 540 | |
| 541 | # We only read/write to the textconv cache when grepping from an OID, |
| 542 | # as the working tree file might have modifications. |
| 543 | git grep --textconv --cached --recurse-submodules x && |
| 544 | |
| 545 | super_textconv_cache="$(git rev-parse --git-path refs/notes/textconv/d2x_cached)" && |
| 546 | sub_textconv_cache="$(git -C submodule rev-parse \ |
| 547 | --path-format=absolute --git-path refs/notes/textconv/d2x_cached)" && |
| 548 | test_path_is_missing "$super_textconv_cache" && |
| 549 | test_path_is_file "$sub_textconv_cache" |
| 550 | ' |
| 551 | |
| 552 | test_expect_success 'grep partially-cloned submodule' ' |
| 553 | # Set up clean superproject and submodule for partial cloning. |
| 554 | test_config_global protocol.file.allow always && |
| 555 | git init super && |
| 556 | git init super/sub && |
| 557 | ( |
| 558 | cd super && |
| 559 | test_commit --no-tag "Add file in superproject" \ |
| 560 | super-file "Some content for super-file" && |
| 561 | test_commit -C sub --no-tag "Add file in submodule" \ |
| 562 | sub-file "Some content for sub-file" && |
| 563 | git submodule add ./sub && |
| 564 | git commit -m "Add other as submodule sub" && |
| 565 | test_tick && |
| 566 | test_commit -C sub --no-tag --append "Update file in submodule" \ |
| 567 | sub-file "Some more content for sub-file" && |
| 568 | git add sub && |
| 569 | git commit -m "Update submodule" && |
| 570 | test_tick && |
| 571 | git config --local uploadpack.allowfilter 1 && |
| 572 | git config --local uploadpack.allowanysha1inwant 1 && |
| 573 | git -C sub config --local uploadpack.allowfilter 1 && |
| 574 | git -C sub config --local uploadpack.allowanysha1inwant 1 |
| 575 | ) && |
| 576 | # Clone the superproject & submodule, then make sure we can lazy-fetch submodule objects. |
| 577 | git clone --filter=blob:none --also-filter-submodules \ |
| 578 | --recurse-submodules "file://$(pwd)/super" partial && |
| 579 | ( |
| 580 | cd partial && |
| 581 | cat >expect <<-\EOF && |
| 582 | HEAD^:sub/sub-file:Some content for sub-file |
| 583 | HEAD^:super-file:Some content for super-file |
| 584 | EOF |
| 585 | |
| 586 | GIT_TRACE2_EVENT="$(pwd)/trace2.log" git grep -e content \ |
| 587 | --recurse-submodules HEAD^ >actual && |
| 588 | test_cmp expect actual && |
| 589 | # Verify that we actually fetched data from the promisor remote: |
| 590 | test_grep \"category\":\"promisor\",\"key\":\"fetch_count\",\"value\":\"1\" trace2.log |
| 591 | ) |
| 592 | ' |
| 593 | |
| 594 | test_expect_success 'check scope of core.useReplaceRefs' ' |
| 595 | git init base && |
| 596 | git init base/sub && |
| 597 | |
| 598 | echo A >base/a && |
| 599 | echo B >base/b && |
| 600 | echo C >base/sub/c && |
| 601 | echo D >base/sub/d && |
| 602 | |
| 603 | git -C base/sub add c d && |
| 604 | git -C base/sub commit -m "Add files" && |
| 605 | |
| 606 | git -C base submodule add ./sub && |
| 607 | git -C base add a b sub && |
| 608 | git -C base commit -m "Add files and submodule" && |
| 609 | |
| 610 | A=$(git -C base rev-parse HEAD:a) && |
| 611 | B=$(git -C base rev-parse HEAD:b) && |
| 612 | C=$(git -C base/sub rev-parse HEAD:c) && |
| 613 | D=$(git -C base/sub rev-parse HEAD:d) && |
| 614 | |
| 615 | git -C base replace $A $B && |
| 616 | git -C base/sub replace $C $D && |
| 617 | |
| 618 | test_must_fail git -C base grep --cached --recurse-submodules A && |
| 619 | test_must_fail git -C base grep --cached --recurse-submodules C && |
| 620 | |
| 621 | git -C base config core.useReplaceRefs false && |
| 622 | git -C base grep --recurse-submodules A && |
| 623 | test_must_fail git -C base grep --cached --recurse-submodules C && |
| 624 | |
| 625 | git -C base/sub config core.useReplaceRefs false && |
| 626 | git -C base grep --cached --recurse-submodules A && |
| 627 | git -C base grep --cached --recurse-submodules C && |
| 628 | |
| 629 | git -C base config --unset core.useReplaceRefs && |
| 630 | test_must_fail git -C base grep --cached --recurse-submodules A && |
| 631 | git -C base grep --cached --recurse-submodules C |
| 632 | ' |
| 633 | |
| 634 | test_done |