@@ -33,6 +33,12 @@ test_create_commit () (
3333 git commit -m " $commit " || error " Could not commit"
3434)
3535
36+ test_wrong_flag () {
37+ test_must_fail " $@ " > out 2> err &&
38+ test_must_be_empty out &&
39+ grep " flag does not make sense with" err
40+ }
41+
3642last_commit_subject () {
3743 git log --pretty=format:%s -1
3844}
@@ -72,6 +78,22 @@ test_expect_success 'no pull from non-existent subtree' '
7278 )
7379'
7480
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 &&
86+ (
87+ cd "$test_count" &&
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
94+ )
95+ '
96+
7597test_expect_success ' add subproj as subtree into sub dir/ with --prefix' '
7698 subtree_test_create_repo "$test_count" &&
7799 subtree_test_create_repo "$test_count/sub proj" &&
@@ -128,6 +150,28 @@ test_expect_success 'add subproj as subtree into sub dir/ with --squash and --pr
128150# Tests for 'git subtree merge'
129151#
130152
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 &&
158+ (
159+ cd "$test_count" &&
160+ git fetch ./"sub proj" HEAD &&
161+ git subtree add --prefix="sub dir" FETCH_HEAD
162+ ) &&
163+ test_create_commit "$test_count/sub proj" sub2 &&
164+ (
165+ cd "$test_count" &&
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
172+ )
173+ '
174+
131175test_expect_success ' merge new subproj history into sub dir/ with --prefix' '
132176 subtree_test_create_repo "$test_count" &&
133177 subtree_test_create_repo "$test_count/sub proj" &&
@@ -262,6 +306,30 @@ test_expect_success 'split requires path given by option --prefix must exist' '
262306 )
263307'
264308
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 &&
314+ (
315+ cd "$test_count" &&
316+ git fetch ./"sub proj" HEAD &&
317+ git subtree add --prefix="sub dir" FETCH_HEAD
318+ ) &&
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 &&
323+ (
324+ cd "$test_count" &&
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
330+ )
331+ '
332+
265333test_expect_success ' split sub dir/ with --rejoin' '
266334 subtree_test_create_repo "$test_count" &&
267335 subtree_test_create_repo "$test_count/sub proj" &&
@@ -542,6 +610,26 @@ test_expect_success 'pull basic operation' '
542610 )
543611'
544612
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 &&
618+ (
619+ cd "$test_count" &&
620+ git fetch ./"sub proj" HEAD &&
621+ git subtree add --prefix="sub dir" FETCH_HEAD
622+ ) &&
623+ test_create_commit "$test_count/sub proj" sub2 &&
624+ (
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
630+ )
631+ '
632+
545633#
546634# Tests for 'git subtree push'
547635#
@@ -584,6 +672,29 @@ test_expect_success 'push requires path given by option --prefix must exist' '
584672 )
585673'
586674
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 &&
680+ (
681+ cd "$test_count" &&
682+ git fetch ./"sub proj" HEAD &&
683+ git subtree add --prefix="sub dir" FETCH_HEAD
684+ ) &&
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 &&
689+ (
690+ cd "$test_count" &&
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
695+ )
696+ '
697+
587698test_expect_success ' push basic operation' '
588699 subtree_test_create_repo "$test_count" &&
589700 subtree_test_create_repo "$test_count/sub proj" &&
0 commit comments