]>
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 # Upon 'git subtree add|merge --squash' of an annotated tag,
47 # pre-2.32.0 versions of 'git subtree' would write the hash of the tag
48 # (sub1 below), instead of the commit (sub1^{commit}) in the
49 # "git-subtree-split" trailer.
50 # We immitate this behaviour below using a replace ref.
51 # This function creates 3 repositories:
53 # - $1-sub (added as subtree "sub" in $1)
54 # - $1-clone (clone of $1)
55 test_create_pre2_32_repo
() {
56 subtree_test_create_repo
"$1" &&
57 subtree_test_create_repo
"$1-sub" &&
58 test_commit
-C "$1" main1
&&
59 test_commit
-C "$1-sub" --annotate sub1
&&
60 git
-C "$1" subtree add
--prefix="sub" --squash "../$1-sub" sub1
&&
61 tag
=$
(git
-C "$1" rev-parse FETCH_HEAD
) &&
62 commit
=$
(git
-C "$1" rev-parse FETCH_HEAD^
{commit
}) &&
63 git
-C "$1" log
-1 --format=%B HEAD^
2 >msg
&&
64 test_commit
-C "$1-sub" --annotate sub2
&&
65 git clone
--no-local "$1" "$1-clone" &&
66 new_commit
=$
(cat msg |
sed -e "s/$commit/$tag/" | git
-C "$1-clone" commit-tree HEAD^
2^
{tree
}) &&
67 git
-C "$1-clone" replace HEAD^
2 $new_commit
70 test_expect_success
'shows short help text for -h' '
71 test_expect_code 129 git subtree -h >out 2>err &&
72 test_must_be_empty err &&
73 grep -e "^ *or: git subtree pull" out &&
74 grep -F -e "--[no-]annotate" out
78 # Tests for 'git subtree add'
81 test_expect_success
'no merge from non-existent subtree' '
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_must_fail git subtree merge --prefix="sub dir" FETCH_HEAD
93 test_expect_success
'no pull from non-existent subtree' '
94 subtree_test_create_repo "$test_count" &&
95 subtree_test_create_repo "$test_count/sub proj" &&
96 test_create_commit "$test_count" main1 &&
97 test_create_commit "$test_count/sub proj" sub1 &&
100 git fetch ./"sub proj" HEAD &&
101 test_must_fail git subtree pull --prefix="sub dir" ./"sub proj" HEAD
105 test_expect_success
'add rejects flags for split' '
106 subtree_test_create_repo "$test_count" &&
107 subtree_test_create_repo "$test_count/sub proj" &&
108 test_create_commit "$test_count" main1 &&
109 test_create_commit "$test_count/sub proj" sub1 &&
112 git fetch ./"sub proj" HEAD &&
113 test_wrong_flag git subtree add --prefix="sub dir" --annotate=foo FETCH_HEAD &&
114 test_wrong_flag git subtree add --prefix="sub dir" --branch=foo FETCH_HEAD &&
115 test_wrong_flag git subtree add --prefix="sub dir" --ignore-joins FETCH_HEAD &&
116 test_wrong_flag git subtree add --prefix="sub dir" --onto=foo FETCH_HEAD &&
117 test_wrong_flag git subtree add --prefix="sub dir" --rejoin FETCH_HEAD
121 test_expect_success
'add subproj as subtree into sub dir/ with --prefix' '
122 subtree_test_create_repo "$test_count" &&
123 subtree_test_create_repo "$test_count/sub proj" &&
124 test_create_commit "$test_count" main1 &&
125 test_create_commit "$test_count/sub proj" sub1 &&
128 git fetch ./"sub proj" HEAD &&
129 git subtree add --prefix="sub dir" FETCH_HEAD &&
130 test "$(last_commit_subject)" = "Add '\''sub dir/'\'' from commit '\''$(git rev-parse FETCH_HEAD)'\''"
134 test_expect_success
'add subproj as subtree into sub dir/ with --prefix and --message' '
135 subtree_test_create_repo "$test_count" &&
136 subtree_test_create_repo "$test_count/sub proj" &&
137 test_create_commit "$test_count" main1 &&
138 test_create_commit "$test_count/sub proj" sub1 &&
141 git fetch ./"sub proj" HEAD &&
142 git subtree add --prefix="sub dir" --message="Added subproject" FETCH_HEAD &&
143 test "$(last_commit_subject)" = "Added subproject"
147 test_expect_success
'add subproj as subtree into sub dir/ with --prefix as -P and --message as -m' '
148 subtree_test_create_repo "$test_count" &&
149 subtree_test_create_repo "$test_count/sub proj" &&
150 test_create_commit "$test_count" main1 &&
151 test_create_commit "$test_count/sub proj" sub1 &&
154 git fetch ./"sub proj" HEAD &&
155 git subtree add -P "sub dir" -m "Added subproject" FETCH_HEAD &&
156 test "$(last_commit_subject)" = "Added subproject"
160 test_expect_success
'add subproj as subtree into sub dir/ with --squash and --prefix and --message' '
161 subtree_test_create_repo "$test_count" &&
162 subtree_test_create_repo "$test_count/sub proj" &&
163 test_create_commit "$test_count" main1 &&
164 test_create_commit "$test_count/sub proj" sub1 &&
167 git fetch ./"sub proj" HEAD &&
168 git subtree add --prefix="sub dir" --message="Added subproject with squash" --squash FETCH_HEAD &&
169 test "$(last_commit_subject)" = "Added subproject with squash"
174 # Tests for 'git subtree merge'
177 test_expect_success
'merge rejects flags for split' '
178 subtree_test_create_repo "$test_count" &&
179 subtree_test_create_repo "$test_count/sub proj" &&
180 test_create_commit "$test_count" main1 &&
181 test_create_commit "$test_count/sub proj" sub1 &&
184 git fetch ./"sub proj" HEAD &&
185 git subtree add --prefix="sub dir" FETCH_HEAD
187 test_create_commit "$test_count/sub proj" sub2 &&
190 git fetch ./"sub proj" HEAD &&
191 test_wrong_flag git subtree merge --prefix="sub dir" --annotate=foo FETCH_HEAD &&
192 test_wrong_flag git subtree merge --prefix="sub dir" --branch=foo FETCH_HEAD &&
193 test_wrong_flag git subtree merge --prefix="sub dir" --ignore-joins FETCH_HEAD &&
194 test_wrong_flag git subtree merge --prefix="sub dir" --onto=foo FETCH_HEAD &&
195 test_wrong_flag git subtree merge --prefix="sub dir" --rejoin FETCH_HEAD
199 test_expect_success
'merge new subproj history into sub dir/ with --prefix' '
200 subtree_test_create_repo "$test_count" &&
201 subtree_test_create_repo "$test_count/sub proj" &&
202 test_create_commit "$test_count" main1 &&
203 test_create_commit "$test_count/sub proj" sub1 &&
206 git fetch ./"sub proj" HEAD &&
207 git subtree add --prefix="sub dir" FETCH_HEAD
209 test_create_commit "$test_count/sub proj" sub2 &&
212 git fetch ./"sub proj" HEAD &&
213 git subtree merge --prefix="sub dir" FETCH_HEAD &&
214 test "$(last_commit_subject)" = "Merge commit '\''$(git rev-parse FETCH_HEAD)'\''"
218 test_expect_success
'merge new subproj history into sub dir/ with --prefix and --message' '
219 subtree_test_create_repo "$test_count" &&
220 subtree_test_create_repo "$test_count/sub proj" &&
221 test_create_commit "$test_count" main1 &&
222 test_create_commit "$test_count/sub proj" sub1 &&
225 git fetch ./"sub proj" HEAD &&
226 git subtree add --prefix="sub dir" FETCH_HEAD
228 test_create_commit "$test_count/sub proj" sub2 &&
231 git fetch ./"sub proj" HEAD &&
232 git subtree merge --prefix="sub dir" --message="Merged changes from subproject" FETCH_HEAD &&
233 test "$(last_commit_subject)" = "Merged changes from subproject"
237 test_expect_success
'merge new subproj history into sub dir/ with --squash and --prefix and --message' '
238 subtree_test_create_repo "$test_count/sub proj" &&
239 subtree_test_create_repo "$test_count" &&
240 test_create_commit "$test_count" main1 &&
241 test_create_commit "$test_count/sub proj" sub1 &&
244 git fetch ./"sub proj" HEAD &&
245 git subtree add --prefix="sub dir" FETCH_HEAD
247 test_create_commit "$test_count/sub proj" sub2 &&
250 git fetch ./"sub proj" HEAD &&
251 git subtree merge --prefix="sub dir" --message="Merged changes from subproject using squash" --squash FETCH_HEAD &&
252 test "$(last_commit_subject)" = "Merged changes from subproject using squash"
256 test_expect_success
'merge the added subproj again, should do nothing' '
257 subtree_test_create_repo "$test_count" &&
258 subtree_test_create_repo "$test_count/sub proj" &&
259 test_create_commit "$test_count" main1 &&
260 test_create_commit "$test_count/sub proj" sub1 &&
263 git fetch ./"sub proj" HEAD &&
264 git subtree add --prefix="sub dir" FETCH_HEAD &&
265 # this shouldn not actually do anything, since FETCH_HEAD
266 # is already a parent
267 result=$(git merge -s ours -m "merge -s -ours" FETCH_HEAD) &&
268 test "${result}" = "Already up to date."
272 test_expect_success
'merge new subproj history into subdir/ with a slash appended to the argument of --prefix' '
273 subtree_test_create_repo "$test_count" &&
274 subtree_test_create_repo "$test_count/subproj" &&
275 test_create_commit "$test_count" main1 &&
276 test_create_commit "$test_count/subproj" sub1 &&
279 git fetch ./subproj HEAD &&
280 git subtree add --prefix=subdir/ FETCH_HEAD
282 test_create_commit "$test_count/subproj" sub2 &&
285 git fetch ./subproj HEAD &&
286 git subtree merge --prefix=subdir/ FETCH_HEAD &&
287 test "$(last_commit_subject)" = "Merge commit '\''$(git rev-parse FETCH_HEAD)'\''"
291 test_expect_success
'merge with --squash after annotated tag was added/merged with --squash pre-v2.32.0 ' '
292 test_create_pre2_32_repo "$test_count" &&
293 git -C "$test_count-clone" fetch "../$test_count-sub" sub2 &&
294 test_must_fail git -C "$test_count-clone" subtree merge --prefix="sub" --squash FETCH_HEAD &&
295 git -C "$test_count-clone" subtree merge --prefix="sub" --squash FETCH_HEAD "../$test_count-sub"
299 # Tests for 'git subtree split'
302 test_expect_success
'split requires option --prefix' '
303 subtree_test_create_repo "$test_count" &&
304 subtree_test_create_repo "$test_count/sub proj" &&
305 test_create_commit "$test_count" main1 &&
306 test_create_commit "$test_count/sub proj" sub1 &&
309 git fetch ./"sub proj" HEAD &&
310 git subtree add --prefix="sub dir" FETCH_HEAD &&
311 echo "fatal: you must provide the --prefix option." >expected &&
312 test_must_fail git subtree split >actual 2>&1 &&
313 test_debug "printf '"expected: "'" &&
314 test_debug "cat expected" &&
315 test_debug "printf '"actual: "'" &&
316 test_debug "cat actual" &&
317 test_cmp expected actual
321 test_expect_success
'split requires path given by option --prefix must exist' '
322 subtree_test_create_repo "$test_count" &&
323 subtree_test_create_repo "$test_count/sub proj" &&
324 test_create_commit "$test_count" main1 &&
325 test_create_commit "$test_count/sub proj" sub1 &&
328 git fetch ./"sub proj" HEAD &&
329 git subtree add --prefix="sub dir" FETCH_HEAD &&
330 echo "fatal: '\''non-existent-directory'\'' does not exist; use '\''git subtree add'\''" >expected &&
331 test_must_fail git subtree split --prefix=non-existent-directory >actual 2>&1 &&
332 test_debug "printf '"expected: "'" &&
333 test_debug "cat expected" &&
334 test_debug "printf '"actual: "'" &&
335 test_debug "cat actual" &&
336 test_cmp expected actual
340 test_expect_success
'split rejects flags for add' '
341 subtree_test_create_repo "$test_count" &&
342 subtree_test_create_repo "$test_count/sub proj" &&
343 test_create_commit "$test_count" main1 &&
344 test_create_commit "$test_count/sub proj" sub1 &&
347 git fetch ./"sub proj" HEAD &&
348 git subtree add --prefix="sub dir" FETCH_HEAD
350 test_create_commit "$test_count" "sub dir"/main-sub1 &&
351 test_create_commit "$test_count" main2 &&
352 test_create_commit "$test_count/sub proj" sub2 &&
353 test_create_commit "$test_count" "sub dir"/main-sub2 &&
356 git fetch ./"sub proj" HEAD &&
357 git subtree merge --prefix="sub dir" FETCH_HEAD &&
358 split_hash=$(git subtree split --prefix="sub dir" --annotate="*") &&
359 test_wrong_flag git subtree split --prefix="sub dir" --squash &&
360 test_wrong_flag git subtree split --prefix="sub dir" --message=foo
364 test_expect_success
'split sub dir/ with --rejoin' '
365 subtree_test_create_repo "$test_count" &&
366 subtree_test_create_repo "$test_count/sub proj" &&
367 test_create_commit "$test_count" main1 &&
368 test_create_commit "$test_count/sub proj" sub1 &&
371 git fetch ./"sub proj" HEAD &&
372 git subtree add --prefix="sub dir" FETCH_HEAD
374 test_create_commit "$test_count" "sub dir"/main-sub1 &&
375 test_create_commit "$test_count" main2 &&
376 test_create_commit "$test_count/sub proj" sub2 &&
377 test_create_commit "$test_count" "sub dir"/main-sub2 &&
380 git fetch ./"sub proj" HEAD &&
381 git subtree merge --prefix="sub dir" FETCH_HEAD &&
382 split_hash=$(git subtree split --prefix="sub dir" --annotate="*") &&
383 git subtree split --prefix="sub dir" --annotate="*" --rejoin &&
384 test "$(last_commit_subject)" = "Split '\''sub dir/'\'' into commit '\''$split_hash'\''"
388 test_expect_success
'split sub dir/ with --rejoin from scratch' '
389 subtree_test_create_repo "$test_count" &&
390 test_create_commit "$test_count" main1 &&
394 echo file >"sub dir"/file &&
395 git add "sub dir/file" &&
396 git commit -m"sub dir file" &&
397 split_hash=$(git subtree split --prefix="sub dir" --rejoin) &&
398 git subtree split --prefix="sub dir" --rejoin &&
399 test "$(last_commit_subject)" = "Split '\''sub dir/'\'' into commit '\''$split_hash'\''"
403 test_expect_success
'split sub dir/ with --rejoin and --message' '
404 subtree_test_create_repo "$test_count" &&
405 subtree_test_create_repo "$test_count/sub proj" &&
406 test_create_commit "$test_count" main1 &&
407 test_create_commit "$test_count/sub proj" sub1 &&
410 git fetch ./"sub proj" HEAD &&
411 git subtree add --prefix="sub dir" FETCH_HEAD
413 test_create_commit "$test_count" "sub dir"/main-sub1 &&
414 test_create_commit "$test_count" main2 &&
415 test_create_commit "$test_count/sub proj" sub2 &&
416 test_create_commit "$test_count" "sub dir"/main-sub2 &&
419 git fetch ./"sub proj" HEAD &&
420 git subtree merge --prefix="sub dir" FETCH_HEAD &&
421 git subtree split --prefix="sub dir" --message="Split & rejoin" --annotate="*" --rejoin &&
422 test "$(last_commit_subject)" = "Split & rejoin"
426 test_expect_success
'split "sub dir"/ with --rejoin and --squash' '
427 subtree_test_create_repo "$test_count" &&
428 subtree_test_create_repo "$test_count/sub proj" &&
429 test_create_commit "$test_count" main1 &&
430 test_create_commit "$test_count/sub proj" sub1 &&
433 git fetch ./"sub proj" HEAD &&
434 git subtree add --prefix="sub dir" --squash FETCH_HEAD
436 test_create_commit "$test_count" "sub dir"/main-sub1 &&
437 test_create_commit "$test_count" main2 &&
438 test_create_commit "$test_count/sub proj" sub2 &&
439 test_create_commit "$test_count" "sub dir"/main-sub2 &&
442 git subtree pull --prefix="sub dir" --squash ./"sub proj" HEAD &&
443 MAIN=$(git rev-parse --verify HEAD) &&
444 SUB=$(git -C "sub proj" rev-parse --verify HEAD) &&
446 SPLIT=$(git subtree split --prefix="sub dir" --annotate="*" --rejoin --squash) &&
448 test_must_fail git merge-base --is-ancestor $SUB HEAD &&
449 test_must_fail git merge-base --is-ancestor $SPLIT HEAD &&
450 git rev-list HEAD ^$MAIN >commit-list &&
451 test_line_count = 2 commit-list &&
452 test "$(git rev-parse --verify HEAD:)" = "$(git rev-parse --verify $MAIN:)" &&
453 test "$(git rev-parse --verify HEAD:"sub dir")" = "$(git rev-parse --verify $SPLIT:)" &&
454 test "$(git rev-parse --verify HEAD^1)" = $MAIN &&
455 test "$(git rev-parse --verify HEAD^2)" != $SPLIT &&
456 test "$(git rev-parse --verify HEAD^2:)" = "$(git rev-parse --verify $SPLIT:)" &&
457 test "$(last_commit_subject)" = "Split '\''sub dir/'\'' into commit '\''$SPLIT'\''"
461 test_expect_success
'split then pull "sub dir"/ with --rejoin and --squash' '
463 subtree_test_create_repo "$test_count" &&
464 subtree_test_create_repo "$test_count/sub proj" &&
465 test_create_commit "$test_count" main1 &&
466 test_create_commit "$test_count/sub proj" sub1 &&
467 git -C "$test_count" subtree --prefix="sub dir" add --squash ./"sub proj" HEAD &&
469 # 2. commit from parent
470 test_create_commit "$test_count" "sub dir"/main-sub1 &&
472 # 3. "split --rejoin --squash"
473 git -C "$test_count" subtree --prefix="sub dir" split --rejoin --squash &&
476 test_create_commit "$test_count/sub proj" sub2 &&
477 git -C "$test_count" subtree -d --prefix="sub dir" pull --squash ./"sub proj" HEAD &&
479 test_must_fail git merge-base HEAD FETCH_HEAD
482 test_expect_success
'split "sub dir"/ with --branch' '
483 subtree_test_create_repo "$test_count" &&
484 subtree_test_create_repo "$test_count/sub proj" &&
485 test_create_commit "$test_count" main1 &&
486 test_create_commit "$test_count/sub proj" sub1 &&
489 git fetch ./"sub proj" HEAD &&
490 git subtree add --prefix="sub dir" FETCH_HEAD
492 test_create_commit "$test_count" "sub dir"/main-sub1 &&
493 test_create_commit "$test_count" main2 &&
494 test_create_commit "$test_count/sub proj" sub2 &&
495 test_create_commit "$test_count" "sub dir"/main-sub2 &&
498 git fetch ./"sub proj" HEAD &&
499 git subtree merge --prefix="sub dir" FETCH_HEAD &&
500 split_hash=$(git subtree split --prefix="sub dir" --annotate="*") &&
501 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br &&
502 test "$(git rev-parse subproj-br)" = "$split_hash"
506 test_expect_success
'check hash of split' '
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 subtree add --prefix="sub dir" FETCH_HEAD
516 test_create_commit "$test_count" "sub dir"/main-sub1 &&
517 test_create_commit "$test_count" main2 &&
518 test_create_commit "$test_count/sub proj" sub2 &&
519 test_create_commit "$test_count" "sub dir"/main-sub2 &&
522 git fetch ./"sub proj" HEAD &&
523 git subtree merge --prefix="sub dir" FETCH_HEAD &&
524 split_hash=$(git subtree split --prefix="sub dir" --annotate="*") &&
525 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br &&
526 test "$(git rev-parse subproj-br)" = "$split_hash" &&
527 # Check hash of split
528 new_hash=$(git rev-parse subproj-br^2) &&
531 subdir_hash=$(git rev-parse HEAD) &&
532 test "$new_hash" = "$subdir_hash"
537 test_expect_success
'split "sub dir"/ with --branch for an existing branch' '
538 subtree_test_create_repo "$test_count" &&
539 subtree_test_create_repo "$test_count/sub proj" &&
540 test_create_commit "$test_count" main1 &&
541 test_create_commit "$test_count/sub proj" sub1 &&
544 git fetch ./"sub proj" HEAD &&
545 git branch subproj-br FETCH_HEAD &&
546 git subtree add --prefix="sub dir" FETCH_HEAD
548 test_create_commit "$test_count" "sub dir"/main-sub1 &&
549 test_create_commit "$test_count" main2 &&
550 test_create_commit "$test_count/sub proj" sub2 &&
551 test_create_commit "$test_count" "sub dir"/main-sub2 &&
554 git fetch ./"sub proj" HEAD &&
555 git subtree merge --prefix="sub dir" FETCH_HEAD &&
556 split_hash=$(git subtree split --prefix="sub dir" --annotate="*") &&
557 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br &&
558 test "$(git rev-parse subproj-br)" = "$split_hash"
562 test_expect_success
'split "sub dir"/ with --branch for an incompatible branch' '
563 subtree_test_create_repo "$test_count" &&
564 subtree_test_create_repo "$test_count/sub proj" &&
565 test_create_commit "$test_count" main1 &&
566 test_create_commit "$test_count/sub proj" sub1 &&
569 git branch init HEAD &&
570 git fetch ./"sub proj" HEAD &&
571 git subtree add --prefix="sub dir" FETCH_HEAD
573 test_create_commit "$test_count" "sub dir"/main-sub1 &&
574 test_create_commit "$test_count" main2 &&
575 test_create_commit "$test_count/sub proj" sub2 &&
576 test_create_commit "$test_count" "sub dir"/main-sub2 &&
579 git fetch ./"sub proj" HEAD &&
580 git subtree merge --prefix="sub dir" FETCH_HEAD &&
581 test_must_fail git subtree split --prefix="sub dir" --branch init
585 test_expect_success
'split after annotated tag was added/merged with --squash pre-v2.32.0' '
586 test_create_pre2_32_repo "$test_count" &&
587 test_must_fail git -C "$test_count-clone" subtree split --prefix="sub" HEAD &&
588 git -C "$test_count-clone" subtree split --prefix="sub" HEAD "../$test_count-sub"
592 # Tests for 'git subtree pull'
595 test_expect_success
'pull requires option --prefix' '
596 subtree_test_create_repo "$test_count" &&
597 subtree_test_create_repo "$test_count/sub proj" &&
598 test_create_commit "$test_count" main1 &&
599 test_create_commit "$test_count/sub proj" sub1 &&
602 git fetch ./"sub proj" HEAD &&
603 git subtree add --prefix="sub dir" FETCH_HEAD
605 test_create_commit "$test_count/sub proj" sub2 &&
608 test_must_fail git subtree pull ./"sub proj" HEAD >out 2>err &&
610 echo "fatal: you must provide the --prefix option." >expected &&
611 test_must_be_empty out &&
612 test_cmp expected err
616 test_expect_success
'pull requires path given by option --prefix must exist' '
617 subtree_test_create_repo "$test_count" &&
618 subtree_test_create_repo "$test_count/sub proj" &&
619 test_create_commit "$test_count" main1 &&
620 test_create_commit "$test_count/sub proj" sub1 &&
622 test_must_fail git subtree pull --prefix="sub dir" ./"sub proj" HEAD >out 2>err &&
624 echo "fatal: '\''sub dir'\'' does not exist; use '\''git subtree add'\''" >expected &&
625 test_must_be_empty out &&
626 test_cmp expected err
630 test_expect_success
'pull basic operation' '
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 &&
637 git fetch ./"sub proj" HEAD &&
638 git subtree add --prefix="sub dir" FETCH_HEAD
640 test_create_commit "$test_count/sub proj" sub2 &&
643 exp=$(git -C "sub proj" rev-parse --verify HEAD:) &&
644 git subtree pull --prefix="sub dir" ./"sub proj" HEAD &&
645 act=$(git rev-parse --verify HEAD:"sub dir") &&
650 test_expect_success
'pull rejects flags for split' '
651 subtree_test_create_repo "$test_count" &&
652 subtree_test_create_repo "$test_count/sub proj" &&
653 test_create_commit "$test_count" main1 &&
654 test_create_commit "$test_count/sub proj" sub1 &&
657 git fetch ./"sub proj" HEAD &&
658 git subtree add --prefix="sub dir" FETCH_HEAD
660 test_create_commit "$test_count/sub proj" sub2 &&
662 test_must_fail git subtree pull --prefix="sub dir" --annotate=foo ./"sub proj" HEAD &&
663 test_must_fail git subtree pull --prefix="sub dir" --branch=foo ./"sub proj" HEAD &&
664 test_must_fail git subtree pull --prefix="sub dir" --ignore-joins ./"sub proj" HEAD &&
665 test_must_fail git subtree pull --prefix="sub dir" --onto=foo ./"sub proj" HEAD &&
666 test_must_fail git subtree pull --prefix="sub dir" --rejoin ./"sub proj" HEAD
670 test_expect_success
'pull with --squash after annotated tag was added/merged with --squash pre-v2.32.0 ' '
671 test_create_pre2_32_repo "$test_count" &&
672 git -C "$test_count-clone" subtree -d pull --prefix="sub" --squash "../$test_count-sub" sub2
676 # Tests for 'git subtree push'
679 test_expect_success
'push requires option --prefix' '
680 subtree_test_create_repo "$test_count" &&
681 subtree_test_create_repo "$test_count/sub proj" &&
682 test_create_commit "$test_count" main1 &&
683 test_create_commit "$test_count/sub proj" sub1 &&
686 git fetch ./"sub proj" HEAD &&
687 git subtree add --prefix="sub dir" FETCH_HEAD &&
688 echo "fatal: you must provide the --prefix option." >expected &&
689 test_must_fail git subtree push "./sub proj" from-mainline >actual 2>&1 &&
690 test_debug "printf '"expected: "'" &&
691 test_debug "cat expected" &&
692 test_debug "printf '"actual: "'" &&
693 test_debug "cat actual" &&
694 test_cmp expected actual
698 test_expect_success
'push requires path given by option --prefix must exist' '
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 &&
707 echo "fatal: '\''non-existent-directory'\'' does not exist; use '\''git subtree add'\''" >expected &&
708 test_must_fail git subtree push --prefix=non-existent-directory "./sub proj" from-mainline >actual 2>&1 &&
709 test_debug "printf '"expected: "'" &&
710 test_debug "cat expected" &&
711 test_debug "printf '"actual: "'" &&
712 test_debug "cat actual" &&
713 test_cmp expected actual
717 test_expect_success
'push rejects flags for add' '
718 subtree_test_create_repo "$test_count" &&
719 subtree_test_create_repo "$test_count/sub proj" &&
720 test_create_commit "$test_count" main1 &&
721 test_create_commit "$test_count/sub proj" sub1 &&
724 git fetch ./"sub proj" HEAD &&
725 git subtree add --prefix="sub dir" FETCH_HEAD
727 test_create_commit "$test_count" "sub dir"/main-sub1 &&
728 test_create_commit "$test_count" main2 &&
729 test_create_commit "$test_count/sub proj" sub2 &&
730 test_create_commit "$test_count" "sub dir"/main-sub2 &&
733 git fetch ./"sub proj" HEAD &&
734 git subtree merge --prefix="sub dir" FETCH_HEAD &&
735 test_wrong_flag git subtree split --prefix="sub dir" --squash ./"sub proj" from-mainline &&
736 test_wrong_flag git subtree split --prefix="sub dir" --message=foo ./"sub proj" from-mainline
740 test_expect_success
'push basic operation' '
741 subtree_test_create_repo "$test_count" &&
742 subtree_test_create_repo "$test_count/sub proj" &&
743 test_create_commit "$test_count" main1 &&
744 test_create_commit "$test_count/sub proj" sub1 &&
747 git fetch ./"sub proj" HEAD &&
748 git subtree add --prefix="sub dir" FETCH_HEAD
750 test_create_commit "$test_count" "sub dir"/main-sub1 &&
751 test_create_commit "$test_count" main2 &&
752 test_create_commit "$test_count/sub proj" sub2 &&
753 test_create_commit "$test_count" "sub dir"/main-sub2 &&
756 git fetch ./"sub proj" HEAD &&
757 git subtree merge --prefix="sub dir" FETCH_HEAD &&
758 before=$(git rev-parse --verify HEAD) &&
759 split_hash=$(git subtree split --prefix="sub dir") &&
760 git subtree push --prefix="sub dir" ./"sub proj" from-mainline &&
761 test "$before" = "$(git rev-parse --verify HEAD)" &&
762 test "$split_hash" = "$(git -C "sub proj" rev-parse --verify refs/heads/from-mainline)"
766 test_expect_success
'push sub dir/ with --rejoin' '
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 split_hash=$(git subtree split --prefix="sub dir" --annotate="*") &&
785 git subtree push --prefix="sub dir" --annotate="*" --rejoin ./"sub proj" from-mainline &&
786 test "$(last_commit_subject)" = "Split '\''sub dir/'\'' into commit '\''$split_hash'\''" &&
787 test "$split_hash" = "$(git -C "sub proj" rev-parse --verify refs/heads/from-mainline)"
791 test_expect_success
'push sub dir/ with --rejoin from scratch' '
792 subtree_test_create_repo "$test_count" &&
793 test_create_commit "$test_count" main1 &&
797 echo file >"sub dir"/file &&
798 git add "sub dir/file" &&
799 git commit -m"sub dir file" &&
800 split_hash=$(git subtree split --prefix="sub dir" --rejoin) &&
801 git init --bare "sub proj.git" &&
802 git subtree push --prefix="sub dir" --rejoin ./"sub proj.git" from-mainline &&
803 test "$(last_commit_subject)" = "Split '\''sub dir/'\'' into commit '\''$split_hash'\''" &&
804 test "$split_hash" = "$(git -C "sub proj.git" rev-parse --verify refs/heads/from-mainline)"
808 test_expect_success
'push sub dir/ with --rejoin and --message' '
809 subtree_test_create_repo "$test_count" &&
810 subtree_test_create_repo "$test_count/sub proj" &&
811 test_create_commit "$test_count" main1 &&
812 test_create_commit "$test_count/sub proj" sub1 &&
815 git fetch ./"sub proj" HEAD &&
816 git subtree add --prefix="sub dir" FETCH_HEAD
818 test_create_commit "$test_count" "sub dir"/main-sub1 &&
819 test_create_commit "$test_count" main2 &&
820 test_create_commit "$test_count/sub proj" sub2 &&
821 test_create_commit "$test_count" "sub dir"/main-sub2 &&
824 git fetch ./"sub proj" HEAD &&
825 git subtree merge --prefix="sub dir" FETCH_HEAD &&
826 git subtree push --prefix="sub dir" --message="Split & rejoin" --annotate="*" --rejoin ./"sub proj" from-mainline &&
827 test "$(last_commit_subject)" = "Split & rejoin" &&
828 split_hash="$(git rev-parse --verify HEAD^2)" &&
829 test "$split_hash" = "$(git -C "sub proj" rev-parse --verify refs/heads/from-mainline)"
833 test_expect_success
'push "sub dir"/ with --rejoin and --squash' '
834 subtree_test_create_repo "$test_count" &&
835 subtree_test_create_repo "$test_count/sub proj" &&
836 test_create_commit "$test_count" main1 &&
837 test_create_commit "$test_count/sub proj" sub1 &&
840 git fetch ./"sub proj" HEAD &&
841 git subtree add --prefix="sub dir" --squash FETCH_HEAD
843 test_create_commit "$test_count" "sub dir"/main-sub1 &&
844 test_create_commit "$test_count" main2 &&
845 test_create_commit "$test_count/sub proj" sub2 &&
846 test_create_commit "$test_count" "sub dir"/main-sub2 &&
849 git subtree pull --prefix="sub dir" --squash ./"sub proj" HEAD &&
850 MAIN=$(git rev-parse --verify HEAD) &&
851 SUB=$(git -C "sub proj" rev-parse --verify HEAD) &&
853 SPLIT=$(git subtree split --prefix="sub dir" --annotate="*") &&
854 git subtree push --prefix="sub dir" --annotate="*" --rejoin --squash ./"sub proj" from-mainline &&
856 test_must_fail git merge-base --is-ancestor $SUB HEAD &&
857 test_must_fail git merge-base --is-ancestor $SPLIT HEAD &&
858 git rev-list HEAD ^$MAIN >commit-list &&
859 test_line_count = 2 commit-list &&
860 test "$(git rev-parse --verify HEAD:)" = "$(git rev-parse --verify $MAIN:)" &&
861 test "$(git rev-parse --verify HEAD:"sub dir")" = "$(git rev-parse --verify $SPLIT:)" &&
862 test "$(git rev-parse --verify HEAD^1)" = $MAIN &&
863 test "$(git rev-parse --verify HEAD^2)" != $SPLIT &&
864 test "$(git rev-parse --verify HEAD^2:)" = "$(git rev-parse --verify $SPLIT:)" &&
865 test "$(last_commit_subject)" = "Split '\''sub dir/'\'' into commit '\''$SPLIT'\''" &&
866 test "$SPLIT" = "$(git -C "sub proj" rev-parse --verify refs/heads/from-mainline)"
870 test_expect_success
'push "sub dir"/ with --branch' '
871 subtree_test_create_repo "$test_count" &&
872 subtree_test_create_repo "$test_count/sub proj" &&
873 test_create_commit "$test_count" main1 &&
874 test_create_commit "$test_count/sub proj" sub1 &&
877 git fetch ./"sub proj" HEAD &&
878 git subtree add --prefix="sub dir" FETCH_HEAD
880 test_create_commit "$test_count" "sub dir"/main-sub1 &&
881 test_create_commit "$test_count" main2 &&
882 test_create_commit "$test_count/sub proj" sub2 &&
883 test_create_commit "$test_count" "sub dir"/main-sub2 &&
886 git fetch ./"sub proj" HEAD &&
887 git subtree merge --prefix="sub dir" FETCH_HEAD &&
888 split_hash=$(git subtree split --prefix="sub dir" --annotate="*") &&
889 git subtree push --prefix="sub dir" --annotate="*" --branch subproj-br ./"sub proj" from-mainline &&
890 test "$(git rev-parse subproj-br)" = "$split_hash" &&
891 test "$split_hash" = "$(git -C "sub proj" rev-parse --verify refs/heads/from-mainline)"
895 test_expect_success
'check hash of push' '
896 subtree_test_create_repo "$test_count" &&
897 subtree_test_create_repo "$test_count/sub proj" &&
898 test_create_commit "$test_count" main1 &&
899 test_create_commit "$test_count/sub proj" sub1 &&
902 git fetch ./"sub proj" HEAD &&
903 git subtree add --prefix="sub dir" FETCH_HEAD
905 test_create_commit "$test_count" "sub dir"/main-sub1 &&
906 test_create_commit "$test_count" main2 &&
907 test_create_commit "$test_count/sub proj" sub2 &&
908 test_create_commit "$test_count" "sub dir"/main-sub2 &&
911 git fetch ./"sub proj" HEAD &&
912 git subtree merge --prefix="sub dir" FETCH_HEAD &&
913 split_hash=$(git subtree split --prefix="sub dir" --annotate="*") &&
914 git subtree push --prefix="sub dir" --annotate="*" --branch subproj-br ./"sub proj" from-mainline &&
915 test "$(git rev-parse subproj-br)" = "$split_hash" &&
916 # Check hash of split
917 new_hash=$(git rev-parse subproj-br^2) &&
920 subdir_hash=$(git rev-parse HEAD) &&
921 test "$new_hash" = "$subdir_hash"
923 test "$split_hash" = "$(git -C "sub proj" rev-parse --verify refs/heads/from-mainline)"
927 test_expect_success
'push "sub dir"/ with --branch for an existing branch' '
928 subtree_test_create_repo "$test_count" &&
929 subtree_test_create_repo "$test_count/sub proj" &&
930 test_create_commit "$test_count" main1 &&
931 test_create_commit "$test_count/sub proj" sub1 &&
934 git fetch ./"sub proj" HEAD &&
935 git branch subproj-br FETCH_HEAD &&
936 git subtree add --prefix="sub dir" FETCH_HEAD
938 test_create_commit "$test_count" "sub dir"/main-sub1 &&
939 test_create_commit "$test_count" main2 &&
940 test_create_commit "$test_count/sub proj" sub2 &&
941 test_create_commit "$test_count" "sub dir"/main-sub2 &&
944 git fetch ./"sub proj" HEAD &&
945 git subtree merge --prefix="sub dir" FETCH_HEAD &&
946 split_hash=$(git subtree split --prefix="sub dir" --annotate="*") &&
947 git subtree push --prefix="sub dir" --annotate="*" --branch subproj-br ./"sub proj" from-mainline &&
948 test "$(git rev-parse subproj-br)" = "$split_hash" &&
949 test "$split_hash" = "$(git -C "sub proj" rev-parse --verify refs/heads/from-mainline)"
953 test_expect_success
'push "sub dir"/ with --branch for an incompatible branch' '
954 subtree_test_create_repo "$test_count" &&
955 subtree_test_create_repo "$test_count/sub proj" &&
956 test_create_commit "$test_count" main1 &&
957 test_create_commit "$test_count/sub proj" sub1 &&
960 git branch init HEAD &&
961 git fetch ./"sub proj" HEAD &&
962 git subtree add --prefix="sub dir" FETCH_HEAD
964 test_create_commit "$test_count" "sub dir"/main-sub1 &&
965 test_create_commit "$test_count" main2 &&
966 test_create_commit "$test_count/sub proj" sub2 &&
967 test_create_commit "$test_count" "sub dir"/main-sub2 &&
970 git fetch ./"sub proj" HEAD &&
971 git subtree merge --prefix="sub dir" FETCH_HEAD &&
972 test_must_fail git subtree push --prefix="sub dir" --branch init "./sub proj" from-mainline
976 test_expect_success
'push "sub dir"/ with a local rev' '
977 subtree_test_create_repo "$test_count" &&
978 subtree_test_create_repo "$test_count/sub proj" &&
979 test_create_commit "$test_count" main1 &&
980 test_create_commit "$test_count/sub proj" sub1 &&
983 git fetch ./"sub proj" HEAD &&
984 git subtree add --prefix="sub dir" FETCH_HEAD
986 test_create_commit "$test_count" "sub dir"/main-sub1 &&
987 test_create_commit "$test_count" "sub dir"/main-sub2 &&
990 bad_tree=$(git rev-parse --verify HEAD:"sub dir") &&
991 good_tree=$(git rev-parse --verify HEAD^:"sub dir") &&
992 git subtree push --prefix="sub dir" --annotate="*" ./"sub proj" HEAD^:from-mainline &&
993 split_tree=$(git -C "sub proj" rev-parse --verify refs/heads/from-mainline:) &&
994 test "$split_tree" = "$good_tree"
998 test_expect_success
'push after annotated tag was added/merged with --squash pre-v2.32.0' '
999 test_create_pre2_32_repo "$test_count" &&
1000 test_create_commit "$test_count-clone" sub/main-sub1 &&
1001 git -C "$test_count-clone" subtree push --prefix="sub" "../$test_count-sub" from-mainline
1008 test_expect_success
'make sure exactly the right set of files ends up in the subproj' '
1009 subtree_test_create_repo "$test_count" &&
1010 subtree_test_create_repo "$test_count/sub proj" &&
1011 test_create_commit "$test_count" main1 &&
1012 test_create_commit "$test_count/sub proj" sub1 &&
1015 git fetch ./"sub proj" HEAD &&
1016 git subtree add --prefix="sub dir" FETCH_HEAD
1018 test_create_commit "$test_count" "sub dir"/main-sub1 &&
1019 test_create_commit "$test_count" main2 &&
1020 test_create_commit "$test_count/sub proj" sub2 &&
1021 test_create_commit "$test_count" "sub dir"/main-sub2 &&
1024 git fetch ./"sub proj" HEAD &&
1025 git subtree merge --prefix="sub dir" FETCH_HEAD &&
1026 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
1028 test_create_commit "$test_count/sub proj" sub3 &&
1029 test_create_commit "$test_count" "sub dir"/main-sub3 &&
1031 cd "$test_count/sub proj" &&
1032 git fetch .. subproj-br &&
1033 git merge FETCH_HEAD
1035 test_create_commit "$test_count/sub proj" sub4 &&
1038 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
1040 test_create_commit "$test_count" "sub dir"/main-sub4 &&
1043 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
1046 cd "$test_count/sub proj" &&
1047 git fetch .. subproj-br &&
1048 git merge FETCH_HEAD &&
1050 test_write_lines main-sub1 main-sub2 main-sub3 main-sub4 \
1051 sub1 sub2 sub3 sub4 >expect &&
1052 git ls-files >actual &&
1053 test_cmp expect actual
1057 test_expect_success
'make sure the subproj *only* contains commits that affect the "sub dir"' '
1058 subtree_test_create_repo "$test_count" &&
1059 subtree_test_create_repo "$test_count/sub proj" &&
1060 test_create_commit "$test_count" main1 &&
1061 test_create_commit "$test_count/sub proj" sub1 &&
1064 git fetch ./"sub proj" HEAD &&
1065 git subtree add --prefix="sub dir" FETCH_HEAD
1067 test_create_commit "$test_count" "sub dir"/main-sub1 &&
1068 test_create_commit "$test_count" main2 &&
1069 test_create_commit "$test_count/sub proj" sub2 &&
1070 test_create_commit "$test_count" "sub dir"/main-sub2 &&
1073 git fetch ./"sub proj" HEAD &&
1074 git subtree merge --prefix="sub dir" FETCH_HEAD &&
1075 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
1077 test_create_commit "$test_count/sub proj" sub3 &&
1078 test_create_commit "$test_count" "sub dir"/main-sub3 &&
1080 cd "$test_count/sub proj" &&
1081 git fetch .. subproj-br &&
1082 git merge FETCH_HEAD
1084 test_create_commit "$test_count/sub proj" sub4 &&
1087 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
1089 test_create_commit "$test_count" "sub dir"/main-sub4 &&
1092 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
1095 cd "$test_count/sub proj" &&
1096 git fetch .. subproj-br &&
1097 git merge FETCH_HEAD &&
1099 test_write_lines main-sub1 main-sub2 main-sub3 main-sub4 \
1100 sub1 sub2 sub3 sub4 >expect &&
1101 git log --name-only --pretty=format:"" >log &&
1102 sort <log | sed "/^\$/ d" >actual &&
1103 test_cmp expect actual
1107 test_expect_success
'make sure exactly the right set of files ends up in the mainline' '
1108 subtree_test_create_repo "$test_count" &&
1109 subtree_test_create_repo "$test_count/sub proj" &&
1110 test_create_commit "$test_count" main1 &&
1111 test_create_commit "$test_count/sub proj" sub1 &&
1114 git fetch ./"sub proj" HEAD &&
1115 git subtree add --prefix="sub dir" FETCH_HEAD
1117 test_create_commit "$test_count" "sub dir"/main-sub1 &&
1118 test_create_commit "$test_count" main2 &&
1119 test_create_commit "$test_count/sub proj" sub2 &&
1120 test_create_commit "$test_count" "sub dir"/main-sub2 &&
1123 git fetch ./"sub proj" HEAD &&
1124 git subtree merge --prefix="sub dir" FETCH_HEAD &&
1125 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
1127 test_create_commit "$test_count/sub proj" sub3 &&
1128 test_create_commit "$test_count" "sub dir"/main-sub3 &&
1130 cd "$test_count/sub proj" &&
1131 git fetch .. subproj-br &&
1132 git merge FETCH_HEAD
1134 test_create_commit "$test_count/sub proj" sub4 &&
1137 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
1139 test_create_commit "$test_count" "sub dir"/main-sub4 &&
1142 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
1145 cd "$test_count/sub proj" &&
1146 git fetch .. subproj-br &&
1147 git merge FETCH_HEAD
1151 git subtree pull --prefix="sub dir" ./"sub proj" HEAD &&
1153 test_write_lines main1 main2 >chkm &&
1154 test_write_lines main-sub1 main-sub2 main-sub3 main-sub4 >chkms &&
1155 sed "s,^,sub dir/," chkms >chkms_sub &&
1156 test_write_lines sub1 sub2 sub3 sub4 >chks &&
1157 sed "s,^,sub dir/," chks >chks_sub &&
1159 cat chkm chkms_sub chks_sub >expect &&
1160 git ls-files >actual &&
1161 test_cmp expect actual
1165 test_expect_success
'make sure each filename changed exactly once in the entire history' '
1166 subtree_test_create_repo "$test_count" &&
1167 subtree_test_create_repo "$test_count/sub proj" &&
1168 test_create_commit "$test_count" main1 &&
1169 test_create_commit "$test_count/sub proj" sub1 &&
1172 git config log.date relative &&
1173 git fetch ./"sub proj" HEAD &&
1174 git subtree add --prefix="sub dir" FETCH_HEAD
1176 test_create_commit "$test_count" "sub dir"/main-sub1 &&
1177 test_create_commit "$test_count" main2 &&
1178 test_create_commit "$test_count/sub proj" sub2 &&
1179 test_create_commit "$test_count" "sub dir"/main-sub2 &&
1182 git fetch ./"sub proj" HEAD &&
1183 git subtree merge --prefix="sub dir" FETCH_HEAD &&
1184 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
1186 test_create_commit "$test_count/sub proj" sub3 &&
1187 test_create_commit "$test_count" "sub dir"/main-sub3 &&
1189 cd "$test_count/sub proj" &&
1190 git fetch .. subproj-br &&
1191 git merge FETCH_HEAD
1193 test_create_commit "$test_count/sub proj" sub4 &&
1196 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
1198 test_create_commit "$test_count" "sub dir"/main-sub4 &&
1201 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
1204 cd "$test_count/sub proj" &&
1205 git fetch .. subproj-br &&
1206 git merge FETCH_HEAD
1210 git subtree pull --prefix="sub dir" ./"sub proj" HEAD &&
1212 test_write_lines main1 main2 >chkm &&
1213 test_write_lines sub1 sub2 sub3 sub4 >chks &&
1214 test_write_lines main-sub1 main-sub2 main-sub3 main-sub4 >chkms &&
1215 sed "s,^,sub dir/," chkms >chkms_sub &&
1217 # main-sub?? and /"sub dir"/main-sub?? both change, because those are the
1218 # changes that were split into their own history. And "sub dir"/sub?? never
1219 # change, since they were *only* changed in the subtree branch.
1220 git log --name-only --pretty=format:"" >log &&
1221 sort <log >sorted-log &&
1222 sed "/^$/ d" sorted-log >actual &&
1224 cat chkms chkm chks chkms_sub >expect-unsorted &&
1225 sort expect-unsorted >expect &&
1226 test_cmp expect actual
1230 test_expect_success
'make sure the --rejoin commits never make it into subproj' '
1231 subtree_test_create_repo "$test_count" &&
1232 subtree_test_create_repo "$test_count/sub proj" &&
1233 test_create_commit "$test_count" main1 &&
1234 test_create_commit "$test_count/sub proj" sub1 &&
1237 git fetch ./"sub proj" HEAD &&
1238 git subtree add --prefix="sub dir" FETCH_HEAD
1240 test_create_commit "$test_count" "sub dir"/main-sub1 &&
1241 test_create_commit "$test_count" main2 &&
1242 test_create_commit "$test_count/sub proj" sub2 &&
1243 test_create_commit "$test_count" "sub dir"/main-sub2 &&
1246 git fetch ./"sub proj" HEAD &&
1247 git subtree merge --prefix="sub dir" FETCH_HEAD &&
1248 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
1250 test_create_commit "$test_count/sub proj" sub3 &&
1251 test_create_commit "$test_count" "sub dir"/main-sub3 &&
1253 cd "$test_count/sub proj" &&
1254 git fetch .. subproj-br &&
1255 git merge FETCH_HEAD
1257 test_create_commit "$test_count/sub proj" sub4 &&
1260 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
1262 test_create_commit "$test_count" "sub dir"/main-sub4 &&
1265 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
1268 cd "$test_count/sub proj" &&
1269 git fetch .. subproj-br &&
1270 git merge FETCH_HEAD
1274 git subtree pull --prefix="sub dir" ./"sub proj" HEAD &&
1275 test "$(git log --pretty=format:"%s" HEAD^2 | grep -i split)" = ""
1279 test_expect_success
'make sure no "git subtree" tagged commits make it into subproj' '
1280 subtree_test_create_repo "$test_count" &&
1281 subtree_test_create_repo "$test_count/sub proj" &&
1282 test_create_commit "$test_count" main1 &&
1283 test_create_commit "$test_count/sub proj" sub1 &&
1286 git fetch ./"sub proj" HEAD &&
1287 git subtree add --prefix="sub dir" FETCH_HEAD
1289 test_create_commit "$test_count" "sub dir"/main-sub1 &&
1290 test_create_commit "$test_count" main2 &&
1291 test_create_commit "$test_count/sub proj" sub2 &&
1292 test_create_commit "$test_count" "sub dir"/main-sub2 &&
1295 git fetch ./"sub proj" HEAD &&
1296 git subtree merge --prefix="sub dir" FETCH_HEAD &&
1297 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
1299 test_create_commit "$test_count/sub proj" sub3 &&
1300 test_create_commit "$test_count" "sub dir"/main-sub3 &&
1302 cd "$test_count/sub proj" &&
1303 git fetch .. subproj-br &&
1304 git merge FETCH_HEAD
1306 test_create_commit "$test_count/sub proj" sub4 &&
1309 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
1311 test_create_commit "$test_count" "sub dir"/main-sub4 &&
1314 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
1317 cd "$test_count/sub proj" &&
1318 git fetch .. subproj-br &&
1319 git merge FETCH_HEAD
1323 git subtree pull --prefix="sub dir" ./"sub proj" HEAD &&
1325 # They are meaningless to subproj since one side of the merge refers to the mainline
1326 test "$(git log --pretty=format:"%s%n%b" HEAD^2 | grep "git-subtree.*:")" = ""
1331 # A new set of tests
1334 test_expect_success
'make sure "git subtree split" find the correct parent' '
1335 subtree_test_create_repo "$test_count" &&
1336 subtree_test_create_repo "$test_count/sub proj" &&
1337 test_create_commit "$test_count" main1 &&
1338 test_create_commit "$test_count/sub proj" sub1 &&
1341 git fetch ./"sub proj" HEAD &&
1342 git subtree add --prefix="sub dir" FETCH_HEAD
1344 test_create_commit "$test_count/sub proj" sub2 &&
1347 git fetch ./"sub proj" HEAD &&
1348 git branch subproj-ref FETCH_HEAD &&
1349 git subtree merge --prefix="sub dir" FETCH_HEAD
1351 test_create_commit "$test_count" "sub dir"/main-sub1 &&
1354 git subtree split --prefix="sub dir" --branch subproj-br &&
1356 # at this point, the new commit parent should be subproj-ref, if it is
1357 # not, something went wrong (the "newparent" of "HEAD~" commit should
1358 # have been sub2, but it was not, because its cache was not set to
1360 test "$(git log --pretty=format:%P -1 subproj-br)" = "$(git rev-parse subproj-ref)"
1364 test_expect_success
'split a new subtree without --onto option' '
1365 subtree_test_create_repo "$test_count" &&
1366 subtree_test_create_repo "$test_count/sub proj" &&
1367 test_create_commit "$test_count" main1 &&
1368 test_create_commit "$test_count/sub proj" sub1 &&
1371 git fetch ./"sub proj" HEAD &&
1372 git subtree add --prefix="sub dir" FETCH_HEAD
1374 test_create_commit "$test_count/sub proj" sub2 &&
1377 git fetch ./"sub proj" HEAD &&
1378 git subtree merge --prefix="sub dir" FETCH_HEAD
1380 test_create_commit "$test_count" "sub dir"/main-sub1 &&
1383 git subtree split --prefix="sub dir" --branch subproj-br
1385 mkdir "$test_count"/"sub dir2" &&
1386 test_create_commit "$test_count" "sub dir2"/main-sub2 &&
1390 # also test that we still can split out an entirely new subtree
1391 # if the parent of the first commit in the tree is not empty,
1392 # then the new subtree has accidentally been attached to something
1393 git subtree split --prefix="sub dir2" --branch subproj2-br &&
1394 test "$(git log --pretty=format:%P -1 subproj2-br)" = ""
1398 test_expect_success
'verify one file change per commit' '
1399 subtree_test_create_repo "$test_count" &&
1400 subtree_test_create_repo "$test_count/sub proj" &&
1401 test_create_commit "$test_count" main1 &&
1402 test_create_commit "$test_count/sub proj" sub1 &&
1405 git fetch ./"sub proj" HEAD &&
1406 git branch sub1 FETCH_HEAD &&
1407 git subtree add --prefix="sub dir" sub1
1409 test_create_commit "$test_count/sub proj" sub2 &&
1412 git fetch ./"sub proj" HEAD &&
1413 git subtree merge --prefix="sub dir" FETCH_HEAD
1415 test_create_commit "$test_count" "sub dir"/main-sub1 &&
1418 git subtree split --prefix="sub dir" --branch subproj-br
1420 mkdir "$test_count"/"sub dir2" &&
1421 test_create_commit "$test_count" "sub dir2"/main-sub2 &&
1424 git subtree split --prefix="sub dir2" --branch subproj2-br &&
1426 git log --format="%H" >commit-list &&
1429 git log -n1 --format="" --name-only "$commit" >file-list &&
1430 test_line_count -le 1 file-list || return 1
1435 test_expect_success
'push split to subproj' '
1436 subtree_test_create_repo "$test_count" &&
1437 subtree_test_create_repo "$test_count/sub proj" &&
1438 test_create_commit "$test_count" main1 &&
1439 test_create_commit "$test_count/sub proj" sub1 &&
1442 git fetch ./"sub proj" HEAD &&
1443 git subtree add --prefix="sub dir" FETCH_HEAD
1445 test_create_commit "$test_count" "sub dir"/main-sub1 &&
1446 test_create_commit "$test_count" main2 &&
1447 test_create_commit "$test_count/sub proj" sub2 &&
1448 test_create_commit "$test_count" "sub dir"/main-sub2 &&
1450 cd $test_count/"sub proj" &&
1451 git branch sub-branch-1 &&
1453 git fetch ./"sub proj" HEAD &&
1454 git subtree merge --prefix="sub dir" FETCH_HEAD
1456 test_create_commit "$test_count" "sub dir"/main-sub3 &&
1459 git subtree push ./"sub proj" --prefix "sub dir" sub-branch-1 &&
1461 git checkout sub-branch-1 &&
1462 test "$(last_commit_subject)" = "sub dir/main-sub3"
1467 # This test covers 2 cases in subtree split copy_or_skip code
1468 # 1) Merges where one parent is a superset of the changes of the other
1469 # parent regarding changes to the subtree, in this case the merge
1470 # commit should be copied
1471 # 2) Merges where only one parent operate on the subtree, and the merge
1472 # commit should be skipped
1474 # (1) is checked by ensuring subtree_tip is a descendent of subtree_branch
1475 # (2) should have a check added (not_a_subtree_change shouldn't be present
1476 # on the produced subtree)
1478 # Other related cases which are not tested (or currently handled correctly)
1479 # - Case (1) where there are more than 2 parents, it will sometimes correctly copy
1480 # the merge, and sometimes not
1481 # - Merge commit where both parents have same tree as the merge, currently
1482 # will always be skipped, even if they reached that state via different
1486 test_expect_success
'subtree descendant check' '
1487 subtree_test_create_repo "$test_count" &&
1488 defaultBranch=$(sed "s,ref: refs/heads/,," "$test_count/.git/HEAD") &&
1489 test_create_commit "$test_count" folder_subtree/a &&
1494 test_create_commit "$test_count" folder_subtree/0 &&
1495 test_create_commit "$test_count" folder_subtree/b &&
1496 cherry=$(cd "$test_count" && git rev-parse HEAD) &&
1501 test_create_commit "$test_count" commit_on_branch &&
1504 git cherry-pick $cherry &&
1505 git checkout $defaultBranch &&
1506 git merge -m "merge should be kept on subtree" branch &&
1507 git branch no_subtree_work_branch
1509 test_create_commit "$test_count" folder_subtree/d &&
1512 git checkout no_subtree_work_branch
1514 test_create_commit "$test_count" not_a_subtree_change &&
1517 git checkout $defaultBranch &&
1518 git merge -m "merge should be skipped on subtree" no_subtree_work_branch &&
1520 git subtree split --prefix folder_subtree/ --branch subtree_tip $defaultBranch &&
1521 git subtree split --prefix folder_subtree/ --branch subtree_branch branch &&
1522 test $(git rev-list --count subtree_tip..subtree_branch) = 0