]>
git.ipfire.org Git - thirdparty/git.git/blob - contrib/subtree/t/t7900-subtree.sh
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, merge, split, pull,
9 and push subcommands of git subtree.
12 TEST_DIRECTORY
=$
(pwd)/..
/..
/..
/t
13 .
"$TEST_DIRECTORY"/test-lib.sh
15 # Use our own wrapper around test-lib.sh's test_create_repo, in order
16 # to set log.date=relative. `git subtree` parses the output of `git
17 # log`, and so it must be careful to not be affected by settings that
18 # change the `git log` output. We test this by setting
19 # log.date=relative for every repo in the tests.
20 subtree_test_create_repo
() {
21 test_create_repo
"$1" &&
22 git
-C "$1" config log.
date relative
25 test_create_commit
() (
29 mkdir
-p "$(dirname "$commit")" \
30 || error
"Could not create directory for commit"
31 echo "$commit" >"$commit" &&
32 git add
"$commit" || error
"Could not add commit"
33 git commit
-m "$commit" || error
"Could not commit"
37 test_must_fail
"$@" >out
2>err
&&
38 test_must_be_empty out
&&
39 grep "flag does not make sense with" err
42 last_commit_subject
() {
43 git log
--pretty=format
:%s
-1
46 test_expect_success
'shows short help text for -h' '
47 test_expect_code 129 git subtree -h >out 2>err &&
48 test_must_be_empty err &&
49 grep -e "^ *or: git subtree pull" out &&
50 grep -e --annotate out
54 # Tests for 'git subtree add'
57 test_expect_success
'no merge from non-existent subtree' '
58 subtree_test_create_repo "$test_count" &&
59 subtree_test_create_repo "$test_count/sub proj" &&
60 test_create_commit "$test_count" main1 &&
61 test_create_commit "$test_count/sub proj" sub1 &&
64 git fetch ./"sub proj" HEAD &&
65 test_must_fail git subtree merge --prefix="sub dir" FETCH_HEAD
69 test_expect_success
'no pull from non-existent subtree' '
70 subtree_test_create_repo "$test_count" &&
71 subtree_test_create_repo "$test_count/sub proj" &&
72 test_create_commit "$test_count" main1 &&
73 test_create_commit "$test_count/sub proj" sub1 &&
76 git fetch ./"sub proj" HEAD &&
77 test_must_fail git subtree pull --prefix="sub dir" ./"sub proj" HEAD
81 test_expect_success
'add rejects flags for split' '
82 subtree_test_create_repo "$test_count" &&
83 subtree_test_create_repo "$test_count/sub proj" &&
84 test_create_commit "$test_count" main1 &&
85 test_create_commit "$test_count/sub proj" sub1 &&
88 git fetch ./"sub proj" HEAD &&
89 test_wrong_flag git subtree add --prefix="sub dir" --annotate=foo FETCH_HEAD &&
90 test_wrong_flag git subtree add --prefix="sub dir" --branch=foo FETCH_HEAD &&
91 test_wrong_flag git subtree add --prefix="sub dir" --ignore-joins FETCH_HEAD &&
92 test_wrong_flag git subtree add --prefix="sub dir" --onto=foo FETCH_HEAD &&
93 test_wrong_flag git subtree add --prefix="sub dir" --rejoin FETCH_HEAD
97 test_expect_success
'add subproj as subtree into sub dir/ with --prefix' '
98 subtree_test_create_repo "$test_count" &&
99 subtree_test_create_repo "$test_count/sub proj" &&
100 test_create_commit "$test_count" main1 &&
101 test_create_commit "$test_count/sub proj" sub1 &&
104 git fetch ./"sub proj" HEAD &&
105 git subtree add --prefix="sub dir" FETCH_HEAD &&
106 test "$(last_commit_subject)" = "Add '\''sub dir/'\'' from commit '\''$(git rev-parse FETCH_HEAD)'\''"
110 test_expect_success
'add subproj as subtree into sub dir/ with --prefix and --message' '
111 subtree_test_create_repo "$test_count" &&
112 subtree_test_create_repo "$test_count/sub proj" &&
113 test_create_commit "$test_count" main1 &&
114 test_create_commit "$test_count/sub proj" sub1 &&
117 git fetch ./"sub proj" HEAD &&
118 git subtree add --prefix="sub dir" --message="Added subproject" FETCH_HEAD &&
119 test "$(last_commit_subject)" = "Added subproject"
123 test_expect_success
'add subproj as subtree into sub dir/ with --prefix as -P and --message as -m' '
124 subtree_test_create_repo "$test_count" &&
125 subtree_test_create_repo "$test_count/sub proj" &&
126 test_create_commit "$test_count" main1 &&
127 test_create_commit "$test_count/sub proj" sub1 &&
130 git fetch ./"sub proj" HEAD &&
131 git subtree add -P "sub dir" -m "Added subproject" FETCH_HEAD &&
132 test "$(last_commit_subject)" = "Added subproject"
136 test_expect_success
'add subproj as subtree into sub dir/ with --squash and --prefix and --message' '
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 &&
143 git fetch ./"sub proj" HEAD &&
144 git subtree add --prefix="sub dir" --message="Added subproject with squash" --squash FETCH_HEAD &&
145 test "$(last_commit_subject)" = "Added subproject with squash"
150 # Tests for 'git subtree merge'
153 test_expect_success
'merge rejects flags for split' '
154 subtree_test_create_repo "$test_count" &&
155 subtree_test_create_repo "$test_count/sub proj" &&
156 test_create_commit "$test_count" main1 &&
157 test_create_commit "$test_count/sub proj" sub1 &&
160 git fetch ./"sub proj" HEAD &&
161 git subtree add --prefix="sub dir" FETCH_HEAD
163 test_create_commit "$test_count/sub proj" sub2 &&
166 git fetch ./"sub proj" HEAD &&
167 test_wrong_flag git subtree merge --prefix="sub dir" --annotate=foo FETCH_HEAD &&
168 test_wrong_flag git subtree merge --prefix="sub dir" --branch=foo FETCH_HEAD &&
169 test_wrong_flag git subtree merge --prefix="sub dir" --ignore-joins FETCH_HEAD &&
170 test_wrong_flag git subtree merge --prefix="sub dir" --onto=foo FETCH_HEAD &&
171 test_wrong_flag git subtree merge --prefix="sub dir" --rejoin FETCH_HEAD
175 test_expect_success
'merge new subproj history into sub dir/ with --prefix' '
176 subtree_test_create_repo "$test_count" &&
177 subtree_test_create_repo "$test_count/sub proj" &&
178 test_create_commit "$test_count" main1 &&
179 test_create_commit "$test_count/sub proj" sub1 &&
182 git fetch ./"sub proj" HEAD &&
183 git subtree add --prefix="sub dir" FETCH_HEAD
185 test_create_commit "$test_count/sub proj" sub2 &&
188 git fetch ./"sub proj" HEAD &&
189 git subtree merge --prefix="sub dir" FETCH_HEAD &&
190 test "$(last_commit_subject)" = "Merge commit '\''$(git rev-parse FETCH_HEAD)'\''"
194 test_expect_success
'merge new subproj history into sub dir/ with --prefix and --message' '
195 subtree_test_create_repo "$test_count" &&
196 subtree_test_create_repo "$test_count/sub proj" &&
197 test_create_commit "$test_count" main1 &&
198 test_create_commit "$test_count/sub proj" sub1 &&
201 git fetch ./"sub proj" HEAD &&
202 git subtree add --prefix="sub dir" FETCH_HEAD
204 test_create_commit "$test_count/sub proj" sub2 &&
207 git fetch ./"sub proj" HEAD &&
208 git subtree merge --prefix="sub dir" --message="Merged changes from subproject" FETCH_HEAD &&
209 test "$(last_commit_subject)" = "Merged changes from subproject"
213 test_expect_success
'merge new subproj history into sub dir/ with --squash and --prefix and --message' '
214 subtree_test_create_repo "$test_count/sub proj" &&
215 subtree_test_create_repo "$test_count" &&
216 test_create_commit "$test_count" main1 &&
217 test_create_commit "$test_count/sub proj" sub1 &&
220 git fetch ./"sub proj" HEAD &&
221 git subtree add --prefix="sub dir" FETCH_HEAD
223 test_create_commit "$test_count/sub proj" sub2 &&
226 git fetch ./"sub proj" HEAD &&
227 git subtree merge --prefix="sub dir" --message="Merged changes from subproject using squash" --squash FETCH_HEAD &&
228 test "$(last_commit_subject)" = "Merged changes from subproject using squash"
232 test_expect_success
'merge the added subproj again, should do nothing' '
233 subtree_test_create_repo "$test_count" &&
234 subtree_test_create_repo "$test_count/sub proj" &&
235 test_create_commit "$test_count" main1 &&
236 test_create_commit "$test_count/sub proj" sub1 &&
239 git fetch ./"sub proj" HEAD &&
240 git subtree add --prefix="sub dir" FETCH_HEAD &&
241 # this shouldn not actually do anything, since FETCH_HEAD
242 # is already a parent
243 result=$(git merge -s ours -m "merge -s -ours" FETCH_HEAD) &&
244 test "${result}" = "Already up to date."
248 test_expect_success
'merge new subproj history into subdir/ with a slash appended to the argument of --prefix' '
249 subtree_test_create_repo "$test_count" &&
250 subtree_test_create_repo "$test_count/subproj" &&
251 test_create_commit "$test_count" main1 &&
252 test_create_commit "$test_count/subproj" sub1 &&
255 git fetch ./subproj HEAD &&
256 git subtree add --prefix=subdir/ FETCH_HEAD
258 test_create_commit "$test_count/subproj" sub2 &&
261 git fetch ./subproj HEAD &&
262 git subtree merge --prefix=subdir/ FETCH_HEAD &&
263 test "$(last_commit_subject)" = "Merge commit '\''$(git rev-parse FETCH_HEAD)'\''"
268 # Tests for 'git subtree split'
271 test_expect_success
'split requires option --prefix' '
272 subtree_test_create_repo "$test_count" &&
273 subtree_test_create_repo "$test_count/sub proj" &&
274 test_create_commit "$test_count" main1 &&
275 test_create_commit "$test_count/sub proj" sub1 &&
278 git fetch ./"sub proj" HEAD &&
279 git subtree add --prefix="sub dir" FETCH_HEAD &&
280 echo "You must provide the --prefix option." >expected &&
281 test_must_fail git subtree split >actual 2>&1 &&
282 test_debug "printf '"expected: "'" &&
283 test_debug "cat expected" &&
284 test_debug "printf '"actual: "'" &&
285 test_debug "cat actual" &&
286 test_cmp expected actual
290 test_expect_success
'split requires path given by option --prefix must exist' '
291 subtree_test_create_repo "$test_count" &&
292 subtree_test_create_repo "$test_count/sub proj" &&
293 test_create_commit "$test_count" main1 &&
294 test_create_commit "$test_count/sub proj" sub1 &&
297 git fetch ./"sub proj" HEAD &&
298 git subtree add --prefix="sub dir" FETCH_HEAD &&
299 echo "'\''non-existent-directory'\'' does not exist; use '\''git subtree add'\''" >expected &&
300 test_must_fail git subtree split --prefix=non-existent-directory >actual 2>&1 &&
301 test_debug "printf '"expected: "'" &&
302 test_debug "cat expected" &&
303 test_debug "printf '"actual: "'" &&
304 test_debug "cat actual" &&
305 test_cmp expected actual
309 test_expect_success
'split rejects flags for add' '
310 subtree_test_create_repo "$test_count" &&
311 subtree_test_create_repo "$test_count/sub proj" &&
312 test_create_commit "$test_count" main1 &&
313 test_create_commit "$test_count/sub proj" sub1 &&
316 git fetch ./"sub proj" HEAD &&
317 git subtree add --prefix="sub dir" FETCH_HEAD
319 test_create_commit "$test_count" "sub dir"/main-sub1 &&
320 test_create_commit "$test_count" main2 &&
321 test_create_commit "$test_count/sub proj" sub2 &&
322 test_create_commit "$test_count" "sub dir"/main-sub2 &&
325 git fetch ./"sub proj" HEAD &&
326 git subtree merge --prefix="sub dir" FETCH_HEAD &&
327 split_hash=$(git subtree split --prefix="sub dir" --annotate="*") &&
328 test_wrong_flag git subtree split --prefix="sub dir" --squash &&
329 test_wrong_flag git subtree split --prefix="sub dir" --message=foo
333 test_expect_success
'split sub dir/ with --rejoin' '
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 &&
340 git fetch ./"sub proj" HEAD &&
341 git subtree add --prefix="sub dir" FETCH_HEAD
343 test_create_commit "$test_count" "sub dir"/main-sub1 &&
344 test_create_commit "$test_count" main2 &&
345 test_create_commit "$test_count/sub proj" sub2 &&
346 test_create_commit "$test_count" "sub dir"/main-sub2 &&
349 git fetch ./"sub proj" HEAD &&
350 git subtree merge --prefix="sub dir" FETCH_HEAD &&
351 split_hash=$(git subtree split --prefix="sub dir" --annotate="*") &&
352 git subtree split --prefix="sub dir" --annotate="*" --rejoin &&
353 test "$(last_commit_subject)" = "Split '\''sub dir/'\'' into commit '\''$split_hash'\''"
357 test_expect_success
'split sub dir/ with --rejoin from scratch' '
358 subtree_test_create_repo "$test_count" &&
359 test_create_commit "$test_count" main1 &&
363 echo file >"sub dir"/file &&
364 git add "sub dir/file" &&
365 git commit -m"sub dir file" &&
366 split_hash=$(git subtree split --prefix="sub dir" --rejoin) &&
367 git subtree split --prefix="sub dir" --rejoin &&
368 test "$(last_commit_subject)" = "Split '\''sub dir/'\'' into commit '\''$split_hash'\''"
372 test_expect_success
'split sub dir/ with --rejoin and --message' '
373 subtree_test_create_repo "$test_count" &&
374 subtree_test_create_repo "$test_count/sub proj" &&
375 test_create_commit "$test_count" main1 &&
376 test_create_commit "$test_count/sub proj" sub1 &&
379 git fetch ./"sub proj" HEAD &&
380 git subtree add --prefix="sub dir" FETCH_HEAD
382 test_create_commit "$test_count" "sub dir"/main-sub1 &&
383 test_create_commit "$test_count" main2 &&
384 test_create_commit "$test_count/sub proj" sub2 &&
385 test_create_commit "$test_count" "sub dir"/main-sub2 &&
388 git fetch ./"sub proj" HEAD &&
389 git subtree merge --prefix="sub dir" FETCH_HEAD &&
390 git subtree split --prefix="sub dir" --message="Split & rejoin" --annotate="*" --rejoin &&
391 test "$(last_commit_subject)" = "Split & rejoin"
395 test_expect_success
'split "sub dir"/ with --rejoin and --squash' '
396 subtree_test_create_repo "$test_count" &&
397 subtree_test_create_repo "$test_count/sub proj" &&
398 test_create_commit "$test_count" main1 &&
399 test_create_commit "$test_count/sub proj" sub1 &&
402 git fetch ./"sub proj" HEAD &&
403 git subtree add --prefix="sub dir" --squash FETCH_HEAD
405 test_create_commit "$test_count" "sub dir"/main-sub1 &&
406 test_create_commit "$test_count" main2 &&
407 test_create_commit "$test_count/sub proj" sub2 &&
408 test_create_commit "$test_count" "sub dir"/main-sub2 &&
411 git subtree pull --prefix="sub dir" --squash ./"sub proj" HEAD &&
412 MAIN=$(git rev-parse --verify HEAD) &&
413 SUB=$(git -C "sub proj" rev-parse --verify HEAD) &&
415 SPLIT=$(git subtree split --prefix="sub dir" --annotate="*" --rejoin --squash) &&
417 test_must_fail git merge-base --is-ancestor $SUB HEAD &&
418 test_must_fail git merge-base --is-ancestor $SPLIT HEAD &&
419 git rev-list HEAD ^$MAIN >commit-list &&
420 test_line_count = 2 commit-list &&
421 test "$(git rev-parse --verify HEAD:)" = "$(git rev-parse --verify $MAIN:)" &&
422 test "$(git rev-parse --verify HEAD:"sub dir")" = "$(git rev-parse --verify $SPLIT:)" &&
423 test "$(git rev-parse --verify HEAD^1)" = $MAIN &&
424 test "$(git rev-parse --verify HEAD^2)" != $SPLIT &&
425 test "$(git rev-parse --verify HEAD^2:)" = "$(git rev-parse --verify $SPLIT:)" &&
426 test "$(last_commit_subject)" = "Split '\''sub dir/'\'' into commit '\''$SPLIT'\''"
430 test_expect_success
'split then pull "sub dir"/ with --rejoin and --squash' '
432 subtree_test_create_repo "$test_count" &&
433 subtree_test_create_repo "$test_count/sub proj" &&
434 test_create_commit "$test_count" main1 &&
435 test_create_commit "$test_count/sub proj" sub1 &&
436 git -C "$test_count" subtree --prefix="sub dir" add --squash ./"sub proj" HEAD &&
438 # 2. commit from parent
439 test_create_commit "$test_count" "sub dir"/main-sub1 &&
441 # 3. "split --rejoin --squash"
442 git -C "$test_count" subtree --prefix="sub dir" split --rejoin --squash &&
445 test_create_commit "$test_count/sub proj" sub2 &&
446 git -C "$test_count" subtree -d --prefix="sub dir" pull --squash ./"sub proj" HEAD &&
448 test_must_fail git merge-base HEAD FETCH_HEAD
451 test_expect_success
'split "sub dir"/ with --branch' '
452 subtree_test_create_repo "$test_count" &&
453 subtree_test_create_repo "$test_count/sub proj" &&
454 test_create_commit "$test_count" main1 &&
455 test_create_commit "$test_count/sub proj" sub1 &&
458 git fetch ./"sub proj" HEAD &&
459 git subtree add --prefix="sub dir" FETCH_HEAD
461 test_create_commit "$test_count" "sub dir"/main-sub1 &&
462 test_create_commit "$test_count" main2 &&
463 test_create_commit "$test_count/sub proj" sub2 &&
464 test_create_commit "$test_count" "sub dir"/main-sub2 &&
467 git fetch ./"sub proj" HEAD &&
468 git subtree merge --prefix="sub dir" FETCH_HEAD &&
469 split_hash=$(git subtree split --prefix="sub dir" --annotate="*") &&
470 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br &&
471 test "$(git rev-parse subproj-br)" = "$split_hash"
475 test_expect_success
'check hash of split' '
476 subtree_test_create_repo "$test_count" &&
477 subtree_test_create_repo "$test_count/sub proj" &&
478 test_create_commit "$test_count" main1 &&
479 test_create_commit "$test_count/sub proj" sub1 &&
482 git fetch ./"sub proj" HEAD &&
483 git subtree add --prefix="sub dir" FETCH_HEAD
485 test_create_commit "$test_count" "sub dir"/main-sub1 &&
486 test_create_commit "$test_count" main2 &&
487 test_create_commit "$test_count/sub proj" sub2 &&
488 test_create_commit "$test_count" "sub dir"/main-sub2 &&
491 git fetch ./"sub proj" HEAD &&
492 git subtree merge --prefix="sub dir" FETCH_HEAD &&
493 split_hash=$(git subtree split --prefix="sub dir" --annotate="*") &&
494 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br &&
495 test "$(git rev-parse subproj-br)" = "$split_hash" &&
496 # Check hash of split
497 new_hash=$(git rev-parse subproj-br^2) &&
500 subdir_hash=$(git rev-parse HEAD) &&
501 test "$new_hash" = "$subdir_hash"
506 test_expect_success
'split "sub dir"/ with --branch for an existing branch' '
507 subtree_test_create_repo "$test_count" &&
508 subtree_test_create_repo "$test_count/sub proj" &&
509 test_create_commit "$test_count" main1 &&
510 test_create_commit "$test_count/sub proj" sub1 &&
513 git fetch ./"sub proj" HEAD &&
514 git branch subproj-br FETCH_HEAD &&
515 git subtree add --prefix="sub dir" FETCH_HEAD
517 test_create_commit "$test_count" "sub dir"/main-sub1 &&
518 test_create_commit "$test_count" main2 &&
519 test_create_commit "$test_count/sub proj" sub2 &&
520 test_create_commit "$test_count" "sub dir"/main-sub2 &&
523 git fetch ./"sub proj" HEAD &&
524 git subtree merge --prefix="sub dir" FETCH_HEAD &&
525 split_hash=$(git subtree split --prefix="sub dir" --annotate="*") &&
526 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br &&
527 test "$(git rev-parse subproj-br)" = "$split_hash"
531 test_expect_success
'split "sub dir"/ with --branch for an incompatible branch' '
532 subtree_test_create_repo "$test_count" &&
533 subtree_test_create_repo "$test_count/sub proj" &&
534 test_create_commit "$test_count" main1 &&
535 test_create_commit "$test_count/sub proj" sub1 &&
538 git branch init HEAD &&
539 git fetch ./"sub proj" HEAD &&
540 git subtree add --prefix="sub dir" FETCH_HEAD
542 test_create_commit "$test_count" "sub dir"/main-sub1 &&
543 test_create_commit "$test_count" main2 &&
544 test_create_commit "$test_count/sub proj" sub2 &&
545 test_create_commit "$test_count" "sub dir"/main-sub2 &&
548 git fetch ./"sub proj" HEAD &&
549 git subtree merge --prefix="sub dir" FETCH_HEAD &&
550 test_must_fail git subtree split --prefix="sub dir" --branch init
555 # Tests for 'git subtree pull'
558 test_expect_success
'pull requires option --prefix' '
559 subtree_test_create_repo "$test_count" &&
560 subtree_test_create_repo "$test_count/sub proj" &&
561 test_create_commit "$test_count" main1 &&
562 test_create_commit "$test_count/sub proj" sub1 &&
565 git fetch ./"sub proj" HEAD &&
566 git subtree add --prefix="sub dir" FETCH_HEAD
568 test_create_commit "$test_count/sub proj" sub2 &&
571 test_must_fail git subtree pull ./"sub proj" HEAD >out 2>err &&
573 echo "You must provide the --prefix option." >expected &&
574 test_must_be_empty out &&
575 test_cmp expected err
579 test_expect_success
'pull requires path given by option --prefix must exist' '
580 subtree_test_create_repo "$test_count" &&
581 subtree_test_create_repo "$test_count/sub proj" &&
582 test_create_commit "$test_count" main1 &&
583 test_create_commit "$test_count/sub proj" sub1 &&
585 test_must_fail git subtree pull --prefix="sub dir" ./"sub proj" HEAD >out 2>err &&
587 echo "'\''sub dir'\'' does not exist; use '\''git subtree add'\''" >expected &&
588 test_must_be_empty out &&
589 test_cmp expected err
593 test_expect_success
'pull basic operation' '
594 subtree_test_create_repo "$test_count" &&
595 subtree_test_create_repo "$test_count/sub proj" &&
596 test_create_commit "$test_count" main1 &&
597 test_create_commit "$test_count/sub proj" sub1 &&
600 git fetch ./"sub proj" HEAD &&
601 git subtree add --prefix="sub dir" FETCH_HEAD
603 test_create_commit "$test_count/sub proj" sub2 &&
606 exp=$(git -C "sub proj" rev-parse --verify HEAD:) &&
607 git subtree pull --prefix="sub dir" ./"sub proj" HEAD &&
608 act=$(git rev-parse --verify HEAD:"sub dir") &&
613 test_expect_success
'pull rejects flags for split' '
614 subtree_test_create_repo "$test_count" &&
615 subtree_test_create_repo "$test_count/sub proj" &&
616 test_create_commit "$test_count" main1 &&
617 test_create_commit "$test_count/sub proj" sub1 &&
620 git fetch ./"sub proj" HEAD &&
621 git subtree add --prefix="sub dir" FETCH_HEAD
623 test_create_commit "$test_count/sub proj" sub2 &&
625 test_must_fail git subtree pull --prefix="sub dir" --annotate=foo ./"sub proj" HEAD &&
626 test_must_fail git subtree pull --prefix="sub dir" --branch=foo ./"sub proj" HEAD &&
627 test_must_fail git subtree pull --prefix="sub dir" --ignore-joins ./"sub proj" HEAD &&
628 test_must_fail git subtree pull --prefix="sub dir" --onto=foo ./"sub proj" HEAD &&
629 test_must_fail git subtree pull --prefix="sub dir" --rejoin ./"sub proj" HEAD
634 # Tests for 'git subtree push'
637 test_expect_success
'push requires option --prefix' '
638 subtree_test_create_repo "$test_count" &&
639 subtree_test_create_repo "$test_count/sub proj" &&
640 test_create_commit "$test_count" main1 &&
641 test_create_commit "$test_count/sub proj" sub1 &&
644 git fetch ./"sub proj" HEAD &&
645 git subtree add --prefix="sub dir" FETCH_HEAD &&
646 echo "You must provide the --prefix option." >expected &&
647 test_must_fail git subtree push "./sub proj" from-mainline >actual 2>&1 &&
648 test_debug "printf '"expected: "'" &&
649 test_debug "cat expected" &&
650 test_debug "printf '"actual: "'" &&
651 test_debug "cat actual" &&
652 test_cmp expected actual
656 test_expect_success
'push requires path given by option --prefix must exist' '
657 subtree_test_create_repo "$test_count" &&
658 subtree_test_create_repo "$test_count/sub proj" &&
659 test_create_commit "$test_count" main1 &&
660 test_create_commit "$test_count/sub proj" sub1 &&
663 git fetch ./"sub proj" HEAD &&
664 git subtree add --prefix="sub dir" FETCH_HEAD &&
665 echo "'\''non-existent-directory'\'' does not exist; use '\''git subtree add'\''" >expected &&
666 test_must_fail git subtree push --prefix=non-existent-directory "./sub proj" from-mainline >actual 2>&1 &&
667 test_debug "printf '"expected: "'" &&
668 test_debug "cat expected" &&
669 test_debug "printf '"actual: "'" &&
670 test_debug "cat actual" &&
671 test_cmp expected actual
675 test_expect_success
'push rejects flags for add' '
676 subtree_test_create_repo "$test_count" &&
677 subtree_test_create_repo "$test_count/sub proj" &&
678 test_create_commit "$test_count" main1 &&
679 test_create_commit "$test_count/sub proj" sub1 &&
682 git fetch ./"sub proj" HEAD &&
683 git subtree add --prefix="sub dir" FETCH_HEAD
685 test_create_commit "$test_count" "sub dir"/main-sub1 &&
686 test_create_commit "$test_count" main2 &&
687 test_create_commit "$test_count/sub proj" sub2 &&
688 test_create_commit "$test_count" "sub dir"/main-sub2 &&
691 git fetch ./"sub proj" HEAD &&
692 git subtree merge --prefix="sub dir" FETCH_HEAD &&
693 test_wrong_flag git subtree split --prefix="sub dir" --squash ./"sub proj" from-mainline &&
694 test_wrong_flag git subtree split --prefix="sub dir" --message=foo ./"sub proj" from-mainline
698 test_expect_success
'push basic operation' '
699 subtree_test_create_repo "$test_count" &&
700 subtree_test_create_repo "$test_count/sub proj" &&
701 test_create_commit "$test_count" main1 &&
702 test_create_commit "$test_count/sub proj" sub1 &&
705 git fetch ./"sub proj" HEAD &&
706 git subtree add --prefix="sub dir" FETCH_HEAD
708 test_create_commit "$test_count" "sub dir"/main-sub1 &&
709 test_create_commit "$test_count" main2 &&
710 test_create_commit "$test_count/sub proj" sub2 &&
711 test_create_commit "$test_count" "sub dir"/main-sub2 &&
714 git fetch ./"sub proj" HEAD &&
715 git subtree merge --prefix="sub dir" FETCH_HEAD &&
716 before=$(git rev-parse --verify HEAD) &&
717 split_hash=$(git subtree split --prefix="sub dir") &&
718 git subtree push --prefix="sub dir" ./"sub proj" from-mainline &&
719 test "$before" = "$(git rev-parse --verify HEAD)" &&
720 test "$split_hash" = "$(git -C "sub proj" rev-parse --verify refs/heads/from-mainline)"
724 test_expect_success
'push sub dir/ with --rejoin' '
725 subtree_test_create_repo "$test_count" &&
726 subtree_test_create_repo "$test_count/sub proj" &&
727 test_create_commit "$test_count" main1 &&
728 test_create_commit "$test_count/sub proj" sub1 &&
731 git fetch ./"sub proj" HEAD &&
732 git subtree add --prefix="sub dir" FETCH_HEAD
734 test_create_commit "$test_count" "sub dir"/main-sub1 &&
735 test_create_commit "$test_count" main2 &&
736 test_create_commit "$test_count/sub proj" sub2 &&
737 test_create_commit "$test_count" "sub dir"/main-sub2 &&
740 git fetch ./"sub proj" HEAD &&
741 git subtree merge --prefix="sub dir" FETCH_HEAD &&
742 split_hash=$(git subtree split --prefix="sub dir" --annotate="*") &&
743 git subtree push --prefix="sub dir" --annotate="*" --rejoin ./"sub proj" from-mainline &&
744 test "$(last_commit_subject)" = "Split '\''sub dir/'\'' into commit '\''$split_hash'\''" &&
745 test "$split_hash" = "$(git -C "sub proj" rev-parse --verify refs/heads/from-mainline)"
749 test_expect_success
'push sub dir/ with --rejoin from scratch' '
750 subtree_test_create_repo "$test_count" &&
751 test_create_commit "$test_count" main1 &&
755 echo file >"sub dir"/file &&
756 git add "sub dir/file" &&
757 git commit -m"sub dir file" &&
758 split_hash=$(git subtree split --prefix="sub dir" --rejoin) &&
759 git init --bare "sub proj.git" &&
760 git subtree push --prefix="sub dir" --rejoin ./"sub proj.git" from-mainline &&
761 test "$(last_commit_subject)" = "Split '\''sub dir/'\'' into commit '\''$split_hash'\''" &&
762 test "$split_hash" = "$(git -C "sub proj.git" rev-parse --verify refs/heads/from-mainline)"
766 test_expect_success
'push sub dir/ with --rejoin and --message' '
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 &&
773 git fetch ./"sub proj" HEAD &&
774 git subtree add --prefix="sub dir" FETCH_HEAD
776 test_create_commit "$test_count" "sub dir"/main-sub1 &&
777 test_create_commit "$test_count" main2 &&
778 test_create_commit "$test_count/sub proj" sub2 &&
779 test_create_commit "$test_count" "sub dir"/main-sub2 &&
782 git fetch ./"sub proj" HEAD &&
783 git subtree merge --prefix="sub dir" FETCH_HEAD &&
784 git subtree push --prefix="sub dir" --message="Split & rejoin" --annotate="*" --rejoin ./"sub proj" from-mainline &&
785 test "$(last_commit_subject)" = "Split & rejoin" &&
786 split_hash="$(git rev-parse --verify HEAD^2)" &&
787 test "$split_hash" = "$(git -C "sub proj" rev-parse --verify refs/heads/from-mainline)"
791 test_expect_success
'push "sub dir"/ with --rejoin and --squash' '
792 subtree_test_create_repo "$test_count" &&
793 subtree_test_create_repo "$test_count/sub proj" &&
794 test_create_commit "$test_count" main1 &&
795 test_create_commit "$test_count/sub proj" sub1 &&
798 git fetch ./"sub proj" HEAD &&
799 git subtree add --prefix="sub dir" --squash FETCH_HEAD
801 test_create_commit "$test_count" "sub dir"/main-sub1 &&
802 test_create_commit "$test_count" main2 &&
803 test_create_commit "$test_count/sub proj" sub2 &&
804 test_create_commit "$test_count" "sub dir"/main-sub2 &&
807 git subtree pull --prefix="sub dir" --squash ./"sub proj" HEAD &&
808 MAIN=$(git rev-parse --verify HEAD) &&
809 SUB=$(git -C "sub proj" rev-parse --verify HEAD) &&
811 SPLIT=$(git subtree split --prefix="sub dir" --annotate="*") &&
812 git subtree push --prefix="sub dir" --annotate="*" --rejoin --squash ./"sub proj" from-mainline &&
814 test_must_fail git merge-base --is-ancestor $SUB HEAD &&
815 test_must_fail git merge-base --is-ancestor $SPLIT HEAD &&
816 git rev-list HEAD ^$MAIN >commit-list &&
817 test_line_count = 2 commit-list &&
818 test "$(git rev-parse --verify HEAD:)" = "$(git rev-parse --verify $MAIN:)" &&
819 test "$(git rev-parse --verify HEAD:"sub dir")" = "$(git rev-parse --verify $SPLIT:)" &&
820 test "$(git rev-parse --verify HEAD^1)" = $MAIN &&
821 test "$(git rev-parse --verify HEAD^2)" != $SPLIT &&
822 test "$(git rev-parse --verify HEAD^2:)" = "$(git rev-parse --verify $SPLIT:)" &&
823 test "$(last_commit_subject)" = "Split '\''sub dir/'\'' into commit '\''$SPLIT'\''" &&
824 test "$SPLIT" = "$(git -C "sub proj" rev-parse --verify refs/heads/from-mainline)"
828 test_expect_success
'push "sub dir"/ with --branch' '
829 subtree_test_create_repo "$test_count" &&
830 subtree_test_create_repo "$test_count/sub proj" &&
831 test_create_commit "$test_count" main1 &&
832 test_create_commit "$test_count/sub proj" sub1 &&
835 git fetch ./"sub proj" HEAD &&
836 git subtree add --prefix="sub dir" FETCH_HEAD
838 test_create_commit "$test_count" "sub dir"/main-sub1 &&
839 test_create_commit "$test_count" main2 &&
840 test_create_commit "$test_count/sub proj" sub2 &&
841 test_create_commit "$test_count" "sub dir"/main-sub2 &&
844 git fetch ./"sub proj" HEAD &&
845 git subtree merge --prefix="sub dir" FETCH_HEAD &&
846 split_hash=$(git subtree split --prefix="sub dir" --annotate="*") &&
847 git subtree push --prefix="sub dir" --annotate="*" --branch subproj-br ./"sub proj" from-mainline &&
848 test "$(git rev-parse subproj-br)" = "$split_hash" &&
849 test "$split_hash" = "$(git -C "sub proj" rev-parse --verify refs/heads/from-mainline)"
853 test_expect_success
'check hash of push' '
854 subtree_test_create_repo "$test_count" &&
855 subtree_test_create_repo "$test_count/sub proj" &&
856 test_create_commit "$test_count" main1 &&
857 test_create_commit "$test_count/sub proj" sub1 &&
860 git fetch ./"sub proj" HEAD &&
861 git subtree add --prefix="sub dir" FETCH_HEAD
863 test_create_commit "$test_count" "sub dir"/main-sub1 &&
864 test_create_commit "$test_count" main2 &&
865 test_create_commit "$test_count/sub proj" sub2 &&
866 test_create_commit "$test_count" "sub dir"/main-sub2 &&
869 git fetch ./"sub proj" HEAD &&
870 git subtree merge --prefix="sub dir" FETCH_HEAD &&
871 split_hash=$(git subtree split --prefix="sub dir" --annotate="*") &&
872 git subtree push --prefix="sub dir" --annotate="*" --branch subproj-br ./"sub proj" from-mainline &&
873 test "$(git rev-parse subproj-br)" = "$split_hash" &&
874 # Check hash of split
875 new_hash=$(git rev-parse subproj-br^2) &&
878 subdir_hash=$(git rev-parse HEAD) &&
879 test "$new_hash" = "$subdir_hash"
881 test "$split_hash" = "$(git -C "sub proj" rev-parse --verify refs/heads/from-mainline)"
885 test_expect_success
'push "sub dir"/ with --branch for an existing branch' '
886 subtree_test_create_repo "$test_count" &&
887 subtree_test_create_repo "$test_count/sub proj" &&
888 test_create_commit "$test_count" main1 &&
889 test_create_commit "$test_count/sub proj" sub1 &&
892 git fetch ./"sub proj" HEAD &&
893 git branch subproj-br FETCH_HEAD &&
894 git subtree add --prefix="sub dir" FETCH_HEAD
896 test_create_commit "$test_count" "sub dir"/main-sub1 &&
897 test_create_commit "$test_count" main2 &&
898 test_create_commit "$test_count/sub proj" sub2 &&
899 test_create_commit "$test_count" "sub dir"/main-sub2 &&
902 git fetch ./"sub proj" HEAD &&
903 git subtree merge --prefix="sub dir" FETCH_HEAD &&
904 split_hash=$(git subtree split --prefix="sub dir" --annotate="*") &&
905 git subtree push --prefix="sub dir" --annotate="*" --branch subproj-br ./"sub proj" from-mainline &&
906 test "$(git rev-parse subproj-br)" = "$split_hash" &&
907 test "$split_hash" = "$(git -C "sub proj" rev-parse --verify refs/heads/from-mainline)"
911 test_expect_success
'push "sub dir"/ with --branch for an incompatible branch' '
912 subtree_test_create_repo "$test_count" &&
913 subtree_test_create_repo "$test_count/sub proj" &&
914 test_create_commit "$test_count" main1 &&
915 test_create_commit "$test_count/sub proj" sub1 &&
918 git branch init HEAD &&
919 git fetch ./"sub proj" HEAD &&
920 git subtree add --prefix="sub dir" FETCH_HEAD
922 test_create_commit "$test_count" "sub dir"/main-sub1 &&
923 test_create_commit "$test_count" main2 &&
924 test_create_commit "$test_count/sub proj" sub2 &&
925 test_create_commit "$test_count" "sub dir"/main-sub2 &&
928 git fetch ./"sub proj" HEAD &&
929 git subtree merge --prefix="sub dir" FETCH_HEAD &&
930 test_must_fail git subtree push --prefix="sub dir" --branch init "./sub proj" from-mainline
934 test_expect_success
'push "sub dir"/ with a local rev' '
935 subtree_test_create_repo "$test_count" &&
936 subtree_test_create_repo "$test_count/sub proj" &&
937 test_create_commit "$test_count" main1 &&
938 test_create_commit "$test_count/sub proj" sub1 &&
941 git fetch ./"sub proj" HEAD &&
942 git subtree add --prefix="sub dir" FETCH_HEAD
944 test_create_commit "$test_count" "sub dir"/main-sub1 &&
945 test_create_commit "$test_count" "sub dir"/main-sub2 &&
948 bad_tree=$(git rev-parse --verify HEAD:"sub dir") &&
949 good_tree=$(git rev-parse --verify HEAD^:"sub dir") &&
950 git subtree push --prefix="sub dir" --annotate="*" ./"sub proj" HEAD^:from-mainline &&
951 split_tree=$(git -C "sub proj" rev-parse --verify refs/heads/from-mainline:) &&
952 test "$split_tree" = "$good_tree"
960 test_expect_success
'make sure exactly the right set of files ends up in the subproj' '
961 subtree_test_create_repo "$test_count" &&
962 subtree_test_create_repo "$test_count/sub proj" &&
963 test_create_commit "$test_count" main1 &&
964 test_create_commit "$test_count/sub proj" sub1 &&
967 git fetch ./"sub proj" HEAD &&
968 git subtree add --prefix="sub dir" FETCH_HEAD
970 test_create_commit "$test_count" "sub dir"/main-sub1 &&
971 test_create_commit "$test_count" main2 &&
972 test_create_commit "$test_count/sub proj" sub2 &&
973 test_create_commit "$test_count" "sub dir"/main-sub2 &&
976 git fetch ./"sub proj" HEAD &&
977 git subtree merge --prefix="sub dir" FETCH_HEAD &&
978 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
980 test_create_commit "$test_count/sub proj" sub3 &&
981 test_create_commit "$test_count" "sub dir"/main-sub3 &&
983 cd "$test_count/sub proj" &&
984 git fetch .. subproj-br &&
987 test_create_commit "$test_count/sub proj" sub4 &&
990 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
992 test_create_commit "$test_count" "sub dir"/main-sub4 &&
995 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
998 cd "$test_count/sub proj" &&
999 git fetch .. subproj-br &&
1000 git merge FETCH_HEAD &&
1002 test_write_lines main-sub1 main-sub2 main-sub3 main-sub4 \
1003 sub1 sub2 sub3 sub4 >expect &&
1004 git ls-files >actual &&
1005 test_cmp expect actual
1009 test_expect_success
'make sure the subproj *only* contains commits that affect the "sub dir"' '
1010 subtree_test_create_repo "$test_count" &&
1011 subtree_test_create_repo "$test_count/sub proj" &&
1012 test_create_commit "$test_count" main1 &&
1013 test_create_commit "$test_count/sub proj" sub1 &&
1016 git fetch ./"sub proj" HEAD &&
1017 git subtree add --prefix="sub dir" FETCH_HEAD
1019 test_create_commit "$test_count" "sub dir"/main-sub1 &&
1020 test_create_commit "$test_count" main2 &&
1021 test_create_commit "$test_count/sub proj" sub2 &&
1022 test_create_commit "$test_count" "sub dir"/main-sub2 &&
1025 git fetch ./"sub proj" HEAD &&
1026 git subtree merge --prefix="sub dir" FETCH_HEAD &&
1027 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
1029 test_create_commit "$test_count/sub proj" sub3 &&
1030 test_create_commit "$test_count" "sub dir"/main-sub3 &&
1032 cd "$test_count/sub proj" &&
1033 git fetch .. subproj-br &&
1034 git merge FETCH_HEAD
1036 test_create_commit "$test_count/sub proj" sub4 &&
1039 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
1041 test_create_commit "$test_count" "sub dir"/main-sub4 &&
1044 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
1047 cd "$test_count/sub proj" &&
1048 git fetch .. subproj-br &&
1049 git merge FETCH_HEAD &&
1051 test_write_lines main-sub1 main-sub2 main-sub3 main-sub4 \
1052 sub1 sub2 sub3 sub4 >expect &&
1053 git log --name-only --pretty=format:"" >log &&
1054 sort <log | sed "/^\$/ d" >actual &&
1055 test_cmp expect actual
1059 test_expect_success
'make sure exactly the right set of files ends up in the mainline' '
1060 subtree_test_create_repo "$test_count" &&
1061 subtree_test_create_repo "$test_count/sub proj" &&
1062 test_create_commit "$test_count" main1 &&
1063 test_create_commit "$test_count/sub proj" sub1 &&
1066 git fetch ./"sub proj" HEAD &&
1067 git subtree add --prefix="sub dir" FETCH_HEAD
1069 test_create_commit "$test_count" "sub dir"/main-sub1 &&
1070 test_create_commit "$test_count" main2 &&
1071 test_create_commit "$test_count/sub proj" sub2 &&
1072 test_create_commit "$test_count" "sub dir"/main-sub2 &&
1075 git fetch ./"sub proj" HEAD &&
1076 git subtree merge --prefix="sub dir" FETCH_HEAD &&
1077 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
1079 test_create_commit "$test_count/sub proj" sub3 &&
1080 test_create_commit "$test_count" "sub dir"/main-sub3 &&
1082 cd "$test_count/sub proj" &&
1083 git fetch .. subproj-br &&
1084 git merge FETCH_HEAD
1086 test_create_commit "$test_count/sub proj" sub4 &&
1089 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
1091 test_create_commit "$test_count" "sub dir"/main-sub4 &&
1094 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
1097 cd "$test_count/sub proj" &&
1098 git fetch .. subproj-br &&
1099 git merge FETCH_HEAD
1103 git subtree pull --prefix="sub dir" ./"sub proj" HEAD &&
1105 test_write_lines main1 main2 >chkm &&
1106 test_write_lines main-sub1 main-sub2 main-sub3 main-sub4 >chkms &&
1107 sed "s,^,sub dir/," chkms >chkms_sub &&
1108 test_write_lines sub1 sub2 sub3 sub4 >chks &&
1109 sed "s,^,sub dir/," chks >chks_sub &&
1111 cat chkm chkms_sub chks_sub >expect &&
1112 git ls-files >actual &&
1113 test_cmp expect actual
1117 test_expect_success
'make sure each filename changed exactly once in the entire history' '
1118 subtree_test_create_repo "$test_count" &&
1119 subtree_test_create_repo "$test_count/sub proj" &&
1120 test_create_commit "$test_count" main1 &&
1121 test_create_commit "$test_count/sub proj" sub1 &&
1124 git config log.date relative &&
1125 git fetch ./"sub proj" HEAD &&
1126 git subtree add --prefix="sub dir" FETCH_HEAD
1128 test_create_commit "$test_count" "sub dir"/main-sub1 &&
1129 test_create_commit "$test_count" main2 &&
1130 test_create_commit "$test_count/sub proj" sub2 &&
1131 test_create_commit "$test_count" "sub dir"/main-sub2 &&
1134 git fetch ./"sub proj" HEAD &&
1135 git subtree merge --prefix="sub dir" FETCH_HEAD &&
1136 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
1138 test_create_commit "$test_count/sub proj" sub3 &&
1139 test_create_commit "$test_count" "sub dir"/main-sub3 &&
1141 cd "$test_count/sub proj" &&
1142 git fetch .. subproj-br &&
1143 git merge FETCH_HEAD
1145 test_create_commit "$test_count/sub proj" sub4 &&
1148 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
1150 test_create_commit "$test_count" "sub dir"/main-sub4 &&
1153 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
1156 cd "$test_count/sub proj" &&
1157 git fetch .. subproj-br &&
1158 git merge FETCH_HEAD
1162 git subtree pull --prefix="sub dir" ./"sub proj" HEAD &&
1164 test_write_lines main1 main2 >chkm &&
1165 test_write_lines sub1 sub2 sub3 sub4 >chks &&
1166 test_write_lines main-sub1 main-sub2 main-sub3 main-sub4 >chkms &&
1167 sed "s,^,sub dir/," chkms >chkms_sub &&
1169 # main-sub?? and /"sub dir"/main-sub?? both change, because those are the
1170 # changes that were split into their own history. And "sub dir"/sub?? never
1171 # change, since they were *only* changed in the subtree branch.
1172 git log --name-only --pretty=format:"" >log &&
1173 sort <log >sorted-log &&
1174 sed "/^$/ d" sorted-log >actual &&
1176 cat chkms chkm chks chkms_sub >expect-unsorted &&
1177 sort expect-unsorted >expect &&
1178 test_cmp expect actual
1182 test_expect_success
'make sure the --rejoin commits never make it into subproj' '
1183 subtree_test_create_repo "$test_count" &&
1184 subtree_test_create_repo "$test_count/sub proj" &&
1185 test_create_commit "$test_count" main1 &&
1186 test_create_commit "$test_count/sub proj" sub1 &&
1189 git fetch ./"sub proj" HEAD &&
1190 git subtree add --prefix="sub dir" FETCH_HEAD
1192 test_create_commit "$test_count" "sub dir"/main-sub1 &&
1193 test_create_commit "$test_count" main2 &&
1194 test_create_commit "$test_count/sub proj" sub2 &&
1195 test_create_commit "$test_count" "sub dir"/main-sub2 &&
1198 git fetch ./"sub proj" HEAD &&
1199 git subtree merge --prefix="sub dir" FETCH_HEAD &&
1200 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
1202 test_create_commit "$test_count/sub proj" sub3 &&
1203 test_create_commit "$test_count" "sub dir"/main-sub3 &&
1205 cd "$test_count/sub proj" &&
1206 git fetch .. subproj-br &&
1207 git merge FETCH_HEAD
1209 test_create_commit "$test_count/sub proj" sub4 &&
1212 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
1214 test_create_commit "$test_count" "sub dir"/main-sub4 &&
1217 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
1220 cd "$test_count/sub proj" &&
1221 git fetch .. subproj-br &&
1222 git merge FETCH_HEAD
1226 git subtree pull --prefix="sub dir" ./"sub proj" HEAD &&
1227 test "$(git log --pretty=format:"%s" HEAD^2 | grep -i split)" = ""
1231 test_expect_success
'make sure no "git subtree" tagged commits make it into subproj' '
1232 subtree_test_create_repo "$test_count" &&
1233 subtree_test_create_repo "$test_count/sub proj" &&
1234 test_create_commit "$test_count" main1 &&
1235 test_create_commit "$test_count/sub proj" sub1 &&
1238 git fetch ./"sub proj" HEAD &&
1239 git subtree add --prefix="sub dir" FETCH_HEAD
1241 test_create_commit "$test_count" "sub dir"/main-sub1 &&
1242 test_create_commit "$test_count" main2 &&
1243 test_create_commit "$test_count/sub proj" sub2 &&
1244 test_create_commit "$test_count" "sub dir"/main-sub2 &&
1247 git fetch ./"sub proj" HEAD &&
1248 git subtree merge --prefix="sub dir" FETCH_HEAD &&
1249 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
1251 test_create_commit "$test_count/sub proj" sub3 &&
1252 test_create_commit "$test_count" "sub dir"/main-sub3 &&
1254 cd "$test_count/sub proj" &&
1255 git fetch .. subproj-br &&
1256 git merge FETCH_HEAD
1258 test_create_commit "$test_count/sub proj" sub4 &&
1261 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
1263 test_create_commit "$test_count" "sub dir"/main-sub4 &&
1266 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
1269 cd "$test_count/sub proj" &&
1270 git fetch .. subproj-br &&
1271 git merge FETCH_HEAD
1275 git subtree pull --prefix="sub dir" ./"sub proj" HEAD &&
1277 # They are meaningless to subproj since one side of the merge refers to the mainline
1278 test "$(git log --pretty=format:"%s%n%b" HEAD^2 | grep "git-subtree.*:")" = ""
1283 # A new set of tests
1286 test_expect_success
'make sure "git subtree split" find the correct parent' '
1287 subtree_test_create_repo "$test_count" &&
1288 subtree_test_create_repo "$test_count/sub proj" &&
1289 test_create_commit "$test_count" main1 &&
1290 test_create_commit "$test_count/sub proj" sub1 &&
1293 git fetch ./"sub proj" HEAD &&
1294 git subtree add --prefix="sub dir" FETCH_HEAD
1296 test_create_commit "$test_count/sub proj" sub2 &&
1299 git fetch ./"sub proj" HEAD &&
1300 git branch subproj-ref FETCH_HEAD &&
1301 git subtree merge --prefix="sub dir" FETCH_HEAD
1303 test_create_commit "$test_count" "sub dir"/main-sub1 &&
1306 git subtree split --prefix="sub dir" --branch subproj-br &&
1308 # at this point, the new commit parent should be subproj-ref, if it is
1309 # not, something went wrong (the "newparent" of "HEAD~" commit should
1310 # have been sub2, but it was not, because its cache was not set to
1312 test "$(git log --pretty=format:%P -1 subproj-br)" = "$(git rev-parse subproj-ref)"
1316 test_expect_success
'split a new subtree without --onto option' '
1317 subtree_test_create_repo "$test_count" &&
1318 subtree_test_create_repo "$test_count/sub proj" &&
1319 test_create_commit "$test_count" main1 &&
1320 test_create_commit "$test_count/sub proj" sub1 &&
1323 git fetch ./"sub proj" HEAD &&
1324 git subtree add --prefix="sub dir" FETCH_HEAD
1326 test_create_commit "$test_count/sub proj" sub2 &&
1329 git fetch ./"sub proj" HEAD &&
1330 git subtree merge --prefix="sub dir" FETCH_HEAD
1332 test_create_commit "$test_count" "sub dir"/main-sub1 &&
1335 git subtree split --prefix="sub dir" --branch subproj-br
1337 mkdir "$test_count"/"sub dir2" &&
1338 test_create_commit "$test_count" "sub dir2"/main-sub2 &&
1342 # also test that we still can split out an entirely new subtree
1343 # if the parent of the first commit in the tree is not empty,
1344 # then the new subtree has accidentally been attached to something
1345 git subtree split --prefix="sub dir2" --branch subproj2-br &&
1346 test "$(git log --pretty=format:%P -1 subproj2-br)" = ""
1350 test_expect_success
'verify one file change per commit' '
1351 subtree_test_create_repo "$test_count" &&
1352 subtree_test_create_repo "$test_count/sub proj" &&
1353 test_create_commit "$test_count" main1 &&
1354 test_create_commit "$test_count/sub proj" sub1 &&
1357 git fetch ./"sub proj" HEAD &&
1358 git branch sub1 FETCH_HEAD &&
1359 git subtree add --prefix="sub dir" sub1
1361 test_create_commit "$test_count/sub proj" sub2 &&
1364 git fetch ./"sub proj" HEAD &&
1365 git subtree merge --prefix="sub dir" FETCH_HEAD
1367 test_create_commit "$test_count" "sub dir"/main-sub1 &&
1370 git subtree split --prefix="sub dir" --branch subproj-br
1372 mkdir "$test_count"/"sub dir2" &&
1373 test_create_commit "$test_count" "sub dir2"/main-sub2 &&
1376 git subtree split --prefix="sub dir2" --branch subproj2-br &&
1378 git log --format="%H" >commit-list &&
1381 git log -n1 --format="" --name-only "$commit" >file-list &&
1382 test_line_count -le 1 file-list || return 1
1387 test_expect_success
'push split to subproj' '
1388 subtree_test_create_repo "$test_count" &&
1389 subtree_test_create_repo "$test_count/sub proj" &&
1390 test_create_commit "$test_count" main1 &&
1391 test_create_commit "$test_count/sub proj" sub1 &&
1394 git fetch ./"sub proj" HEAD &&
1395 git subtree add --prefix="sub dir" FETCH_HEAD
1397 test_create_commit "$test_count" "sub dir"/main-sub1 &&
1398 test_create_commit "$test_count" main2 &&
1399 test_create_commit "$test_count/sub proj" sub2 &&
1400 test_create_commit "$test_count" "sub dir"/main-sub2 &&
1402 cd $test_count/"sub proj" &&
1403 git branch sub-branch-1 &&
1405 git fetch ./"sub proj" HEAD &&
1406 git subtree merge --prefix="sub dir" FETCH_HEAD
1408 test_create_commit "$test_count" "sub dir"/main-sub3 &&
1411 git subtree push ./"sub proj" --prefix "sub dir" sub-branch-1 &&
1413 git checkout sub-branch-1 &&
1414 test "$(last_commit_subject)" = "sub dir/main-sub3"
1419 # This test covers 2 cases in subtree split copy_or_skip code
1420 # 1) Merges where one parent is a superset of the changes of the other
1421 # parent regarding changes to the subtree, in this case the merge
1422 # commit should be copied
1423 # 2) Merges where only one parent operate on the subtree, and the merge
1424 # commit should be skipped
1426 # (1) is checked by ensuring subtree_tip is a descendent of subtree_branch
1427 # (2) should have a check added (not_a_subtree_change shouldn't be present
1428 # on the produced subtree)
1430 # Other related cases which are not tested (or currently handled correctly)
1431 # - Case (1) where there are more than 2 parents, it will sometimes correctly copy
1432 # the merge, and sometimes not
1433 # - Merge commit where both parents have same tree as the merge, currently
1434 # will always be skipped, even if they reached that state via different
1438 test_expect_success
'subtree descendant check' '
1439 subtree_test_create_repo "$test_count" &&
1440 defaultBranch=$(sed "s,ref: refs/heads/,," "$test_count/.git/HEAD") &&
1441 test_create_commit "$test_count" folder_subtree/a &&
1446 test_create_commit "$test_count" folder_subtree/0 &&
1447 test_create_commit "$test_count" folder_subtree/b &&
1448 cherry=$(cd "$test_count"; git rev-parse HEAD) &&
1453 test_create_commit "$test_count" commit_on_branch &&
1456 git cherry-pick $cherry &&
1457 git checkout $defaultBranch &&
1458 git merge -m "merge should be kept on subtree" branch &&
1459 git branch no_subtree_work_branch
1461 test_create_commit "$test_count" folder_subtree/d &&
1464 git checkout no_subtree_work_branch
1466 test_create_commit "$test_count" not_a_subtree_change &&
1469 git checkout $defaultBranch &&
1470 git merge -m "merge should be skipped on subtree" no_subtree_work_branch &&
1472 git subtree split --prefix folder_subtree/ --branch subtree_tip $defaultBranch &&
1473 git subtree split --prefix folder_subtree/ --branch subtree_branch branch &&
1474 test $(git rev-list --count subtree_tip..subtree_branch) = 0