3 # Copyright (c) 2012 Avery Pennaraum
4 # Copyright (c) 2015 Alexey Shumkin
6 test_description='Basic porcelain support for subtrees
8 This test verifies the basic operation of the add, pull, merge
9 and split subcommands of git subtree.
12 TEST_DIRECTORY=$(pwd)/../../../t
15 . ../../../t/test-lib.sh
17 subtree_test_create_repo()
22 git config log.date relative
35 test_debug "echo \"check a:\" \"{$1}\""
36 test_debug "echo \" b:\" \"{$2}\""
37 if [ "$1" = "$2" ]; then
46 git reset --hard HEAD~
49 # Make sure no patch changes more than one file.
50 # The original set of commits changed only one file each.
51 # A multi-file change would imply that we pruned commits
60 elif [ "$x" = "commit:" ]; then
61 if [ -n "$commit" ]; then
73 test_create_commit() (
77 mkdir -p $(dirname "$commit") \
78 || error "Could not create directory for commit"
79 echo "$commit" >"$commit"
80 git add "$commit" || error "Could not add commit"
81 git commit -m "$commit" || error "Could not commit"
86 git log --pretty=format:%s -1
91 subtree_test_count=$(($subtree_test_count+1))
95 # Tests for 'git subtree add'
99 test_expect_success 'no merge from non-existent subtree' '
100 subtree_test_create_repo "$subtree_test_count" &&
101 subtree_test_create_repo "$subtree_test_count/sub proj" &&
102 test_create_commit "$subtree_test_count" main1 &&
103 test_create_commit "$subtree_test_count/sub proj" sub1 &&
105 cd "$subtree_test_count" &&
106 git fetch ./"sub proj" master &&
107 test_must_fail git subtree merge --prefix="sub dir" FETCH_HEAD
112 test_expect_success 'no pull from non-existent subtree' '
113 subtree_test_create_repo "$subtree_test_count" &&
114 subtree_test_create_repo "$subtree_test_count/sub proj" &&
115 test_create_commit "$subtree_test_count" main1 &&
116 test_create_commit "$subtree_test_count/sub proj" sub1 &&
118 cd "$subtree_test_count" &&
119 git fetch ./"sub proj" master &&
120 test_must_fail git subtree pull --prefix="sub dir" ./"sub proj" master
124 test_expect_success 'add subproj as subtree into sub dir/ with --prefix' '
125 subtree_test_create_repo "$subtree_test_count" &&
126 subtree_test_create_repo "$subtree_test_count/sub proj" &&
127 test_create_commit "$subtree_test_count" main1 &&
128 test_create_commit "$subtree_test_count/sub proj" sub1 &&
130 cd "$subtree_test_count" &&
131 git fetch ./"sub proj" master &&
132 git subtree add --prefix="sub dir" FETCH_HEAD &&
133 check_equal "$(last_commit_message)" "Add '\''sub dir/'\'' from commit '\''$(git rev-parse FETCH_HEAD)'\''"
138 test_expect_success 'add subproj as subtree into sub dir/ with --prefix and --message' '
139 subtree_test_create_repo "$subtree_test_count" &&
140 subtree_test_create_repo "$subtree_test_count/sub proj" &&
141 test_create_commit "$subtree_test_count" main1 &&
142 test_create_commit "$subtree_test_count/sub proj" sub1 &&
144 cd "$subtree_test_count" &&
145 git fetch ./"sub proj" master &&
146 git subtree add --prefix="sub dir" --message="Added subproject" FETCH_HEAD &&
147 check_equal "$(last_commit_message)" "Added subproject"
152 test_expect_success 'add subproj as subtree into sub dir/ with --prefix as -P and --message as -m' '
153 subtree_test_create_repo "$subtree_test_count" &&
154 subtree_test_create_repo "$subtree_test_count/sub proj" &&
155 test_create_commit "$subtree_test_count" main1 &&
156 test_create_commit "$subtree_test_count/sub proj" sub1 &&
158 cd "$subtree_test_count" &&
159 git fetch ./"sub proj" master &&
160 git subtree add -P "sub dir" -m "Added subproject" FETCH_HEAD &&
161 check_equal "$(last_commit_message)" "Added subproject"
166 test_expect_success 'add subproj as subtree into sub dir/ with --squash and --prefix and --message' '
167 subtree_test_create_repo "$subtree_test_count" &&
168 subtree_test_create_repo "$subtree_test_count/sub proj" &&
169 test_create_commit "$subtree_test_count" main1 &&
170 test_create_commit "$subtree_test_count/sub proj" sub1 &&
172 cd "$subtree_test_count" &&
173 git fetch ./"sub proj" master &&
174 git subtree add --prefix="sub dir" --message="Added subproject with squash" --squash FETCH_HEAD &&
175 check_equal "$(last_commit_message)" "Added subproject with squash"
180 # Tests for 'git subtree merge'
184 test_expect_success 'merge new subproj history into sub dir/ with --prefix' '
185 subtree_test_create_repo "$subtree_test_count" &&
186 subtree_test_create_repo "$subtree_test_count/sub proj" &&
187 test_create_commit "$subtree_test_count" main1 &&
188 test_create_commit "$subtree_test_count/sub proj" sub1 &&
190 cd "$subtree_test_count" &&
191 git fetch ./"sub proj" master &&
192 git subtree add --prefix="sub dir" FETCH_HEAD
194 test_create_commit "$subtree_test_count/sub proj" sub2 &&
196 cd "$subtree_test_count" &&
197 git fetch ./"sub proj" master &&
198 git subtree merge --prefix="sub dir" FETCH_HEAD &&
199 check_equal "$(last_commit_message)" "Merge commit '\''$(git rev-parse FETCH_HEAD)'\''"
204 test_expect_success 'merge new subproj history into sub dir/ with --prefix and --message' '
205 subtree_test_create_repo "$subtree_test_count" &&
206 subtree_test_create_repo "$subtree_test_count/sub proj" &&
207 test_create_commit "$subtree_test_count" main1 &&
208 test_create_commit "$subtree_test_count/sub proj" sub1 &&
210 cd "$subtree_test_count" &&
211 git fetch ./"sub proj" master &&
212 git subtree add --prefix="sub dir" FETCH_HEAD
214 test_create_commit "$subtree_test_count/sub proj" sub2 &&
216 cd "$subtree_test_count" &&
217 git fetch ./"sub proj" master &&
218 git subtree merge --prefix="sub dir" --message="Merged changes from subproject" FETCH_HEAD &&
219 check_equal "$(last_commit_message)" "Merged changes from subproject"
224 test_expect_success 'merge new subproj history into sub dir/ with --squash and --prefix and --message' '
225 subtree_test_create_repo "$subtree_test_count/sub proj" &&
226 subtree_test_create_repo "$subtree_test_count" &&
227 test_create_commit "$subtree_test_count" main1 &&
228 test_create_commit "$subtree_test_count/sub proj" sub1 &&
230 cd "$subtree_test_count" &&
231 git fetch ./"sub proj" master &&
232 git subtree add --prefix="sub dir" FETCH_HEAD
234 test_create_commit "$subtree_test_count/sub proj" sub2 &&
236 cd "$subtree_test_count" &&
237 git fetch ./"sub proj" master &&
238 git subtree merge --prefix="sub dir" --message="Merged changes from subproject using squash" --squash FETCH_HEAD &&
239 check_equal "$(last_commit_message)" "Merged changes from subproject using squash"
244 test_expect_success 'merge the added subproj again, should do nothing' '
245 subtree_test_create_repo "$subtree_test_count" &&
246 subtree_test_create_repo "$subtree_test_count/sub proj" &&
247 test_create_commit "$subtree_test_count" main1 &&
248 test_create_commit "$subtree_test_count/sub proj" sub1 &&
250 cd "$subtree_test_count" &&
251 git fetch ./"sub proj" master &&
252 git subtree add --prefix="sub dir" FETCH_HEAD &&
253 # this shouldn not actually do anything, since FETCH_HEAD
254 # is already a parent
255 result=$(git merge -s ours -m "merge -s -ours" FETCH_HEAD) &&
256 check_equal "${result}" "Already up-to-date."
261 # Tests for 'git subtree split'
265 test_expect_success 'split requires option --prefix' '
266 subtree_test_create_repo "$subtree_test_count" &&
267 subtree_test_create_repo "$subtree_test_count/sub proj" &&
268 test_create_commit "$subtree_test_count" main1 &&
269 test_create_commit "$subtree_test_count/sub proj" sub1 &&
271 cd "$subtree_test_count" &&
272 git fetch ./"sub proj" master &&
273 git subtree add --prefix="sub dir" FETCH_HEAD &&
274 echo "You must provide the --prefix option." > expected &&
275 test_must_fail git subtree split > actual 2>&1 &&
276 test_debug "printf '"expected: "'" &&
277 test_debug "cat expected" &&
278 test_debug "printf '"actual: "'" &&
279 test_debug "cat actual" &&
280 test_cmp expected actual
285 test_expect_success 'split requires path given by option --prefix must exist' '
286 subtree_test_create_repo "$subtree_test_count" &&
287 subtree_test_create_repo "$subtree_test_count/sub proj" &&
288 test_create_commit "$subtree_test_count" main1 &&
289 test_create_commit "$subtree_test_count/sub proj" sub1 &&
291 cd "$subtree_test_count" &&
292 git fetch ./"sub proj" master &&
293 git subtree add --prefix="sub dir" FETCH_HEAD &&
294 echo "'\''non-existent-directory'\'' does not exist; use '\''git subtree add'\''" > expected &&
295 test_must_fail git subtree split --prefix=non-existent-directory > actual 2>&1 &&
296 test_debug "printf '"expected: "'" &&
297 test_debug "cat expected" &&
298 test_debug "printf '"actual: "'" &&
299 test_debug "cat actual" &&
300 test_cmp expected actual
305 test_expect_success 'split sub dir/ with --rejoin' '
306 subtree_test_create_repo "$subtree_test_count" &&
307 subtree_test_create_repo "$subtree_test_count/sub proj" &&
308 test_create_commit "$subtree_test_count" main1 &&
309 test_create_commit "$subtree_test_count/sub proj" sub1 &&
311 cd "$subtree_test_count" &&
312 git fetch ./"sub proj" master &&
313 git subtree add --prefix="sub dir" FETCH_HEAD
315 test_create_commit "$subtree_test_count" "sub dir"/main-sub1 &&
316 test_create_commit "$subtree_test_count" main2 &&
317 test_create_commit "$subtree_test_count/sub proj" sub2 &&
318 test_create_commit "$subtree_test_count" "sub dir"/main-sub2 &&
320 cd "$subtree_test_count" &&
321 git fetch ./"sub proj" master &&
322 git subtree merge --prefix="sub dir" FETCH_HEAD &&
323 split_hash=$(git subtree split --prefix="sub dir" --annotate="*") &&
324 git subtree split --prefix="sub dir" --annotate="*" --rejoin &&
325 check_equal "$(last_commit_message)" "Split '\''sub dir/'\'' into commit '\''$split_hash'\''"
330 test_expect_success 'split sub dir/ with --rejoin and --message' '
331 subtree_test_create_repo "$subtree_test_count" &&
332 subtree_test_create_repo "$subtree_test_count/sub proj" &&
333 test_create_commit "$subtree_test_count" main1 &&
334 test_create_commit "$subtree_test_count/sub proj" sub1 &&
336 cd "$subtree_test_count" &&
337 git fetch ./"sub proj" master &&
338 git subtree add --prefix="sub dir" FETCH_HEAD
340 test_create_commit "$subtree_test_count" "sub dir"/main-sub1 &&
341 test_create_commit "$subtree_test_count" main2 &&
342 test_create_commit "$subtree_test_count/sub proj" sub2 &&
343 test_create_commit "$subtree_test_count" "sub dir"/main-sub2 &&
345 cd "$subtree_test_count" &&
346 git fetch ./"sub proj" master &&
347 git subtree merge --prefix="sub dir" FETCH_HEAD &&
348 git subtree split --prefix="sub dir" --message="Split & rejoin" --annotate="*" --rejoin &&
349 check_equal "$(last_commit_message)" "Split & rejoin"
354 test_expect_success 'split "sub dir"/ with --branch' '
355 subtree_test_create_repo "$subtree_test_count" &&
356 subtree_test_create_repo "$subtree_test_count/sub proj" &&
357 test_create_commit "$subtree_test_count" main1 &&
358 test_create_commit "$subtree_test_count/sub proj" sub1 &&
360 cd "$subtree_test_count" &&
361 git fetch ./"sub proj" master &&
362 git subtree add --prefix="sub dir" FETCH_HEAD
364 test_create_commit "$subtree_test_count" "sub dir"/main-sub1 &&
365 test_create_commit "$subtree_test_count" main2 &&
366 test_create_commit "$subtree_test_count/sub proj" sub2 &&
367 test_create_commit "$subtree_test_count" "sub dir"/main-sub2 &&
369 cd "$subtree_test_count" &&
370 git fetch ./"sub proj" master &&
371 git subtree merge --prefix="sub dir" FETCH_HEAD &&
372 split_hash=$(git subtree split --prefix="sub dir" --annotate="*") &&
373 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br &&
374 check_equal "$(git rev-parse subproj-br)" "$split_hash"
379 test_expect_success 'check hash of split' '
380 subtree_test_create_repo "$subtree_test_count" &&
381 subtree_test_create_repo "$subtree_test_count/sub proj" &&
382 test_create_commit "$subtree_test_count" main1 &&
383 test_create_commit "$subtree_test_count/sub proj" sub1 &&
385 cd "$subtree_test_count" &&
386 git fetch ./"sub proj" master &&
387 git subtree add --prefix="sub dir" FETCH_HEAD
389 test_create_commit "$subtree_test_count" "sub dir"/main-sub1 &&
390 test_create_commit "$subtree_test_count" main2 &&
391 test_create_commit "$subtree_test_count/sub proj" sub2 &&
392 test_create_commit "$subtree_test_count" "sub dir"/main-sub2 &&
394 cd "$subtree_test_count" &&
395 git fetch ./"sub proj" master &&
396 git subtree merge --prefix="sub dir" FETCH_HEAD &&
397 split_hash=$(git subtree split --prefix="sub dir" --annotate="*") &&
398 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br &&
399 check_equal "$(git rev-parse subproj-br)" "$split_hash" &&
400 # Check hash of split
401 new_hash=$(git rev-parse subproj-br^2) &&
404 subdir_hash=$(git rev-parse HEAD) &&
405 check_equal ''"$new_hash"'' "$subdir_hash"
411 test_expect_success 'split "sub dir"/ with --branch for an existing branch' '
412 subtree_test_create_repo "$subtree_test_count" &&
413 subtree_test_create_repo "$subtree_test_count/sub proj" &&
414 test_create_commit "$subtree_test_count" main1 &&
415 test_create_commit "$subtree_test_count/sub proj" sub1 &&
417 cd "$subtree_test_count" &&
418 git fetch ./"sub proj" master &&
419 git branch subproj-br FETCH_HEAD &&
420 git subtree add --prefix="sub dir" FETCH_HEAD
422 test_create_commit "$subtree_test_count" "sub dir"/main-sub1 &&
423 test_create_commit "$subtree_test_count" main2 &&
424 test_create_commit "$subtree_test_count/sub proj" sub2 &&
425 test_create_commit "$subtree_test_count" "sub dir"/main-sub2 &&
427 cd "$subtree_test_count" &&
428 git fetch ./"sub proj" master &&
429 git subtree merge --prefix="sub dir" FETCH_HEAD &&
430 split_hash=$(git subtree split --prefix="sub dir" --annotate="*") &&
431 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br &&
432 check_equal "$(git rev-parse subproj-br)" "$split_hash"
437 test_expect_success 'split "sub dir"/ with --branch for an incompatible branch' '
438 subtree_test_create_repo "$subtree_test_count" &&
439 subtree_test_create_repo "$subtree_test_count/sub proj" &&
440 test_create_commit "$subtree_test_count" main1 &&
441 test_create_commit "$subtree_test_count/sub proj" sub1 &&
443 cd "$subtree_test_count" &&
444 git branch init HEAD &&
445 git fetch ./"sub proj" master &&
446 git subtree add --prefix="sub dir" FETCH_HEAD
448 test_create_commit "$subtree_test_count" "sub dir"/main-sub1 &&
449 test_create_commit "$subtree_test_count" main2 &&
450 test_create_commit "$subtree_test_count/sub proj" sub2 &&
451 test_create_commit "$subtree_test_count" "sub dir"/main-sub2 &&
453 cd "$subtree_test_count" &&
454 git fetch ./"sub proj" master &&
455 git subtree merge --prefix="sub dir" FETCH_HEAD &&
456 test_must_fail git subtree split --prefix="sub dir" --branch init
465 test_expect_success 'make sure exactly the right set of files ends up in the subproj' '
466 subtree_test_create_repo "$subtree_test_count" &&
467 subtree_test_create_repo "$subtree_test_count/sub proj" &&
468 test_create_commit "$subtree_test_count" main1 &&
469 test_create_commit "$subtree_test_count/sub proj" sub1 &&
471 cd "$subtree_test_count" &&
472 git fetch ./"sub proj" master &&
473 git subtree add --prefix="sub dir" FETCH_HEAD
475 test_create_commit "$subtree_test_count" "sub dir"/main-sub1 &&
476 test_create_commit "$subtree_test_count" main2 &&
477 test_create_commit "$subtree_test_count/sub proj" sub2 &&
478 test_create_commit "$subtree_test_count" "sub dir"/main-sub2 &&
480 cd "$subtree_test_count" &&
481 git fetch ./"sub proj" master &&
482 git subtree merge --prefix="sub dir" FETCH_HEAD &&
483 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
485 test_create_commit "$subtree_test_count/sub proj" sub3 &&
486 test_create_commit "$subtree_test_count" "sub dir"/main-sub3 &&
488 cd "$subtree_test_count/sub proj" &&
489 git fetch .. subproj-br &&
492 test_create_commit "$subtree_test_count/sub proj" sub4 &&
494 cd "$subtree_test_count" &&
495 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
497 test_create_commit "$subtree_test_count" "sub dir"/main-sub4 &&
499 cd "$subtree_test_count" &&
500 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
503 cd "$subtree_test_count/sub proj" &&
504 git fetch .. subproj-br &&
505 git merge FETCH_HEAD &&
511 chks_sub=$(cat <<TXT | sed '\''s,^,sub dir/,'\''
519 chkms_sub=$(cat <<TXT | sed '\''s,^,sub dir/,'\''
524 subfiles=$(git ls-files) &&
525 check_equal "$subfiles" "$chkms
531 test_expect_success 'make sure the subproj *only* contains commits that affect the "sub dir"' '
532 subtree_test_create_repo "$subtree_test_count" &&
533 subtree_test_create_repo "$subtree_test_count/sub proj" &&
534 test_create_commit "$subtree_test_count" main1 &&
535 test_create_commit "$subtree_test_count/sub proj" sub1 &&
537 cd "$subtree_test_count" &&
538 git fetch ./"sub proj" master &&
539 git subtree add --prefix="sub dir" FETCH_HEAD
541 test_create_commit "$subtree_test_count" "sub dir"/main-sub1 &&
542 test_create_commit "$subtree_test_count" main2 &&
543 test_create_commit "$subtree_test_count/sub proj" sub2 &&
544 test_create_commit "$subtree_test_count" "sub dir"/main-sub2 &&
546 cd "$subtree_test_count" &&
547 git fetch ./"sub proj" master &&
548 git subtree merge --prefix="sub dir" FETCH_HEAD &&
549 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
551 test_create_commit "$subtree_test_count/sub proj" sub3 &&
552 test_create_commit "$subtree_test_count" "sub dir"/main-sub3 &&
554 cd "$subtree_test_count/sub proj" &&
555 git fetch .. subproj-br &&
558 test_create_commit "$subtree_test_count/sub proj" sub4 &&
560 cd "$subtree_test_count" &&
561 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
563 test_create_commit "$subtree_test_count" "sub dir"/main-sub4 &&
565 cd "$subtree_test_count" &&
566 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
569 cd "$subtree_test_count/sub proj" &&
570 git fetch .. subproj-br &&
571 git merge FETCH_HEAD &&
577 chks_sub=$(cat <<TXT | sed '\''s,^,sub dir/,'\''
585 chkms_sub=$(cat <<TXT | sed '\''s,^,sub dir/,'\''
589 allchanges=$(git log --name-only --pretty=format:"" | sort | sed "/^$/d") &&
590 check_equal "$allchanges" "$chkms
596 test_expect_success 'make sure exactly the right set of files ends up in the mainline' '
597 subtree_test_create_repo "$subtree_test_count" &&
598 subtree_test_create_repo "$subtree_test_count/sub proj" &&
599 test_create_commit "$subtree_test_count" main1 &&
600 test_create_commit "$subtree_test_count/sub proj" sub1 &&
602 cd "$subtree_test_count" &&
603 git fetch ./"sub proj" master &&
604 git subtree add --prefix="sub dir" FETCH_HEAD
606 test_create_commit "$subtree_test_count" "sub dir"/main-sub1 &&
607 test_create_commit "$subtree_test_count" main2 &&
608 test_create_commit "$subtree_test_count/sub proj" sub2 &&
609 test_create_commit "$subtree_test_count" "sub dir"/main-sub2 &&
611 cd "$subtree_test_count" &&
612 git fetch ./"sub proj" master &&
613 git subtree merge --prefix="sub dir" FETCH_HEAD &&
614 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
616 test_create_commit "$subtree_test_count/sub proj" sub3 &&
617 test_create_commit "$subtree_test_count" "sub dir"/main-sub3 &&
619 cd "$subtree_test_count/sub proj" &&
620 git fetch .. subproj-br &&
623 test_create_commit "$subtree_test_count/sub proj" sub4 &&
625 cd "$subtree_test_count" &&
626 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
628 test_create_commit "$subtree_test_count" "sub dir"/main-sub4 &&
630 cd "$subtree_test_count" &&
631 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
634 cd "$subtree_test_count/sub proj" &&
635 git fetch .. subproj-br &&
639 cd "$subtree_test_count" &&
640 git subtree pull --prefix="sub dir" ./"sub proj" master &&
648 chks_sub=$(cat <<TXT | sed '\''s,^,sub dir/,'\''
656 chkms_sub=$(cat <<TXT | sed '\''s,^,sub dir/,'\''
660 mainfiles=$(git ls-files) &&
661 check_equal "$mainfiles" "$chkm
668 test_expect_success 'make sure each filename changed exactly once in the entire history' '
669 subtree_test_create_repo "$subtree_test_count" &&
670 subtree_test_create_repo "$subtree_test_count/sub proj" &&
671 test_create_commit "$subtree_test_count" main1 &&
672 test_create_commit "$subtree_test_count/sub proj" sub1 &&
674 cd "$subtree_test_count" &&
675 git config log.date relative
676 git fetch ./"sub proj" master &&
677 git subtree add --prefix="sub dir" FETCH_HEAD
679 test_create_commit "$subtree_test_count" "sub dir"/main-sub1 &&
680 test_create_commit "$subtree_test_count" main2 &&
681 test_create_commit "$subtree_test_count/sub proj" sub2 &&
682 test_create_commit "$subtree_test_count" "sub dir"/main-sub2 &&
684 cd "$subtree_test_count" &&
685 git fetch ./"sub proj" master &&
686 git subtree merge --prefix="sub dir" FETCH_HEAD &&
687 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
689 test_create_commit "$subtree_test_count/sub proj" sub3 &&
690 test_create_commit "$subtree_test_count" "sub dir"/main-sub3 &&
692 cd "$subtree_test_count/sub proj" &&
693 git fetch .. subproj-br &&
696 test_create_commit "$subtree_test_count/sub proj" sub4 &&
698 cd "$subtree_test_count" &&
699 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
701 test_create_commit "$subtree_test_count" "sub dir"/main-sub4 &&
703 cd "$subtree_test_count" &&
704 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
707 cd "$subtree_test_count/sub proj" &&
708 git fetch .. subproj-br &&
712 cd "$subtree_test_count" &&
713 git subtree pull --prefix="sub dir" ./"sub proj" master &&
721 chks_sub=$(cat <<TXT | sed '\''s,^,sub dir/,'\''
729 chkms_sub=$(cat <<TXT | sed '\''s,^,sub dir/,'\''
734 # main-sub?? and /"sub dir"/main-sub?? both change, because those are the
735 # changes that were split into their own history. And "sub dir"/sub?? never
736 # change, since they were *only* changed in the subtree branch.
737 allchanges=$(git log --name-only --pretty=format:"" | sort | sed "/^$/d") &&
738 expected=''"$(cat <<TXT | sort
745 check_equal "$allchanges" "$expected"
750 test_expect_success 'make sure the --rejoin commits never make it into subproj' '
751 subtree_test_create_repo "$subtree_test_count" &&
752 subtree_test_create_repo "$subtree_test_count/sub proj" &&
753 test_create_commit "$subtree_test_count" main1 &&
754 test_create_commit "$subtree_test_count/sub proj" sub1 &&
756 cd "$subtree_test_count" &&
757 git fetch ./"sub proj" master &&
758 git subtree add --prefix="sub dir" FETCH_HEAD
760 test_create_commit "$subtree_test_count" "sub dir"/main-sub1 &&
761 test_create_commit "$subtree_test_count" main2 &&
762 test_create_commit "$subtree_test_count/sub proj" sub2 &&
763 test_create_commit "$subtree_test_count" "sub dir"/main-sub2 &&
765 cd "$subtree_test_count" &&
766 git fetch ./"sub proj" master &&
767 git subtree merge --prefix="sub dir" FETCH_HEAD &&
768 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
770 test_create_commit "$subtree_test_count/sub proj" sub3 &&
771 test_create_commit "$subtree_test_count" "sub dir"/main-sub3 &&
773 cd "$subtree_test_count/sub proj" &&
774 git fetch .. subproj-br &&
777 test_create_commit "$subtree_test_count/sub proj" sub4 &&
779 cd "$subtree_test_count" &&
780 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
782 test_create_commit "$subtree_test_count" "sub dir"/main-sub4 &&
784 cd "$subtree_test_count" &&
785 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
788 cd "$subtree_test_count/sub proj" &&
789 git fetch .. subproj-br &&
793 cd "$subtree_test_count" &&
794 git subtree pull --prefix="sub dir" ./"sub proj" master &&
795 check_equal "$(git log --pretty=format:"%s" HEAD^2 | grep -i split)" ""
800 test_expect_success 'make sure no "git subtree" tagged commits make it into subproj' '
801 subtree_test_create_repo "$subtree_test_count" &&
802 subtree_test_create_repo "$subtree_test_count/sub proj" &&
803 test_create_commit "$subtree_test_count" main1 &&
804 test_create_commit "$subtree_test_count/sub proj" sub1 &&
806 cd "$subtree_test_count" &&
807 git fetch ./"sub proj" master &&
808 git subtree add --prefix="sub dir" FETCH_HEAD
810 test_create_commit "$subtree_test_count" "sub dir"/main-sub1 &&
811 test_create_commit "$subtree_test_count" main2 &&
812 test_create_commit "$subtree_test_count/sub proj" sub2 &&
813 test_create_commit "$subtree_test_count" "sub dir"/main-sub2 &&
815 cd "$subtree_test_count" &&
816 git fetch ./"sub proj" master &&
817 git subtree merge --prefix="sub dir" FETCH_HEAD &&
818 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
820 test_create_commit "$subtree_test_count/sub proj" sub3 &&
821 test_create_commit "$subtree_test_count" "sub dir"/main-sub3 &&
823 cd "$subtree_test_count/sub proj" &&
824 git fetch .. subproj-br &&
827 test_create_commit "$subtree_test_count/sub proj" sub4 &&
829 cd "$subtree_test_count" &&
830 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
832 test_create_commit "$subtree_test_count" "sub dir"/main-sub4 &&
834 cd "$subtree_test_count" &&
835 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
838 cd "$subtree_test_count/sub proj" &&
839 git fetch .. subproj-br &&
843 cd "$subtree_test_count" &&
844 git subtree pull --prefix="sub dir" ./"sub proj" master &&
846 # They are meaningless to subproj since one side of the merge refers to the mainline
847 check_equal "$(git log --pretty=format:"%s%n%b" HEAD^2 | grep "git-subtree.*:")" ""
856 test_expect_success 'make sure "git subtree split" find the correct parent' '
857 subtree_test_create_repo "$subtree_test_count" &&
858 subtree_test_create_repo "$subtree_test_count/sub proj" &&
859 test_create_commit "$subtree_test_count" main1 &&
860 test_create_commit "$subtree_test_count/sub proj" sub1 &&
862 cd "$subtree_test_count" &&
863 git fetch ./"sub proj" master &&
864 git subtree add --prefix="sub dir" FETCH_HEAD
866 test_create_commit "$subtree_test_count/sub proj" sub2 &&
868 cd "$subtree_test_count" &&
869 git fetch ./"sub proj" master &&
870 git branch subproj-ref FETCH_HEAD &&
871 git subtree merge --prefix="sub dir" FETCH_HEAD
873 test_create_commit "$subtree_test_count" "sub dir"/main-sub1 &&
875 cd "$subtree_test_count" &&
876 git subtree split --prefix="sub dir" --branch subproj-br &&
878 # at this point, the new commit parent should be subproj-ref, if it is
879 # not, something went wrong (the "newparent" of "master~" commit should
880 # have been sub2, but it was not, because its cache was not set to
882 check_equal "$(git log --pretty=format:%P -1 subproj-br)" "$(git rev-parse subproj-ref)"
887 test_expect_success 'split a new subtree without --onto option' '
888 subtree_test_create_repo "$subtree_test_count" &&
889 subtree_test_create_repo "$subtree_test_count/sub proj" &&
890 test_create_commit "$subtree_test_count" main1 &&
891 test_create_commit "$subtree_test_count/sub proj" sub1 &&
893 cd "$subtree_test_count" &&
894 git fetch ./"sub proj" master &&
895 git subtree add --prefix="sub dir" FETCH_HEAD
897 test_create_commit "$subtree_test_count/sub proj" sub2 &&
899 cd "$subtree_test_count" &&
900 git fetch ./"sub proj" master &&
901 git subtree merge --prefix="sub dir" FETCH_HEAD
903 test_create_commit "$subtree_test_count" "sub dir"/main-sub1 &&
905 cd "$subtree_test_count" &&
906 git subtree split --prefix="sub dir" --branch subproj-br
908 mkdir "$subtree_test_count"/"sub dir2" &&
909 test_create_commit "$subtree_test_count" "sub dir2"/main-sub2 &&
911 cd "$subtree_test_count" &&
913 # also test that we still can split out an entirely new subtree
914 # if the parent of the first commit in the tree is not empty,
915 # then the new subtree has accidently been attached to something
916 git subtree split --prefix="sub dir2" --branch subproj2-br &&
917 check_equal "$(git log --pretty=format:%P -1 subproj2-br)" ""
922 test_expect_success 'verify one file change per commit' '
923 subtree_test_create_repo "$subtree_test_count" &&
924 subtree_test_create_repo "$subtree_test_count/sub proj" &&
925 test_create_commit "$subtree_test_count" main1 &&
926 test_create_commit "$subtree_test_count/sub proj" sub1 &&
928 cd "$subtree_test_count" &&
929 git fetch ./"sub proj" master &&
930 git branch sub1 FETCH_HEAD &&
931 git subtree add --prefix="sub dir" sub1
933 test_create_commit "$subtree_test_count/sub proj" sub2 &&
935 cd "$subtree_test_count" &&
936 git fetch ./"sub proj" master &&
937 git subtree merge --prefix="sub dir" FETCH_HEAD
939 test_create_commit "$subtree_test_count" "sub dir"/main-sub1 &&
941 cd "$subtree_test_count" &&
942 git subtree split --prefix="sub dir" --branch subproj-br
944 mkdir "$subtree_test_count"/"sub dir2" &&
945 test_create_commit "$subtree_test_count" "sub dir2"/main-sub2 &&
947 cd "$subtree_test_count" &&
948 git subtree split --prefix="sub dir2" --branch subproj2-br &&
951 git log --pretty=format:"commit: %H" | join_commits |
953 while read commit a b; do
954 test_debug "echo Verifying commit $commit"
955 test_debug "echo a: $a"
956 test_debug "echo b: $b"
966 test_expect_success 'push split to subproj' '
967 subtree_test_create_repo "$subtree_test_count" &&
968 subtree_test_create_repo "$subtree_test_count/sub proj" &&
969 test_create_commit "$subtree_test_count" main1 &&
970 test_create_commit "$subtree_test_count/sub proj" sub1 &&
972 cd "$subtree_test_count" &&
973 git fetch ./"sub proj" master &&
974 git subtree add --prefix="sub dir" FETCH_HEAD
976 test_create_commit "$subtree_test_count" "sub dir"/main-sub1 &&
977 test_create_commit "$subtree_test_count" main2 &&
978 test_create_commit "$subtree_test_count/sub proj" sub2 &&
979 test_create_commit "$subtree_test_count" "sub dir"/main-sub2 &&
981 cd $subtree_test_count/"sub proj" &&
982 git branch sub-branch-1 &&
984 git fetch ./"sub proj" master &&
985 git subtree merge --prefix="sub dir" FETCH_HEAD
987 test_create_commit "$subtree_test_count" "sub dir"/main-sub3 &&
989 cd "$subtree_test_count" &&
990 git subtree push ./"sub proj" --prefix "sub dir" sub-branch-1 &&
992 git checkout sub-branch-1 &&
993 check_equal "$(last_commit_message)" "sub dir/main-sub3"