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/contrib/subtree/t/t7900-subtree.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 / contrib / subtree / t / t7900-subtree.sh` 1951 lines · 68803 bytes Raw Blame History 1 #!/bin/sh 2 # 3 # Copyright (c) 2012 Avery Pennaraum 4 # Copyright (c) 2015 Alexey Shumkin 5 # 6 test_description='Basic porcelain support for subtrees 7 8 This test verifies the basic operation of the add, merge, split, pull, 9 and push subcommands of git subtree. 10 ' 11 12 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main 13 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME 14 15 TEST_DIRECTORY=$(pwd)/../../../t 16 . "$TEST_DIRECTORY"/test-lib.sh 17 . "$TEST_DIRECTORY"/lib-gpg.sh 18 19 # Use our own wrapper around test-lib.sh's test_create_repo, in order 20 # to set log.date=relative. `git subtree` parses the output of `git 21 # log`, and so it must be careful to not be affected by settings that 22 # change the `git log` output. We test this by setting 23 # log.date=relative for every repo in the tests. 24 subtree_test_create_repo () { 25 test_create_repo "$1" && 26 git -C "$1" config log.date relative 27 } 28 29 test_create_commit () ( 30 repo=$1 && 31 commit=$2 && 32 cd "$repo" && 33 mkdir -p "$(dirname "$commit")" \ 34 || error "Could not create directory for commit" 35 echo "$commit" >"$commit" && 36 git add "$commit" || error "Could not add commit" 37 git commit -m "$commit" || error "Could not commit" 38 ) 39 40 test_wrong_flag() { 41 test_must_fail "$@" >out 2>err && 42 test_must_be_empty out && 43 grep "flag does not make sense with" err 44 } 45 46 last_commit_subject () { 47 git log --pretty=format:%s -1 48 } 49 50 # Upon 'git subtree add|merge --squash' of an annotated tag, 51 # pre-2.32.0 versions of 'git subtree' would write the hash of the tag 52 # (sub1 below), instead of the commit (sub1^{commit}) in the 53 # "git-subtree-split" trailer. 54 # We imitate this behaviour below using a replace ref. 55 # This function creates 3 repositories: 56 # - $1 57 # - $1-sub (added as subtree "sub" in $1) 58 # - $1-clone (clone of $1) 59 test_create_pre2_32_repo () { 60 subtree_test_create_repo "$1" && 61 subtree_test_create_repo "$1-sub" && 62 test_commit -C "$1" main1 && 63 test_commit -C "$1-sub" --annotate sub1 && 64 git -C "$1" subtree add --prefix="sub" --squash "../$1-sub" sub1 && 65 tag=$(git -C "$1" rev-parse FETCH_HEAD) && 66 commit=$(git -C "$1" rev-parse FETCH_HEAD^{commit}) && 67 git -C "$1" log -1 --format=%B HEAD^2 >msg && 68 test_commit -C "$1-sub" --annotate sub2 && 69 git clone --no-local "$1" "$1-clone" && 70 new_commit=$(sed -e "s/$commit/$tag/" msg | git -C "$1-clone" commit-tree HEAD^2^{tree}) && 71 git -C "$1-clone" replace HEAD^2 $new_commit 72 } 73 74 # test_create_subtree_add REPO ORPHAN PREFIX FILENAME ... 75 # 76 # Create a simple subtree on a new branch named ORPHAN in REPO. 77 # The subtree is then merged into the current branch of REPO, 78 # under PREFIX. The generated subtree has one commit 79 # with subject and tag FILENAME with a single file "FILENAME.t" 80 # 81 # When this method returns: 82 # - the current branch of REPO will have file PREFIX/FILENAME.t 83 # - REPO will have a branch named ORPHAN with subtree history 84 # 85 # additional arguments are forwarded to "subtree add" 86 test_create_subtree_add () { 87 ( 88 cd "$1" && 89 orphan="$2" && 90 prefix="$3" && 91 filename="$4" && 92 shift 4 && 93 last="$(git branch --show-current)" && 94 git switch --orphan "$orphan" && 95 test_commit "$filename" && 96 git checkout "$last" && 97 git subtree add --prefix="$prefix" "$@" "$orphan" 98 ) 99 } 100 101 test_expect_success 'shows short help text for -h' ' 102 git subtree -h >out 2>err && 103 test_must_be_empty err && 104 grep -e "^ *or: git subtree pull" out && 105 grep -F -e "--[no-]annotate" out 106 ' 107 108 # 109 # Tests for 'git subtree add' 110 # 111 112 test_expect_success 'no merge from non-existent subtree' ' 113 subtree_test_create_repo "$test_count" && 114 subtree_test_create_repo "$test_count/sub proj" && 115 test_create_commit "$test_count" main1 && 116 test_create_commit "$test_count/sub proj" sub1 && 117 ( 118 cd "$test_count" && 119 git fetch ./"sub proj" HEAD && 120 test_must_fail git subtree merge --prefix="sub dir" FETCH_HEAD 121 ) 122 ' 123 124 test_expect_success 'no pull from non-existent subtree' ' 125 subtree_test_create_repo "$test_count" && 126 subtree_test_create_repo "$test_count/sub proj" && 127 test_create_commit "$test_count" main1 && 128 test_create_commit "$test_count/sub proj" sub1 && 129 ( 130 cd "$test_count" && 131 git fetch ./"sub proj" HEAD && 132 test_must_fail git subtree pull --prefix="sub dir" ./"sub proj" HEAD 133 ) 134 ' 135 136 test_expect_success 'add rejects flags for split' ' 137 subtree_test_create_repo "$test_count" && 138 subtree_test_create_repo "$test_count/sub proj" && 139 test_create_commit "$test_count" main1 && 140 test_create_commit "$test_count/sub proj" sub1 && 141 ( 142 cd "$test_count" && 143 git fetch ./"sub proj" HEAD && 144 test_wrong_flag git subtree add --prefix="sub dir" --annotate=foo FETCH_HEAD && 145 test_wrong_flag git subtree add --prefix="sub dir" --branch=foo FETCH_HEAD && 146 test_wrong_flag git subtree add --prefix="sub dir" --ignore-joins FETCH_HEAD && 147 test_wrong_flag git subtree add --prefix="sub dir" --onto=foo FETCH_HEAD && 148 test_wrong_flag git subtree add --prefix="sub dir" --rejoin FETCH_HEAD 149 ) 150 ' 151 152 test_expect_success 'add subproj as subtree into sub dir/ with --prefix' ' 153 subtree_test_create_repo "$test_count" && 154 subtree_test_create_repo "$test_count/sub proj" && 155 test_create_commit "$test_count" main1 && 156 test_create_commit "$test_count/sub proj" sub1 && 157 ( 158 cd "$test_count" && 159 git fetch ./"sub proj" HEAD && 160 git subtree add --prefix="sub dir" FETCH_HEAD && 161 test "$(last_commit_subject)" = "Add '\''sub dir/'\'' from commit '\''$(git rev-parse FETCH_HEAD)'\''" 162 ) 163 ' 164 165 test_expect_success 'add subproj as subtree into sub dir/ with --prefix and --message' ' 166 subtree_test_create_repo "$test_count" && 167 subtree_test_create_repo "$test_count/sub proj" && 168 test_create_commit "$test_count" main1 && 169 test_create_commit "$test_count/sub proj" sub1 && 170 ( 171 cd "$test_count" && 172 git fetch ./"sub proj" HEAD && 173 git subtree add --prefix="sub dir" --message="Added subproject" FETCH_HEAD && 174 test "$(last_commit_subject)" = "Added subproject" 175 ) 176 ' 177 178 test_expect_success 'add subproj as subtree into sub dir/ with --prefix as -P and --message as -m' ' 179 subtree_test_create_repo "$test_count" && 180 subtree_test_create_repo "$test_count/sub proj" && 181 test_create_commit "$test_count" main1 && 182 test_create_commit "$test_count/sub proj" sub1 && 183 ( 184 cd "$test_count" && 185 git fetch ./"sub proj" HEAD && 186 git subtree add -P "sub dir" -m "Added subproject" FETCH_HEAD && 187 test "$(last_commit_subject)" = "Added subproject" 188 ) 189 ' 190 191 test_expect_success 'add subproj as subtree into sub dir/ with --squash and --prefix and --message' ' 192 subtree_test_create_repo "$test_count" && 193 subtree_test_create_repo "$test_count/sub proj" && 194 test_create_commit "$test_count" main1 && 195 test_create_commit "$test_count/sub proj" sub1 && 196 ( 197 cd "$test_count" && 198 git fetch ./"sub proj" HEAD && 199 git subtree add --prefix="sub dir" --message="Added subproject with squash" --squash FETCH_HEAD && 200 test "$(last_commit_subject)" = "Added subproject with squash" 201 ) 202 ' 203 204 # 205 # Tests for 'git subtree merge' 206 # 207 208 test_expect_success 'merge rejects flags for split' ' 209 subtree_test_create_repo "$test_count" && 210 subtree_test_create_repo "$test_count/sub proj" && 211 test_create_commit "$test_count" main1 && 212 test_create_commit "$test_count/sub proj" sub1 && 213 ( 214 cd "$test_count" && 215 git fetch ./"sub proj" HEAD && 216 git subtree add --prefix="sub dir" FETCH_HEAD 217 ) && 218 test_create_commit "$test_count/sub proj" sub2 && 219 ( 220 cd "$test_count" && 221 git fetch ./"sub proj" HEAD && 222 test_wrong_flag git subtree merge --prefix="sub dir" --annotate=foo FETCH_HEAD && 223 test_wrong_flag git subtree merge --prefix="sub dir" --branch=foo FETCH_HEAD && 224 test_wrong_flag git subtree merge --prefix="sub dir" --ignore-joins FETCH_HEAD && 225 test_wrong_flag git subtree merge --prefix="sub dir" --onto=foo FETCH_HEAD && 226 test_wrong_flag git subtree merge --prefix="sub dir" --rejoin FETCH_HEAD 227 ) 228 ' 229 230 test_expect_success 'merge new subproj history into sub dir/ with --prefix' ' 231 subtree_test_create_repo "$test_count" && 232 subtree_test_create_repo "$test_count/sub proj" && 233 test_create_commit "$test_count" main1 && 234 test_create_commit "$test_count/sub proj" sub1 && 235 ( 236 cd "$test_count" && 237 git fetch ./"sub proj" HEAD && 238 git subtree add --prefix="sub dir" FETCH_HEAD 239 ) && 240 test_create_commit "$test_count/sub proj" sub2 && 241 ( 242 cd "$test_count" && 243 git fetch ./"sub proj" HEAD && 244 git subtree merge --prefix="sub dir" FETCH_HEAD && 245 test "$(last_commit_subject)" = "Merge commit '\''$(git rev-parse FETCH_HEAD)'\''" 246 ) 247 ' 248 249 test_expect_success 'merge new subproj history into sub dir/ with --prefix and --message' ' 250 subtree_test_create_repo "$test_count" && 251 subtree_test_create_repo "$test_count/sub proj" && 252 test_create_commit "$test_count" main1 && 253 test_create_commit "$test_count/sub proj" sub1 && 254 ( 255 cd "$test_count" && 256 git fetch ./"sub proj" HEAD && 257 git subtree add --prefix="sub dir" FETCH_HEAD 258 ) && 259 test_create_commit "$test_count/sub proj" sub2 && 260 ( 261 cd "$test_count" && 262 git fetch ./"sub proj" HEAD && 263 git subtree merge --prefix="sub dir" --message="Merged changes from subproject" FETCH_HEAD && 264 test "$(last_commit_subject)" = "Merged changes from subproject" 265 ) 266 ' 267 268 test_expect_success 'merge new subproj history into sub dir/ with --squash and --prefix and --message' ' 269 subtree_test_create_repo "$test_count/sub proj" && 270 subtree_test_create_repo "$test_count" && 271 test_create_commit "$test_count" main1 && 272 test_create_commit "$test_count/sub proj" sub1 && 273 ( 274 cd "$test_count" && 275 git fetch ./"sub proj" HEAD && 276 git subtree add --prefix="sub dir" FETCH_HEAD 277 ) && 278 test_create_commit "$test_count/sub proj" sub2 && 279 ( 280 cd "$test_count" && 281 git fetch ./"sub proj" HEAD && 282 git subtree merge --prefix="sub dir" --message="Merged changes from subproject using squash" --squash FETCH_HEAD && 283 test "$(last_commit_subject)" = "Merged changes from subproject using squash" 284 ) 285 ' 286 287 test_expect_success 'merge the added subproj again, should do nothing' ' 288 subtree_test_create_repo "$test_count" && 289 subtree_test_create_repo "$test_count/sub proj" && 290 test_create_commit "$test_count" main1 && 291 test_create_commit "$test_count/sub proj" sub1 && 292 ( 293 cd "$test_count" && 294 git fetch ./"sub proj" HEAD && 295 git subtree add --prefix="sub dir" FETCH_HEAD && 296 # this shouldn not actually do anything, since FETCH_HEAD 297 # is already a parent 298 result=$(git merge -s ours -m "merge -s -ours" FETCH_HEAD) && 299 test "${result}" = "Already up to date." 300 ) 301 ' 302 303 test_expect_success 'merge new subproj history into subdir/ with a slash appended to the argument of --prefix' ' 304 subtree_test_create_repo "$test_count" && 305 subtree_test_create_repo "$test_count/subproj" && 306 test_create_commit "$test_count" main1 && 307 test_create_commit "$test_count/subproj" sub1 && 308 ( 309 cd "$test_count" && 310 git fetch ./subproj HEAD && 311 git subtree add --prefix=subdir/ FETCH_HEAD 312 ) && 313 test_create_commit "$test_count/subproj" sub2 && 314 ( 315 cd "$test_count" && 316 git fetch ./subproj HEAD && 317 git subtree merge --prefix=subdir/ FETCH_HEAD && 318 test "$(last_commit_subject)" = "Merge commit '\''$(git rev-parse FETCH_HEAD)'\''" 319 ) 320 ' 321 322 test_expect_success 'merge with --squash after annotated tag was added/merged with --squash pre-v2.32.0 ' ' 323 test_create_pre2_32_repo "$test_count" && 324 git -C "$test_count-clone" fetch "../$test_count-sub" sub2 && 325 test_must_fail git -C "$test_count-clone" subtree merge --prefix="sub" --squash FETCH_HEAD && 326 git -C "$test_count-clone" subtree merge --prefix="sub" --squash FETCH_HEAD "../$test_count-sub" 327 ' 328 329 # 330 # Tests for 'git subtree split' 331 # 332 333 test_expect_success 'split requires option --prefix' ' 334 subtree_test_create_repo "$test_count" && 335 subtree_test_create_repo "$test_count/sub proj" && 336 test_create_commit "$test_count" main1 && 337 test_create_commit "$test_count/sub proj" sub1 && 338 ( 339 cd "$test_count" && 340 git fetch ./"sub proj" HEAD && 341 git subtree add --prefix="sub dir" FETCH_HEAD && 342 echo "fatal: you must provide the --prefix option." >expected && 343 test_must_fail git subtree split >actual 2>&1 && 344 test_debug "printf '"expected: "'" && 345 test_debug "cat expected" && 346 test_debug "printf '"actual: "'" && 347 test_debug "cat actual" && 348 test_cmp expected actual 349 ) 350 ' 351 352 test_expect_success 'split requires path given by option --prefix must exist' ' 353 subtree_test_create_repo "$test_count" && 354 subtree_test_create_repo "$test_count/sub proj" && 355 test_create_commit "$test_count" main1 && 356 test_create_commit "$test_count/sub proj" sub1 && 357 ( 358 cd "$test_count" && 359 git fetch ./"sub proj" HEAD && 360 git subtree add --prefix="sub dir" FETCH_HEAD && 361 echo "fatal: '\''non-existent-directory'\'' does not exist; use '\''git subtree add'\''" >expected && 362 test_must_fail git subtree split --prefix=non-existent-directory >actual 2>&1 && 363 test_debug "printf '"expected: "'" && 364 test_debug "cat expected" && 365 test_debug "printf '"actual: "'" && 366 test_debug "cat actual" && 367 test_cmp expected actual 368 ) 369 ' 370 371 test_expect_success 'split works when prefix exists in commit but not in working tree' ' 372 subtree_test_create_repo "$test_count" && 373 ( 374 cd "$test_count" && 375 376 # create subtree 377 mkdir pkg && 378 echo ok >pkg/file && 379 git add pkg && 380 git commit -m "add pkg" && 381 good=$(git rev-parse HEAD) && 382 383 # remove it from working tree in later commit 384 git rm -r pkg && 385 git commit -m "remove pkg" && 386 387 # must still be able to split using the old commit 388 git subtree split --prefix=pkg "$good" >out && 389 test -s out 390 ) 391 ' 392 393 test_expect_success 'split rejects flags for add' ' 394 subtree_test_create_repo "$test_count" && 395 subtree_test_create_repo "$test_count/sub proj" && 396 test_create_commit "$test_count" main1 && 397 test_create_commit "$test_count/sub proj" sub1 && 398 ( 399 cd "$test_count" && 400 git fetch ./"sub proj" HEAD && 401 git subtree add --prefix="sub dir" FETCH_HEAD 402 ) && 403 test_create_commit "$test_count" "sub dir"/main-sub1 && 404 test_create_commit "$test_count" main2 && 405 test_create_commit "$test_count/sub proj" sub2 && 406 test_create_commit "$test_count" "sub dir"/main-sub2 && 407 ( 408 cd "$test_count" && 409 git fetch ./"sub proj" HEAD && 410 git subtree merge --prefix="sub dir" FETCH_HEAD && 411 split_hash=$(git subtree split --prefix="sub dir" --annotate="*") && 412 test_wrong_flag git subtree split --prefix="sub dir" --squash && 413 test_wrong_flag git subtree split --prefix="sub dir" --message=foo 414 ) 415 ' 416 417 test_expect_success 'split sub dir/ with --rejoin' ' 418 subtree_test_create_repo "$test_count" && 419 subtree_test_create_repo "$test_count/sub proj" && 420 test_create_commit "$test_count" main1 && 421 test_create_commit "$test_count/sub proj" sub1 && 422 ( 423 cd "$test_count" && 424 git fetch ./"sub proj" HEAD && 425 git subtree add --prefix="sub dir" FETCH_HEAD 426 ) && 427 test_create_commit "$test_count" "sub dir"/main-sub1 && 428 test_create_commit "$test_count" main2 && 429 test_create_commit "$test_count/sub proj" sub2 && 430 test_create_commit "$test_count" "sub dir"/main-sub2 && 431 ( 432 cd "$test_count" && 433 git fetch ./"sub proj" HEAD && 434 git subtree merge --prefix="sub dir" FETCH_HEAD && 435 split_hash=$(git subtree split --prefix="sub dir" --annotate="*") && 436 git subtree split --prefix="sub dir" --annotate="*" -b spl --rejoin && 437 test "$(last_commit_subject)" = "Split '\''sub dir/'\'' into commit '\''$split_hash'\''" && 438 test "$(git rev-list --count spl)" -eq 5 439 ) 440 ' 441 442 # Tests that commits from other subtrees are not processed as 443 # part of a split. 444 # 445 # This test performs the following: 446 # - Creates Repo with subtrees 'subA' and 'subB' 447 # - Creates commits in the repo including changes to subtrees 448 # - Runs the following 'split' and commit' commands in order: 449 # - Perform 'split' on subtree A 450 # - Perform 'split' on subtree B 451 # - Create new commits with changes to subtree A and B 452 # - Perform split on subtree A 453 # - Check for expected history 454 test_expect_success 'split with multiple subtrees' ' 455 subtree_test_create_repo "$test_count" && 456 subtree_test_create_repo "$test_count/subA" && 457 subtree_test_create_repo "$test_count/subB" && 458 test_create_commit "$test_count" main1 && 459 test_create_commit "$test_count/subA" subA1 && 460 test_create_commit "$test_count/subA" subA2 && 461 test_create_commit "$test_count/subA" subA3 && 462 test_create_commit "$test_count/subB" subB1 && 463 git -C "$test_count" fetch ./subA HEAD && 464 git -C "$test_count" subtree add --prefix=subADir FETCH_HEAD && 465 git -C "$test_count" fetch ./subB HEAD && 466 git -C "$test_count" subtree add --prefix=subBDir FETCH_HEAD && 467 test "$(git -C "$test_count" rev-list --count main)" -eq 7 && 468 test_create_commit "$test_count" subADir/main-subA1 && 469 test_create_commit "$test_count" subBDir/main-subB1 && 470 git -C "$test_count" subtree split --prefix=subADir \ 471 --squash --rejoin -m "Sub A Split 1" -b a1 && 472 test "$(git -C "$test_count" rev-list --count main..a1)" -eq 1 && 473 git -C "$test_count" subtree split --prefix=subBDir \ 474 --squash --rejoin -m "Sub B Split 1" -b b1 && 475 test "$(git -C "$test_count" rev-list --count main..b1)" -eq 1 && 476 test_create_commit "$test_count" subADir/main-subA2 && 477 test_create_commit "$test_count" subBDir/main-subB2 && 478 git -C "$test_count" subtree split --prefix=subADir \ 479 --squash --rejoin -m "Sub A Split 2" -b a2 && 480 test "$(git -C "$test_count" rev-list --count main..a2)" -eq 2 && 481 test "$(git -C "$test_count" rev-list --count a1..a2)" -eq 1 && 482 git -C "$test_count" subtree split --prefix=subBDir \ 483 --squash --rejoin -d -m "Sub B Split 1" -b b2 && 484 test "$(git -C "$test_count" rev-list --count main..b2)" -eq 2 && 485 test "$(git -C "$test_count" rev-list --count b1..b2)" -eq 1 486 ' 487 488 # When subtree split-ing a directory that has other subtree 489 # *merges* underneath it, the split must include those subtrees. 490 # This test creates a nested subtree, `subA/subB`, and tests 491 # that the tree is correct after a subtree split of `subA/`. 492 # The test covers: 493 # - An initial `subtree add`; and 494 # - A follow-up `subtree merge` 495 # both with and without `--squashed`. 496 for is_squashed in '' 'y' 497 do 498 test_expect_success "split keeps nested ${is_squashed:+--squash }subtrees that are part of the split" ' 499 subtree_test_create_repo "$test_count" && 500 ( 501 cd "$test_count" && 502 mkdir subA && 503 test_commit subA/file1 && 504 test_create_subtree_add \ 505 . mksubtree subA/subB file2 ${is_squashed:+--squash} && 506 test_path_is_file subA/file1.t && 507 test_path_is_file subA/subB/file2.t && 508 git subtree split --prefix=subA --branch=bsplit && 509 test "$(git rev-list --count bsplit)" -eq 2 && 510 git checkout bsplit && 511 test_path_is_file file1.t && 512 test_path_is_file subB/file2.t && 513 git checkout mksubtree && 514 git branch -D bsplit && 515 test_commit file3 && 516 git checkout main && 517 git subtree merge \ 518 ${is_squashed:+--squash} \ 519 --prefix=subA/subB mksubtree && 520 test_path_is_file subA/subB/file3.t && 521 git subtree split --prefix=subA --branch=bsplit && 522 test "$(git rev-list --count bsplit)" -eq 3 && 523 git checkout bsplit && 524 test_path_is_file file1.t && 525 test_path_is_file subB/file2.t && 526 test_path_is_file subB/file3.t 527 ) 528 ' 529 done 530 531 # Usually, 532 # 533 # git subtree merge -P subA --squash f00... 534 # 535 # makes two commits, in this order: 536 # 537 # 1. Squashed 'subA/' content from commit f00... 538 # 2. Merge commit (1) as 'subA' 539 # 540 # Commit 1 updates the subtree but does *not* rewrite paths. 541 # Commit 2 rewrites all trees to start with `subA/` 542 # 543 # Commit 1 either has no parents or depends only on other 544 # "Squashed 'subA/' content" commits. 545 # 546 # For merge without --squash, subtree produces just one commit: 547 # a merge commit with git-subtree trailers. 548 # 549 # In either case, if the user rebases these commits, they will 550 # still have the git-subtree-* trailers… but will NOT have 551 # the layout described above. 552 # 553 # Test that subsequent `git subtree split` are not confused by this. 554 test_expect_success 'split with rebased subtree commit' ' 555 subtree_test_create_repo "$test_count" && 556 ( 557 cd "$test_count" && 558 test_commit file0 && 559 test_create_subtree_add \ 560 . mksubtree subA file1 --squash && 561 test_path_is_file subA/file1.t && 562 mkdir subB && 563 test_commit subB/bfile && 564 git commit --amend -F - <<'EOF' && 565 Squashed '\''subB/'\'' content from commit '\''`badf00da911bbe895347b4b236f5461d55dc9877`'\'' 566 567 Simulate a cherry-picked or rebased subtree commit. 568 569 git-subtree-dir: subB 570 git-subtree-split: `badf00da911bbe895347b4b236f5461d55dc9877` 571 EOF 572 test_commit subA/file2 && 573 test_commit subB/bfile2 && 574 git commit --amend -F - <<'EOF' && 575 Split '\''subB/'\'' into commit '\''`badf00da911bbe895347b4b236f5461d55dc9877`'\'' 576 577 Simulate a cherry-picked or rebased subtree commit. 578 579 git-subtree-dir: subB 580 git-subtree-mainline: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 581 git-subtree-split: `badf00da911bbe895347b4b236f5461d55dc9877` 582 EOF 583 git subtree split --prefix=subA --branch=bsplit && 584 git checkout bsplit && 585 test_path_is_file file1.t && 586 test_path_is_file file2.t && 587 test "$(last_commit_subject)" = "subA/file2" && 588 test "$(git rev-list --count bsplit)" -eq 2 589 ) 590 ' 591 592 test_expect_success 'split sub dir/ with --rejoin from scratch' ' 593 subtree_test_create_repo "$test_count" && 594 test_create_commit "$test_count" main1 && 595 ( 596 cd "$test_count" && 597 mkdir "sub dir" && 598 echo file >"sub dir"/file && 599 git add "sub dir/file" && 600 git commit -m"sub dir file" && 601 split_hash=$(git subtree split --prefix="sub dir" --rejoin) && 602 git subtree split --prefix="sub dir" --rejoin && 603 test "$(last_commit_subject)" = "Split '\''sub dir/'\'' into commit '\''$split_hash'\''" 604 ) 605 ' 606 607 test_expect_success 'split sub dir/ with --rejoin and --message' ' 608 subtree_test_create_repo "$test_count" && 609 subtree_test_create_repo "$test_count/sub proj" && 610 test_create_commit "$test_count" main1 && 611 test_create_commit "$test_count/sub proj" sub1 && 612 ( 613 cd "$test_count" && 614 git fetch ./"sub proj" HEAD && 615 git subtree add --prefix="sub dir" FETCH_HEAD 616 ) && 617 test_create_commit "$test_count" "sub dir"/main-sub1 && 618 test_create_commit "$test_count" main2 && 619 test_create_commit "$test_count/sub proj" sub2 && 620 test_create_commit "$test_count" "sub dir"/main-sub2 && 621 ( 622 cd "$test_count" && 623 git fetch ./"sub proj" HEAD && 624 git subtree merge --prefix="sub dir" FETCH_HEAD && 625 git subtree split --prefix="sub dir" --message="Split & rejoin" --annotate="*" --rejoin && 626 test "$(last_commit_subject)" = "Split & rejoin" 627 ) 628 ' 629 630 test_expect_success 'split "sub dir"/ with --rejoin and --squash' ' 631 subtree_test_create_repo "$test_count" && 632 subtree_test_create_repo "$test_count/sub proj" && 633 test_create_commit "$test_count" main1 && 634 test_create_commit "$test_count/sub proj" sub1 && 635 ( 636 cd "$test_count" && 637 git fetch ./"sub proj" HEAD && 638 git subtree add --prefix="sub dir" --squash FETCH_HEAD 639 ) && 640 test_create_commit "$test_count" "sub dir"/main-sub1 && 641 test_create_commit "$test_count" main2 && 642 test_create_commit "$test_count/sub proj" sub2 && 643 test_create_commit "$test_count" "sub dir"/main-sub2 && 644 ( 645 cd "$test_count" && 646 git subtree pull --prefix="sub dir" --squash ./"sub proj" HEAD && 647 MAIN=$(git rev-parse --verify HEAD) && 648 SUB=$(git -C "sub proj" rev-parse --verify HEAD) && 649 650 SPLIT=$(git subtree split --prefix="sub dir" --annotate="*" --rejoin --squash) && 651 652 test_must_fail git merge-base --is-ancestor $SUB HEAD && 653 test_must_fail git merge-base --is-ancestor $SPLIT HEAD && 654 git rev-list HEAD ^$MAIN >commit-list && 655 test_line_count = 2 commit-list && 656 test "$(git rev-parse --verify HEAD:)" = "$(git rev-parse --verify $MAIN:)" && 657 test "$(git rev-parse --verify HEAD:"sub dir")" = "$(git rev-parse --verify $SPLIT:)" && 658 test "$(git rev-parse --verify HEAD^1)" = $MAIN && 659 test "$(git rev-parse --verify HEAD^2)" != $SPLIT && 660 test "$(git rev-parse --verify HEAD^2:)" = "$(git rev-parse --verify $SPLIT:)" && 661 test "$(last_commit_subject)" = "Split '\''sub dir/'\'' into commit '\''$SPLIT'\''" 662 ) 663 ' 664 665 test_expect_success 'split then pull "sub dir"/ with --rejoin and --squash' ' 666 # 1. "add" 667 subtree_test_create_repo "$test_count" && 668 subtree_test_create_repo "$test_count/sub proj" && 669 test_create_commit "$test_count" main1 && 670 test_create_commit "$test_count/sub proj" sub1 && 671 git -C "$test_count" subtree --prefix="sub dir" add --squash ./"sub proj" HEAD && 672 673 # 2. commit from parent 674 test_create_commit "$test_count" "sub dir"/main-sub1 && 675 676 # 3. "split --rejoin --squash" 677 git -C "$test_count" subtree --prefix="sub dir" split --rejoin --squash && 678 679 # 4. "pull --squash" 680 test_create_commit "$test_count/sub proj" sub2 && 681 git -C "$test_count" subtree -d --prefix="sub dir" pull --squash ./"sub proj" HEAD && 682 683 test_must_fail git merge-base HEAD FETCH_HEAD 684 ' 685 686 test_expect_success 'split "sub dir"/ with --branch' ' 687 subtree_test_create_repo "$test_count" && 688 subtree_test_create_repo "$test_count/sub proj" && 689 test_create_commit "$test_count" main1 && 690 test_create_commit "$test_count/sub proj" sub1 && 691 ( 692 cd "$test_count" && 693 git fetch ./"sub proj" HEAD && 694 git subtree add --prefix="sub dir" FETCH_HEAD 695 ) && 696 test_create_commit "$test_count" "sub dir"/main-sub1 && 697 test_create_commit "$test_count" main2 && 698 test_create_commit "$test_count/sub proj" sub2 && 699 test_create_commit "$test_count" "sub dir"/main-sub2 && 700 ( 701 cd "$test_count" && 702 git fetch ./"sub proj" HEAD && 703 git subtree merge --prefix="sub dir" FETCH_HEAD && 704 split_hash=$(git subtree split --prefix="sub dir" --annotate="*") && 705 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br && 706 test "$(git rev-parse subproj-br)" = "$split_hash" 707 ) 708 ' 709 710 test_expect_success 'check hash of split' ' 711 subtree_test_create_repo "$test_count" && 712 subtree_test_create_repo "$test_count/sub proj" && 713 test_create_commit "$test_count" main1 && 714 test_create_commit "$test_count/sub proj" sub1 && 715 ( 716 cd "$test_count" && 717 git fetch ./"sub proj" HEAD && 718 git subtree add --prefix="sub dir" FETCH_HEAD 719 ) && 720 test_create_commit "$test_count" "sub dir"/main-sub1 && 721 test_create_commit "$test_count" main2 && 722 test_create_commit "$test_count/sub proj" sub2 && 723 test_create_commit "$test_count" "sub dir"/main-sub2 && 724 ( 725 cd "$test_count" && 726 git fetch ./"sub proj" HEAD && 727 git subtree merge --prefix="sub dir" FETCH_HEAD && 728 split_hash=$(git subtree split --prefix="sub dir" --annotate="*") && 729 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br && 730 test "$(git rev-parse subproj-br)" = "$split_hash" && 731 # Check hash of split 732 new_hash=$(git rev-parse subproj-br^2) && 733 ( 734 cd ./"sub proj" && 735 subdir_hash=$(git rev-parse HEAD) && 736 test "$new_hash" = "$subdir_hash" 737 ) 738 ) 739 ' 740 741 test_expect_success 'split "sub dir"/ with --branch for an existing branch' ' 742 subtree_test_create_repo "$test_count" && 743 subtree_test_create_repo "$test_count/sub proj" && 744 test_create_commit "$test_count" main1 && 745 test_create_commit "$test_count/sub proj" sub1 && 746 ( 747 cd "$test_count" && 748 git fetch ./"sub proj" HEAD && 749 git branch subproj-br FETCH_HEAD && 750 git subtree add --prefix="sub dir" FETCH_HEAD 751 ) && 752 test_create_commit "$test_count" "sub dir"/main-sub1 && 753 test_create_commit "$test_count" main2 && 754 test_create_commit "$test_count/sub proj" sub2 && 755 test_create_commit "$test_count" "sub dir"/main-sub2 && 756 ( 757 cd "$test_count" && 758 git fetch ./"sub proj" HEAD && 759 git subtree merge --prefix="sub dir" FETCH_HEAD && 760 split_hash=$(git subtree split --prefix="sub dir" --annotate="*") && 761 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br && 762 test "$(git rev-parse subproj-br)" = "$split_hash" 763 ) 764 ' 765 766 test_expect_success 'split "sub dir"/ with --branch for an incompatible branch' ' 767 subtree_test_create_repo "$test_count" && 768 subtree_test_create_repo "$test_count/sub proj" && 769 test_create_commit "$test_count" main1 && 770 test_create_commit "$test_count/sub proj" sub1 && 771 ( 772 cd "$test_count" && 773 git branch init HEAD && 774 git fetch ./"sub proj" HEAD && 775 git subtree add --prefix="sub dir" FETCH_HEAD 776 ) && 777 test_create_commit "$test_count" "sub dir"/main-sub1 && 778 test_create_commit "$test_count" main2 && 779 test_create_commit "$test_count/sub proj" sub2 && 780 test_create_commit "$test_count" "sub dir"/main-sub2 && 781 ( 782 cd "$test_count" && 783 git fetch ./"sub proj" HEAD && 784 git subtree merge --prefix="sub dir" FETCH_HEAD && 785 test_must_fail git subtree split --prefix="sub dir" --branch init 786 ) 787 ' 788 789 test_expect_success 'split after annotated tag was added/merged with --squash pre-v2.32.0' ' 790 test_create_pre2_32_repo "$test_count" && 791 test_must_fail git -C "$test_count-clone" subtree split --prefix="sub" HEAD && 792 git -C "$test_count-clone" subtree split --prefix="sub" HEAD "../$test_count-sub" 793 ' 794 795 # 796 # Tests for 'git subtree pull' 797 # 798 799 test_expect_success 'pull requires option --prefix' ' 800 subtree_test_create_repo "$test_count" && 801 subtree_test_create_repo "$test_count/sub proj" && 802 test_create_commit "$test_count" main1 && 803 test_create_commit "$test_count/sub proj" sub1 && 804 ( 805 cd "$test_count" && 806 git fetch ./"sub proj" HEAD && 807 git subtree add --prefix="sub dir" FETCH_HEAD 808 ) && 809 test_create_commit "$test_count/sub proj" sub2 && 810 ( 811 cd "$test_count" && 812 test_must_fail git subtree pull ./"sub proj" HEAD >out 2>err && 813 814 echo "fatal: you must provide the --prefix option." >expected && 815 test_must_be_empty out && 816 test_cmp expected err 817 ) 818 ' 819 820 test_expect_success 'pull requires path given by option --prefix must exist' ' 821 subtree_test_create_repo "$test_count" && 822 subtree_test_create_repo "$test_count/sub proj" && 823 test_create_commit "$test_count" main1 && 824 test_create_commit "$test_count/sub proj" sub1 && 825 ( 826 test_must_fail git subtree pull --prefix="sub dir" ./"sub proj" HEAD >out 2>err && 827 828 echo "fatal: '\''sub dir'\'' does not exist; use '\''git subtree add'\''" >expected && 829 test_must_be_empty out && 830 test_cmp expected err 831 ) 832 ' 833 834 test_expect_success 'pull basic operation' ' 835 subtree_test_create_repo "$test_count" && 836 subtree_test_create_repo "$test_count/sub proj" && 837 test_create_commit "$test_count" main1 && 838 test_create_commit "$test_count/sub proj" sub1 && 839 ( 840 cd "$test_count" && 841 git fetch ./"sub proj" HEAD && 842 git subtree add --prefix="sub dir" FETCH_HEAD 843 ) && 844 test_create_commit "$test_count/sub proj" sub2 && 845 ( 846 cd "$test_count" && 847 exp=$(git -C "sub proj" rev-parse --verify HEAD:) && 848 git subtree pull --prefix="sub dir" ./"sub proj" HEAD && 849 act=$(git rev-parse --verify HEAD:"sub dir") && 850 test "$act" = "$exp" 851 ) 852 ' 853 854 test_expect_success 'pull rejects flags for split' ' 855 subtree_test_create_repo "$test_count" && 856 subtree_test_create_repo "$test_count/sub proj" && 857 test_create_commit "$test_count" main1 && 858 test_create_commit "$test_count/sub proj" sub1 && 859 ( 860 cd "$test_count" && 861 git fetch ./"sub proj" HEAD && 862 git subtree add --prefix="sub dir" FETCH_HEAD 863 ) && 864 test_create_commit "$test_count/sub proj" sub2 && 865 ( 866 test_must_fail git subtree pull --prefix="sub dir" --annotate=foo ./"sub proj" HEAD && 867 test_must_fail git subtree pull --prefix="sub dir" --branch=foo ./"sub proj" HEAD && 868 test_must_fail git subtree pull --prefix="sub dir" --ignore-joins ./"sub proj" HEAD && 869 test_must_fail git subtree pull --prefix="sub dir" --onto=foo ./"sub proj" HEAD && 870 test_must_fail git subtree pull --prefix="sub dir" --rejoin ./"sub proj" HEAD 871 ) 872 ' 873 874 test_expect_success 'pull with --squash after annotated tag was added/merged with --squash pre-v2.32.0 ' ' 875 test_create_pre2_32_repo "$test_count" && 876 git -C "$test_count-clone" subtree -d pull --prefix="sub" --squash "../$test_count-sub" sub2 877 ' 878 879 # 880 # Tests for 'git subtree push' 881 # 882 883 test_expect_success 'push requires option --prefix' ' 884 subtree_test_create_repo "$test_count" && 885 subtree_test_create_repo "$test_count/sub proj" && 886 test_create_commit "$test_count" main1 && 887 test_create_commit "$test_count/sub proj" sub1 && 888 ( 889 cd "$test_count" && 890 git fetch ./"sub proj" HEAD && 891 git subtree add --prefix="sub dir" FETCH_HEAD && 892 echo "fatal: you must provide the --prefix option." >expected && 893 test_must_fail git subtree push "./sub proj" from-mainline >actual 2>&1 && 894 test_debug "printf '"expected: "'" && 895 test_debug "cat expected" && 896 test_debug "printf '"actual: "'" && 897 test_debug "cat actual" && 898 test_cmp expected actual 899 ) 900 ' 901 902 test_expect_success 'push requires path given by option --prefix must exist' ' 903 subtree_test_create_repo "$test_count" && 904 subtree_test_create_repo "$test_count/sub proj" && 905 test_create_commit "$test_count" main1 && 906 test_create_commit "$test_count/sub proj" sub1 && 907 ( 908 cd "$test_count" && 909 git fetch ./"sub proj" HEAD && 910 git subtree add --prefix="sub dir" FETCH_HEAD && 911 echo "fatal: '\''non-existent-directory'\'' does not exist; use '\''git subtree add'\''" >expected && 912 test_must_fail git subtree push --prefix=non-existent-directory "./sub proj" from-mainline >actual 2>&1 && 913 test_debug "printf '"expected: "'" && 914 test_debug "cat expected" && 915 test_debug "printf '"actual: "'" && 916 test_debug "cat actual" && 917 test_cmp expected actual 918 ) 919 ' 920 921 test_expect_success 'push rejects flags for add' ' 922 subtree_test_create_repo "$test_count" && 923 subtree_test_create_repo "$test_count/sub proj" && 924 test_create_commit "$test_count" main1 && 925 test_create_commit "$test_count/sub proj" sub1 && 926 ( 927 cd "$test_count" && 928 git fetch ./"sub proj" HEAD && 929 git subtree add --prefix="sub dir" FETCH_HEAD 930 ) && 931 test_create_commit "$test_count" "sub dir"/main-sub1 && 932 test_create_commit "$test_count" main2 && 933 test_create_commit "$test_count/sub proj" sub2 && 934 test_create_commit "$test_count" "sub dir"/main-sub2 && 935 ( 936 cd "$test_count" && 937 git fetch ./"sub proj" HEAD && 938 git subtree merge --prefix="sub dir" FETCH_HEAD && 939 test_wrong_flag git subtree split --prefix="sub dir" --squash ./"sub proj" from-mainline && 940 test_wrong_flag git subtree split --prefix="sub dir" --message=foo ./"sub proj" from-mainline 941 ) 942 ' 943 944 test_expect_success 'push basic operation' ' 945 subtree_test_create_repo "$test_count" && 946 subtree_test_create_repo "$test_count/sub proj" && 947 test_create_commit "$test_count" main1 && 948 test_create_commit "$test_count/sub proj" sub1 && 949 ( 950 cd "$test_count" && 951 git fetch ./"sub proj" HEAD && 952 git subtree add --prefix="sub dir" FETCH_HEAD 953 ) && 954 test_create_commit "$test_count" "sub dir"/main-sub1 && 955 test_create_commit "$test_count" main2 && 956 test_create_commit "$test_count/sub proj" sub2 && 957 test_create_commit "$test_count" "sub dir"/main-sub2 && 958 ( 959 cd "$test_count" && 960 git fetch ./"sub proj" HEAD && 961 git subtree merge --prefix="sub dir" FETCH_HEAD && 962 before=$(git rev-parse --verify HEAD) && 963 split_hash=$(git subtree split --prefix="sub dir") && 964 git subtree push --prefix="sub dir" ./"sub proj" from-mainline && 965 test "$before" = "$(git rev-parse --verify HEAD)" && 966 test "$split_hash" = "$(git -C "sub proj" rev-parse --verify refs/heads/from-mainline)" 967 ) 968 ' 969 970 test_expect_success 'push sub dir/ with --rejoin' ' 971 subtree_test_create_repo "$test_count" && 972 subtree_test_create_repo "$test_count/sub proj" && 973 test_create_commit "$test_count" main1 && 974 test_create_commit "$test_count/sub proj" sub1 && 975 ( 976 cd "$test_count" && 977 git fetch ./"sub proj" HEAD && 978 git subtree add --prefix="sub dir" FETCH_HEAD 979 ) && 980 test_create_commit "$test_count" "sub dir"/main-sub1 && 981 test_create_commit "$test_count" main2 && 982 test_create_commit "$test_count/sub proj" sub2 && 983 test_create_commit "$test_count" "sub dir"/main-sub2 && 984 ( 985 cd "$test_count" && 986 git fetch ./"sub proj" HEAD && 987 git subtree merge --prefix="sub dir" FETCH_HEAD && 988 split_hash=$(git subtree split --prefix="sub dir" --annotate="*") && 989 git subtree push --prefix="sub dir" --annotate="*" --rejoin ./"sub proj" from-mainline && 990 test "$(last_commit_subject)" = "Split '\''sub dir/'\'' into commit '\''$split_hash'\''" && 991 test "$split_hash" = "$(git -C "sub proj" rev-parse --verify refs/heads/from-mainline)" 992 ) 993 ' 994 995 test_expect_success 'push sub dir/ with --rejoin from scratch' ' 996 subtree_test_create_repo "$test_count" && 997 test_create_commit "$test_count" main1 && 998 ( 999 cd "$test_count" && 1000 mkdir "sub dir" && 1001 echo file >"sub dir"/file && 1002 git add "sub dir/file" && 1003 git commit -m"sub dir file" && 1004 split_hash=$(git subtree split --prefix="sub dir" --rejoin) && 1005 git init --bare "sub proj.git" && 1006 git subtree push --prefix="sub dir" --rejoin ./"sub proj.git" from-mainline && 1007 test "$(last_commit_subject)" = "Split '\''sub dir/'\'' into commit '\''$split_hash'\''" && 1008 test "$split_hash" = "$(git -C "sub proj.git" rev-parse --verify refs/heads/from-mainline)" 1009 ) 1010 ' 1011 1012 test_expect_success 'push sub dir/ with --rejoin and --message' ' 1013 subtree_test_create_repo "$test_count" && 1014 subtree_test_create_repo "$test_count/sub proj" && 1015 test_create_commit "$test_count" main1 && 1016 test_create_commit "$test_count/sub proj" sub1 && 1017 ( 1018 cd "$test_count" && 1019 git fetch ./"sub proj" HEAD && 1020 git subtree add --prefix="sub dir" FETCH_HEAD 1021 ) && 1022 test_create_commit "$test_count" "sub dir"/main-sub1 && 1023 test_create_commit "$test_count" main2 && 1024 test_create_commit "$test_count/sub proj" sub2 && 1025 test_create_commit "$test_count" "sub dir"/main-sub2 && 1026 ( 1027 cd "$test_count" && 1028 git fetch ./"sub proj" HEAD && 1029 git subtree merge --prefix="sub dir" FETCH_HEAD && 1030 git subtree push --prefix="sub dir" --message="Split & rejoin" --annotate="*" --rejoin ./"sub proj" from-mainline && 1031 test "$(last_commit_subject)" = "Split & rejoin" && 1032 split_hash="$(git rev-parse --verify HEAD^2)" && 1033 test "$split_hash" = "$(git -C "sub proj" rev-parse --verify refs/heads/from-mainline)" 1034 ) 1035 ' 1036 1037 test_expect_success 'push "sub dir"/ with --rejoin and --squash' ' 1038 subtree_test_create_repo "$test_count" && 1039 subtree_test_create_repo "$test_count/sub proj" && 1040 test_create_commit "$test_count" main1 && 1041 test_create_commit "$test_count/sub proj" sub1 && 1042 ( 1043 cd "$test_count" && 1044 git fetch ./"sub proj" HEAD && 1045 git subtree add --prefix="sub dir" --squash FETCH_HEAD 1046 ) && 1047 test_create_commit "$test_count" "sub dir"/main-sub1 && 1048 test_create_commit "$test_count" main2 && 1049 test_create_commit "$test_count/sub proj" sub2 && 1050 test_create_commit "$test_count" "sub dir"/main-sub2 && 1051 ( 1052 cd "$test_count" && 1053 git subtree pull --prefix="sub dir" --squash ./"sub proj" HEAD && 1054 MAIN=$(git rev-parse --verify HEAD) && 1055 SUB=$(git -C "sub proj" rev-parse --verify HEAD) && 1056 1057 SPLIT=$(git subtree split --prefix="sub dir" --annotate="*") && 1058 git subtree push --prefix="sub dir" --annotate="*" --rejoin --squash ./"sub proj" from-mainline && 1059 1060 test_must_fail git merge-base --is-ancestor $SUB HEAD && 1061 test_must_fail git merge-base --is-ancestor $SPLIT HEAD && 1062 git rev-list HEAD ^$MAIN >commit-list && 1063 test_line_count = 2 commit-list && 1064 test "$(git rev-parse --verify HEAD:)" = "$(git rev-parse --verify $MAIN:)" && 1065 test "$(git rev-parse --verify HEAD:"sub dir")" = "$(git rev-parse --verify $SPLIT:)" && 1066 test "$(git rev-parse --verify HEAD^1)" = $MAIN && 1067 test "$(git rev-parse --verify HEAD^2)" != $SPLIT && 1068 test "$(git rev-parse --verify HEAD^2:)" = "$(git rev-parse --verify $SPLIT:)" && 1069 test "$(last_commit_subject)" = "Split '\''sub dir/'\'' into commit '\''$SPLIT'\''" && 1070 test "$SPLIT" = "$(git -C "sub proj" rev-parse --verify refs/heads/from-mainline)" 1071 ) 1072 ' 1073 1074 test_expect_success 'push "sub dir"/ with --branch' ' 1075 subtree_test_create_repo "$test_count" && 1076 subtree_test_create_repo "$test_count/sub proj" && 1077 test_create_commit "$test_count" main1 && 1078 test_create_commit "$test_count/sub proj" sub1 && 1079 ( 1080 cd "$test_count" && 1081 git fetch ./"sub proj" HEAD && 1082 git subtree add --prefix="sub dir" FETCH_HEAD 1083 ) && 1084 test_create_commit "$test_count" "sub dir"/main-sub1 && 1085 test_create_commit "$test_count" main2 && 1086 test_create_commit "$test_count/sub proj" sub2 && 1087 test_create_commit "$test_count" "sub dir"/main-sub2 && 1088 ( 1089 cd "$test_count" && 1090 git fetch ./"sub proj" HEAD && 1091 git subtree merge --prefix="sub dir" FETCH_HEAD && 1092 split_hash=$(git subtree split --prefix="sub dir" --annotate="*") && 1093 git subtree push --prefix="sub dir" --annotate="*" --branch subproj-br ./"sub proj" from-mainline && 1094 test "$(git rev-parse subproj-br)" = "$split_hash" && 1095 test "$split_hash" = "$(git -C "sub proj" rev-parse --verify refs/heads/from-mainline)" 1096 ) 1097 ' 1098 1099 test_expect_success 'check hash of push' ' 1100 subtree_test_create_repo "$test_count" && 1101 subtree_test_create_repo "$test_count/sub proj" && 1102 test_create_commit "$test_count" main1 && 1103 test_create_commit "$test_count/sub proj" sub1 && 1104 ( 1105 cd "$test_count" && 1106 git fetch ./"sub proj" HEAD && 1107 git subtree add --prefix="sub dir" FETCH_HEAD 1108 ) && 1109 test_create_commit "$test_count" "sub dir"/main-sub1 && 1110 test_create_commit "$test_count" main2 && 1111 test_create_commit "$test_count/sub proj" sub2 && 1112 test_create_commit "$test_count" "sub dir"/main-sub2 && 1113 ( 1114 cd "$test_count" && 1115 git fetch ./"sub proj" HEAD && 1116 git subtree merge --prefix="sub dir" FETCH_HEAD && 1117 split_hash=$(git subtree split --prefix="sub dir" --annotate="*") && 1118 git subtree push --prefix="sub dir" --annotate="*" --branch subproj-br ./"sub proj" from-mainline && 1119 test "$(git rev-parse subproj-br)" = "$split_hash" && 1120 # Check hash of split 1121 new_hash=$(git rev-parse subproj-br^2) && 1122 ( 1123 cd ./"sub proj" && 1124 subdir_hash=$(git rev-parse HEAD) && 1125 test "$new_hash" = "$subdir_hash" 1126 ) && 1127 test "$split_hash" = "$(git -C "sub proj" rev-parse --verify refs/heads/from-mainline)" 1128 ) 1129 ' 1130 1131 test_expect_success 'push "sub dir"/ with --branch for an existing branch' ' 1132 subtree_test_create_repo "$test_count" && 1133 subtree_test_create_repo "$test_count/sub proj" && 1134 test_create_commit "$test_count" main1 && 1135 test_create_commit "$test_count/sub proj" sub1 && 1136 ( 1137 cd "$test_count" && 1138 git fetch ./"sub proj" HEAD && 1139 git branch subproj-br FETCH_HEAD && 1140 git subtree add --prefix="sub dir" FETCH_HEAD 1141 ) && 1142 test_create_commit "$test_count" "sub dir"/main-sub1 && 1143 test_create_commit "$test_count" main2 && 1144 test_create_commit "$test_count/sub proj" sub2 && 1145 test_create_commit "$test_count" "sub dir"/main-sub2 && 1146 ( 1147 cd "$test_count" && 1148 git fetch ./"sub proj" HEAD && 1149 git subtree merge --prefix="sub dir" FETCH_HEAD && 1150 split_hash=$(git subtree split --prefix="sub dir" --annotate="*") && 1151 git subtree push --prefix="sub dir" --annotate="*" --branch subproj-br ./"sub proj" from-mainline && 1152 test "$(git rev-parse subproj-br)" = "$split_hash" && 1153 test "$split_hash" = "$(git -C "sub proj" rev-parse --verify refs/heads/from-mainline)" 1154 ) 1155 ' 1156 1157 test_expect_success 'push "sub dir"/ with --branch for an incompatible branch' ' 1158 subtree_test_create_repo "$test_count" && 1159 subtree_test_create_repo "$test_count/sub proj" && 1160 test_create_commit "$test_count" main1 && 1161 test_create_commit "$test_count/sub proj" sub1 && 1162 ( 1163 cd "$test_count" && 1164 git branch init HEAD && 1165 git fetch ./"sub proj" HEAD && 1166 git subtree add --prefix="sub dir" FETCH_HEAD 1167 ) && 1168 test_create_commit "$test_count" "sub dir"/main-sub1 && 1169 test_create_commit "$test_count" main2 && 1170 test_create_commit "$test_count/sub proj" sub2 && 1171 test_create_commit "$test_count" "sub dir"/main-sub2 && 1172 ( 1173 cd "$test_count" && 1174 git fetch ./"sub proj" HEAD && 1175 git subtree merge --prefix="sub dir" FETCH_HEAD && 1176 test_must_fail git subtree push --prefix="sub dir" --branch init "./sub proj" from-mainline 1177 ) 1178 ' 1179 1180 test_expect_success 'push "sub dir"/ with a local rev' ' 1181 subtree_test_create_repo "$test_count" && 1182 subtree_test_create_repo "$test_count/sub proj" && 1183 test_create_commit "$test_count" main1 && 1184 test_create_commit "$test_count/sub proj" sub1 && 1185 ( 1186 cd "$test_count" && 1187 git fetch ./"sub proj" HEAD && 1188 git subtree add --prefix="sub dir" FETCH_HEAD 1189 ) && 1190 test_create_commit "$test_count" "sub dir"/main-sub1 && 1191 test_create_commit "$test_count" "sub dir"/main-sub2 && 1192 ( 1193 cd "$test_count" && 1194 bad_tree=$(git rev-parse --verify HEAD:"sub dir") && 1195 good_tree=$(git rev-parse --verify HEAD^:"sub dir") && 1196 git subtree push --prefix="sub dir" --annotate="*" ./"sub proj" HEAD^:from-mainline && 1197 split_tree=$(git -C "sub proj" rev-parse --verify refs/heads/from-mainline:) && 1198 test "$split_tree" = "$good_tree" 1199 ) 1200 ' 1201 1202 test_expect_success 'push after annotated tag was added/merged with --squash pre-v2.32.0' ' 1203 test_create_pre2_32_repo "$test_count" && 1204 test_create_commit "$test_count-clone" sub/main-sub1 && 1205 git -C "$test_count-clone" subtree push --prefix="sub" "../$test_count-sub" from-mainline 1206 ' 1207 1208 # 1209 # Validity checking 1210 # 1211 1212 test_expect_success 'make sure exactly the right set of files ends up in the subproj' ' 1213 subtree_test_create_repo "$test_count" && 1214 subtree_test_create_repo "$test_count/sub proj" && 1215 test_create_commit "$test_count" main1 && 1216 test_create_commit "$test_count/sub proj" sub1 && 1217 ( 1218 cd "$test_count" && 1219 git fetch ./"sub proj" HEAD && 1220 git subtree add --prefix="sub dir" FETCH_HEAD 1221 ) && 1222 test_create_commit "$test_count" "sub dir"/main-sub1 && 1223 test_create_commit "$test_count" main2 && 1224 test_create_commit "$test_count/sub proj" sub2 && 1225 test_create_commit "$test_count" "sub dir"/main-sub2 && 1226 ( 1227 cd "$test_count" && 1228 git fetch ./"sub proj" HEAD && 1229 git subtree merge --prefix="sub dir" FETCH_HEAD && 1230 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin 1231 ) && 1232 test_create_commit "$test_count/sub proj" sub3 && 1233 test_create_commit "$test_count" "sub dir"/main-sub3 && 1234 ( 1235 cd "$test_count/sub proj" && 1236 git fetch .. subproj-br && 1237 git merge FETCH_HEAD 1238 ) && 1239 test_create_commit "$test_count/sub proj" sub4 && 1240 ( 1241 cd "$test_count" && 1242 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin 1243 ) && 1244 test_create_commit "$test_count" "sub dir"/main-sub4 && 1245 ( 1246 cd "$test_count" && 1247 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin 1248 ) && 1249 ( 1250 cd "$test_count/sub proj" && 1251 git fetch .. subproj-br && 1252 git merge FETCH_HEAD && 1253 1254 test_write_lines main-sub1 main-sub2 main-sub3 main-sub4 \ 1255 sub1 sub2 sub3 sub4 >expect && 1256 git ls-files >actual && 1257 test_cmp expect actual 1258 ) 1259 ' 1260 1261 test_expect_success 'make sure the subproj *only* contains commits that affect the "sub dir"' ' 1262 subtree_test_create_repo "$test_count" && 1263 subtree_test_create_repo "$test_count/sub proj" && 1264 test_create_commit "$test_count" main1 && 1265 test_create_commit "$test_count/sub proj" sub1 && 1266 ( 1267 cd "$test_count" && 1268 git fetch ./"sub proj" HEAD && 1269 git subtree add --prefix="sub dir" FETCH_HEAD 1270 ) && 1271 test_create_commit "$test_count" "sub dir"/main-sub1 && 1272 test_create_commit "$test_count" main2 && 1273 test_create_commit "$test_count/sub proj" sub2 && 1274 test_create_commit "$test_count" "sub dir"/main-sub2 && 1275 ( 1276 cd "$test_count" && 1277 git fetch ./"sub proj" HEAD && 1278 git subtree merge --prefix="sub dir" FETCH_HEAD && 1279 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin 1280 ) && 1281 test_create_commit "$test_count/sub proj" sub3 && 1282 test_create_commit "$test_count" "sub dir"/main-sub3 && 1283 ( 1284 cd "$test_count/sub proj" && 1285 git fetch .. subproj-br && 1286 git merge FETCH_HEAD 1287 ) && 1288 test_create_commit "$test_count/sub proj" sub4 && 1289 ( 1290 cd "$test_count" && 1291 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin 1292 ) && 1293 test_create_commit "$test_count" "sub dir"/main-sub4 && 1294 ( 1295 cd "$test_count" && 1296 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin 1297 ) && 1298 ( 1299 cd "$test_count/sub proj" && 1300 git fetch .. subproj-br && 1301 git merge FETCH_HEAD && 1302 1303 test_write_lines main-sub1 main-sub2 main-sub3 main-sub4 \ 1304 sub1 sub2 sub3 sub4 >expect && 1305 git log --name-only --pretty=format:"" >log && 1306 sort actual && 1307 test_cmp expect actual 1308 ) 1309 ' 1310 1311 test_expect_success 'make sure exactly the right set of files ends up in the mainline' ' 1312 subtree_test_create_repo "$test_count" && 1313 subtree_test_create_repo "$test_count/sub proj" && 1314 test_create_commit "$test_count" main1 && 1315 test_create_commit "$test_count/sub proj" sub1 && 1316 ( 1317 cd "$test_count" && 1318 git fetch ./"sub proj" HEAD && 1319 git subtree add --prefix="sub dir" FETCH_HEAD 1320 ) && 1321 test_create_commit "$test_count" "sub dir"/main-sub1 && 1322 test_create_commit "$test_count" main2 && 1323 test_create_commit "$test_count/sub proj" sub2 && 1324 test_create_commit "$test_count" "sub dir"/main-sub2 && 1325 ( 1326 cd "$test_count" && 1327 git fetch ./"sub proj" HEAD && 1328 git subtree merge --prefix="sub dir" FETCH_HEAD && 1329 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin 1330 ) && 1331 test_create_commit "$test_count/sub proj" sub3 && 1332 test_create_commit "$test_count" "sub dir"/main-sub3 && 1333 ( 1334 cd "$test_count/sub proj" && 1335 git fetch .. subproj-br && 1336 git merge FETCH_HEAD 1337 ) && 1338 test_create_commit "$test_count/sub proj" sub4 && 1339 ( 1340 cd "$test_count" && 1341 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin 1342 ) && 1343 test_create_commit "$test_count" "sub dir"/main-sub4 && 1344 ( 1345 cd "$test_count" && 1346 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin 1347 ) && 1348 ( 1349 cd "$test_count/sub proj" && 1350 git fetch .. subproj-br && 1351 git merge FETCH_HEAD 1352 ) && 1353 ( 1354 cd "$test_count" && 1355 git subtree pull --prefix="sub dir" ./"sub proj" HEAD && 1356 1357 test_write_lines main1 main2 >chkm && 1358 test_write_lines main-sub1 main-sub2 main-sub3 main-sub4 >chkms && 1359 sed "s,^,sub dir/," chkms >chkms_sub && 1360 test_write_lines sub1 sub2 sub3 sub4 >chks && 1361 sed "s,^,sub dir/," chks >chks_sub && 1362 1363 cat chkm chkms_sub chks_sub >expect && 1364 git ls-files >actual && 1365 test_cmp expect actual 1366 ) 1367 ' 1368 1369 test_expect_success 'make sure each filename changed exactly once in the entire history' ' 1370 subtree_test_create_repo "$test_count" && 1371 subtree_test_create_repo "$test_count/sub proj" && 1372 test_create_commit "$test_count" main1 && 1373 test_create_commit "$test_count/sub proj" sub1 && 1374 ( 1375 cd "$test_count" && 1376 git config log.date relative && 1377 git fetch ./"sub proj" HEAD && 1378 git subtree add --prefix="sub dir" FETCH_HEAD 1379 ) && 1380 test_create_commit "$test_count" "sub dir"/main-sub1 && 1381 test_create_commit "$test_count" main2 && 1382 test_create_commit "$test_count/sub proj" sub2 && 1383 test_create_commit "$test_count" "sub dir"/main-sub2 && 1384 ( 1385 cd "$test_count" && 1386 git fetch ./"sub proj" HEAD && 1387 git subtree merge --prefix="sub dir" FETCH_HEAD && 1388 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin 1389 ) && 1390 test_create_commit "$test_count/sub proj" sub3 && 1391 test_create_commit "$test_count" "sub dir"/main-sub3 && 1392 ( 1393 cd "$test_count/sub proj" && 1394 git fetch .. subproj-br && 1395 git merge FETCH_HEAD 1396 ) && 1397 test_create_commit "$test_count/sub proj" sub4 && 1398 ( 1399 cd "$test_count" && 1400 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin 1401 ) && 1402 test_create_commit "$test_count" "sub dir"/main-sub4 && 1403 ( 1404 cd "$test_count" && 1405 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin 1406 ) && 1407 ( 1408 cd "$test_count/sub proj" && 1409 git fetch .. subproj-br && 1410 git merge FETCH_HEAD 1411 ) && 1412 ( 1413 cd "$test_count" && 1414 git subtree pull --prefix="sub dir" ./"sub proj" HEAD && 1415 1416 test_write_lines main1 main2 >chkm && 1417 test_write_lines sub1 sub2 sub3 sub4 >chks && 1418 test_write_lines main-sub1 main-sub2 main-sub3 main-sub4 >chkms && 1419 sed "s,^,sub dir/," chkms >chkms_sub && 1420 1421 # main-sub?? and /"sub dir"/main-sub?? both change, because those are the 1422 # changes that were split into their own history. And "sub dir"/sub?? never 1423 # change, since they were *only* changed in the subtree branch. 1424 git log --name-only --pretty=format:"" >log && 1425 sort sorted-log && 1426 sed "/^$/ d" sorted-log >actual && 1427 1428 cat chkms chkm chks chkms_sub >expect-unsorted && 1429 sort expect-unsorted >expect && 1430 test_cmp expect actual 1431 ) 1432 ' 1433 1434 test_expect_success 'make sure the --rejoin commits never make it into subproj' ' 1435 subtree_test_create_repo "$test_count" && 1436 subtree_test_create_repo "$test_count/sub proj" && 1437 test_create_commit "$test_count" main1 && 1438 test_create_commit "$test_count/sub proj" sub1 && 1439 ( 1440 cd "$test_count" && 1441 git fetch ./"sub proj" HEAD && 1442 git subtree add --prefix="sub dir" FETCH_HEAD 1443 ) && 1444 test_create_commit "$test_count" "sub dir"/main-sub1 && 1445 test_create_commit "$test_count" main2 && 1446 test_create_commit "$test_count/sub proj" sub2 && 1447 test_create_commit "$test_count" "sub dir"/main-sub2 && 1448 ( 1449 cd "$test_count" && 1450 git fetch ./"sub proj" HEAD && 1451 git subtree merge --prefix="sub dir" FETCH_HEAD && 1452 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin 1453 ) && 1454 test_create_commit "$test_count/sub proj" sub3 && 1455 test_create_commit "$test_count" "sub dir"/main-sub3 && 1456 ( 1457 cd "$test_count/sub proj" && 1458 git fetch .. subproj-br && 1459 git merge FETCH_HEAD 1460 ) && 1461 test_create_commit "$test_count/sub proj" sub4 && 1462 ( 1463 cd "$test_count" && 1464 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin 1465 ) && 1466 test_create_commit "$test_count" "sub dir"/main-sub4 && 1467 ( 1468 cd "$test_count" && 1469 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin 1470 ) && 1471 ( 1472 cd "$test_count/sub proj" && 1473 git fetch .. subproj-br && 1474 git merge FETCH_HEAD 1475 ) && 1476 ( 1477 cd "$test_count" && 1478 git subtree pull --prefix="sub dir" ./"sub proj" HEAD && 1479 test "$(git log --pretty=format:"%s" HEAD^2 | grep -i split)" = "" 1480 ) 1481 ' 1482 1483 test_expect_success 'make sure no "git subtree" tagged commits make it into subproj' ' 1484 subtree_test_create_repo "$test_count" && 1485 subtree_test_create_repo "$test_count/sub proj" && 1486 test_create_commit "$test_count" main1 && 1487 test_create_commit "$test_count/sub proj" sub1 && 1488 ( 1489 cd "$test_count" && 1490 git fetch ./"sub proj" HEAD && 1491 git subtree add --prefix="sub dir" FETCH_HEAD 1492 ) && 1493 test_create_commit "$test_count" "sub dir"/main-sub1 && 1494 test_create_commit "$test_count" main2 && 1495 test_create_commit "$test_count/sub proj" sub2 && 1496 test_create_commit "$test_count" "sub dir"/main-sub2 && 1497 ( 1498 cd "$test_count" && 1499 git fetch ./"sub proj" HEAD && 1500 git subtree merge --prefix="sub dir" FETCH_HEAD && 1501 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin 1502 ) && 1503 test_create_commit "$test_count/sub proj" sub3 && 1504 test_create_commit "$test_count" "sub dir"/main-sub3 && 1505 ( 1506 cd "$test_count/sub proj" && 1507 git fetch .. subproj-br && 1508 git merge FETCH_HEAD 1509 ) && 1510 test_create_commit "$test_count/sub proj" sub4 && 1511 ( 1512 cd "$test_count" && 1513 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin 1514 ) && 1515 test_create_commit "$test_count" "sub dir"/main-sub4 && 1516 ( 1517 cd "$test_count" && 1518 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin 1519 ) && 1520 ( 1521 cd "$test_count/sub proj" && 1522 git fetch .. subproj-br && 1523 git merge FETCH_HEAD 1524 ) && 1525 ( 1526 cd "$test_count" && 1527 git subtree pull --prefix="sub dir" ./"sub proj" HEAD && 1528 1529 # They are meaningless to subproj since one side of the merge refers to the mainline 1530 test "$(git log --pretty=format:"%s%n%b" HEAD^2 | grep "git-subtree.*:")" = "" 1531 ) 1532 ' 1533 1534 # 1535 # A new set of tests 1536 # 1537 1538 test_expect_success 'make sure "git subtree split" find the correct parent' ' 1539 subtree_test_create_repo "$test_count" && 1540 subtree_test_create_repo "$test_count/sub proj" && 1541 test_create_commit "$test_count" main1 && 1542 test_create_commit "$test_count/sub proj" sub1 && 1543 ( 1544 cd "$test_count" && 1545 git fetch ./"sub proj" HEAD && 1546 git subtree add --prefix="sub dir" FETCH_HEAD 1547 ) && 1548 test_create_commit "$test_count/sub proj" sub2 && 1549 ( 1550 cd "$test_count" && 1551 git fetch ./"sub proj" HEAD && 1552 git branch subproj-ref FETCH_HEAD && 1553 git subtree merge --prefix="sub dir" FETCH_HEAD 1554 ) && 1555 test_create_commit "$test_count" "sub dir"/main-sub1 && 1556 ( 1557 cd "$test_count" && 1558 git subtree split --prefix="sub dir" --branch subproj-br && 1559 1560 # at this point, the new commit parent should be subproj-ref, if it is 1561 # not, something went wrong (the "newparent" of "HEAD~" commit should 1562 # have been sub2, but it was not, because its cache was not set to 1563 # itself) 1564 test "$(git log --pretty=format:%P -1 subproj-br)" = "$(git rev-parse subproj-ref)" 1565 ) 1566 ' 1567 1568 test_expect_success 'split a new subtree without --onto option' ' 1569 subtree_test_create_repo "$test_count" && 1570 subtree_test_create_repo "$test_count/sub proj" && 1571 test_create_commit "$test_count" main1 && 1572 test_create_commit "$test_count/sub proj" sub1 && 1573 ( 1574 cd "$test_count" && 1575 git fetch ./"sub proj" HEAD && 1576 git subtree add --prefix="sub dir" FETCH_HEAD 1577 ) && 1578 test_create_commit "$test_count/sub proj" sub2 && 1579 ( 1580 cd "$test_count" && 1581 git fetch ./"sub proj" HEAD && 1582 git subtree merge --prefix="sub dir" FETCH_HEAD 1583 ) && 1584 test_create_commit "$test_count" "sub dir"/main-sub1 && 1585 ( 1586 cd "$test_count" && 1587 git subtree split --prefix="sub dir" --branch subproj-br 1588 ) && 1589 mkdir "$test_count"/"sub dir2" && 1590 test_create_commit "$test_count" "sub dir2"/main-sub2 && 1591 ( 1592 cd "$test_count" && 1593 1594 # also test that we still can split out an entirely new subtree 1595 # if the parent of the first commit in the tree is not empty, 1596 # then the new subtree has accidentally been attached to something 1597 git subtree split --prefix="sub dir2" --branch subproj2-br && 1598 test "$(git log --pretty=format:%P -1 subproj2-br)" = "" 1599 ) 1600 ' 1601 1602 test_expect_success 'verify one file change per commit' ' 1603 subtree_test_create_repo "$test_count" && 1604 subtree_test_create_repo "$test_count/sub proj" && 1605 test_create_commit "$test_count" main1 && 1606 test_create_commit "$test_count/sub proj" sub1 && 1607 ( 1608 cd "$test_count" && 1609 git fetch ./"sub proj" HEAD && 1610 git branch sub1 FETCH_HEAD && 1611 git subtree add --prefix="sub dir" sub1 1612 ) && 1613 test_create_commit "$test_count/sub proj" sub2 && 1614 ( 1615 cd "$test_count" && 1616 git fetch ./"sub proj" HEAD && 1617 git subtree merge --prefix="sub dir" FETCH_HEAD 1618 ) && 1619 test_create_commit "$test_count" "sub dir"/main-sub1 && 1620 ( 1621 cd "$test_count" && 1622 git subtree split --prefix="sub dir" --branch subproj-br 1623 ) && 1624 mkdir "$test_count"/"sub dir2" && 1625 test_create_commit "$test_count" "sub dir2"/main-sub2 && 1626 ( 1627 cd "$test_count" && 1628 git subtree split --prefix="sub dir2" --branch subproj2-br && 1629 1630 git log --format="%H" >commit-list && 1631 while read commit 1632 do 1633 git log -n1 --format="" --name-only "$commit" >file-list && 1634 test_line_count -le 1 file-list || return 1 1635 done