@@ -33,6 +33,12 @@ test_create_commit () (
33
33
git commit -m " $commit " || error " Could not commit"
34
34
)
35
35
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
+
36
42
last_commit_subject () {
37
43
git log --pretty=format:%s -1
38
44
}
@@ -72,6 +78,22 @@ test_expect_success 'no pull from non-existent subtree' '
72
78
)
73
79
'
74
80
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
+
75
97
test_expect_success ' add subproj as subtree into sub dir/ with --prefix' '
76
98
subtree_test_create_repo "$test_count" &&
77
99
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
128
150
# Tests for 'git subtree merge'
129
151
#
130
152
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
+
131
175
test_expect_success ' merge new subproj history into sub dir/ with --prefix' '
132
176
subtree_test_create_repo "$test_count" &&
133
177
subtree_test_create_repo "$test_count/sub proj" &&
@@ -262,6 +306,30 @@ test_expect_success 'split requires path given by option --prefix must exist' '
262
306
)
263
307
'
264
308
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
+
265
333
test_expect_success ' split sub dir/ with --rejoin' '
266
334
subtree_test_create_repo "$test_count" &&
267
335
subtree_test_create_repo "$test_count/sub proj" &&
@@ -542,6 +610,26 @@ test_expect_success 'pull basic operation' '
542
610
)
543
611
'
544
612
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
+
545
633
#
546
634
# Tests for 'git subtree push'
547
635
#
@@ -584,6 +672,29 @@ test_expect_success 'push requires path given by option --prefix must exist' '
584
672
)
585
673
'
586
674
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
+
587
698
test_expect_success ' push basic operation' '
588
699
subtree_test_create_repo "$test_count" &&
589
700
subtree_test_create_repo "$test_count/sub proj" &&
0 commit comments