]> git.ipfire.org Git - thirdparty/git.git/blame - contrib/subtree/t/t7900-subtree.sh
Merge branch 'bb/unicode-width-table-15'
[thirdparty/git.git] / contrib / subtree / t / t7900-subtree.sh
CommitLineData
d3a04e06
DG
1#!/bin/sh
2#
3# Copyright (c) 2012 Avery Pennaraum
5b6ab38b 4# Copyright (c) 2015 Alexey Shumkin
d3a04e06
DG
5#
6test_description='Basic porcelain support for subtrees
7
94389e7c
LS
8This test verifies the basic operation of the add, merge, split, pull,
9and push subcommands of git subtree.
d3a04e06
DG
10'
11
bed137d2 12TEST_DIRECTORY=$(pwd)/../../../t
f7004069 13. "$TEST_DIRECTORY"/test-lib.sh
603ee0f0 14
40b1e1ec
LS
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.
f7004069 20subtree_test_create_repo () {
fbd3199a 21 test_create_repo "$1" &&
40b1e1ec 22 git -C "$1" config log.date relative
43711746
TZ
23}
24
f7004069 25test_create_commit () (
fbd3199a
DA
26 repo=$1 &&
27 commit=$2 &&
28 cd "$repo" &&
29 mkdir -p "$(dirname "$commit")" \
43711746 30 || error "Could not create directory for commit"
fbd3199a 31 echo "$commit" >"$commit" &&
43711746
TZ
32 git add "$commit" || error "Could not add commit"
33 git commit -m "$commit" || error "Could not commit"
34)
35
9a3e3ca2
LS
36test_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
db6952b2 42last_commit_subject () {
6fe98630 43 git log --pretty=format:%s -1
13ea2b5e
JS
44}
45
0d330673
PB
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:
52# - $1
53# - $1-sub (added as subtree "sub" in $1)
54# - $1-clone (clone of $1)
55test_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
68}
69
b2699769
LS
70test_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 &&
e8e5d294 74 grep -F -e "--[no-]annotate" out
b2699769
LS
75'
76
43711746
TZ
77#
78# Tests for 'git subtree add'
79#
d3a04e06 80
a6867011 81test_expect_success 'no merge from non-existent subtree' '
f2bb7fef
LS
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 &&
43711746 86 (
f2bb7fef 87 cd "$test_count" &&
914d5125 88 git fetch ./"sub proj" HEAD &&
43711746
TZ
89 test_must_fail git subtree merge --prefix="sub dir" FETCH_HEAD
90 )
a6867011
TZ
91'
92
43711746 93test_expect_success 'no pull from non-existent subtree' '
f2bb7fef
LS
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 &&
43711746 98 (
f2bb7fef 99 cd "$test_count" &&
914d5125
LS
100 git fetch ./"sub proj" HEAD &&
101 test_must_fail git subtree pull --prefix="sub dir" ./"sub proj" HEAD
f7004069
LS
102 )
103'
c9924996 104
9a3e3ca2
LS
105test_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 &&
110 (
111 cd "$test_count" &&
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
118 )
119'
120
43711746 121test_expect_success 'add subproj as subtree into sub dir/ with --prefix' '
f2bb7fef
LS
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 &&
43711746 126 (
f2bb7fef 127 cd "$test_count" &&
914d5125 128 git fetch ./"sub proj" HEAD &&
43711746 129 git subtree add --prefix="sub dir" FETCH_HEAD &&
db6952b2 130 test "$(last_commit_subject)" = "Add '\''sub dir/'\'' from commit '\''$(git rev-parse FETCH_HEAD)'\''"
43711746 131 )
d3a04e06
DG
132'
133
c9924996 134test_expect_success 'add subproj as subtree into sub dir/ with --prefix and --message' '
f2bb7fef
LS
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 &&
43711746 139 (
f2bb7fef 140 cd "$test_count" &&
914d5125 141 git fetch ./"sub proj" HEAD &&
43711746 142 git subtree add --prefix="sub dir" --message="Added subproject" FETCH_HEAD &&
db6952b2 143 test "$(last_commit_subject)" = "Added subproject"
43711746 144 )
d3a04e06
DG
145'
146
43711746 147test_expect_success 'add subproj as subtree into sub dir/ with --prefix as -P and --message as -m' '
f2bb7fef
LS
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 &&
43711746 152 (
f2bb7fef 153 cd "$test_count" &&
914d5125 154 git fetch ./"sub proj" HEAD &&
43711746 155 git subtree add -P "sub dir" -m "Added subproject" FETCH_HEAD &&
db6952b2 156 test "$(last_commit_subject)" = "Added subproject"
43711746 157 )
d3a04e06
DG
158'
159
c9924996 160test_expect_success 'add subproj as subtree into sub dir/ with --squash and --prefix and --message' '
f2bb7fef
LS
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 &&
43711746 165 (
f2bb7fef 166 cd "$test_count" &&
914d5125 167 git fetch ./"sub proj" HEAD &&
43711746 168 git subtree add --prefix="sub dir" --message="Added subproject with squash" --squash FETCH_HEAD &&
db6952b2 169 test "$(last_commit_subject)" = "Added subproject with squash"
43711746 170 )
d3a04e06
DG
171'
172
43711746
TZ
173#
174# Tests for 'git subtree merge'
175#
d3a04e06 176
9a3e3ca2
LS
177test_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 &&
182 (
183 cd "$test_count" &&
184 git fetch ./"sub proj" HEAD &&
185 git subtree add --prefix="sub dir" FETCH_HEAD
186 ) &&
187 test_create_commit "$test_count/sub proj" sub2 &&
188 (
189 cd "$test_count" &&
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
196 )
197'
198
43711746 199test_expect_success 'merge new subproj history into sub dir/ with --prefix' '
f2bb7fef
LS
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 &&
43711746 204 (
f2bb7fef 205 cd "$test_count" &&
914d5125 206 git fetch ./"sub proj" HEAD &&
43711746
TZ
207 git subtree add --prefix="sub dir" FETCH_HEAD
208 ) &&
f2bb7fef 209 test_create_commit "$test_count/sub proj" sub2 &&
43711746 210 (
f2bb7fef 211 cd "$test_count" &&
914d5125 212 git fetch ./"sub proj" HEAD &&
43711746 213 git subtree merge --prefix="sub dir" FETCH_HEAD &&
db6952b2 214 test "$(last_commit_subject)" = "Merge commit '\''$(git rev-parse FETCH_HEAD)'\''"
43711746 215 )
d3a04e06
DG
216'
217
43711746 218test_expect_success 'merge new subproj history into sub dir/ with --prefix and --message' '
f2bb7fef
LS
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 &&
43711746 223 (
f2bb7fef 224 cd "$test_count" &&
914d5125 225 git fetch ./"sub proj" HEAD &&
43711746
TZ
226 git subtree add --prefix="sub dir" FETCH_HEAD
227 ) &&
f2bb7fef 228 test_create_commit "$test_count/sub proj" sub2 &&
43711746 229 (
f2bb7fef 230 cd "$test_count" &&
914d5125 231 git fetch ./"sub proj" HEAD &&
43711746 232 git subtree merge --prefix="sub dir" --message="Merged changes from subproject" FETCH_HEAD &&
db6952b2 233 test "$(last_commit_subject)" = "Merged changes from subproject"
43711746 234 )
d3a04e06
DG
235'
236
43711746 237test_expect_success 'merge new subproj history into sub dir/ with --squash and --prefix and --message' '
f2bb7fef
LS
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 &&
43711746 242 (
f2bb7fef 243 cd "$test_count" &&
914d5125 244 git fetch ./"sub proj" HEAD &&
43711746
TZ
245 git subtree add --prefix="sub dir" FETCH_HEAD
246 ) &&
f2bb7fef 247 test_create_commit "$test_count/sub proj" sub2 &&
43711746 248 (
f2bb7fef 249 cd "$test_count" &&
914d5125 250 git fetch ./"sub proj" HEAD &&
43711746 251 git subtree merge --prefix="sub dir" --message="Merged changes from subproject using squash" --squash FETCH_HEAD &&
db6952b2 252 test "$(last_commit_subject)" = "Merged changes from subproject using squash"
43711746 253 )
d3a04e06
DG
254'
255
43711746 256test_expect_success 'merge the added subproj again, should do nothing' '
f2bb7fef
LS
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 &&
43711746 261 (
f2bb7fef 262 cd "$test_count" &&
914d5125 263 git fetch ./"sub proj" HEAD &&
43711746
TZ
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) &&
c4566ab4 268 test "${result}" = "Already up to date."
43711746 269 )
4f96fcc9
TZ
270'
271
d16031ca 272test_expect_success 'merge new subproj history into subdir/ with a slash appended to the argument of --prefix' '
40b1e1ec
LS
273 subtree_test_create_repo "$test_count" &&
274 subtree_test_create_repo "$test_count/subproj" &&
d16031ca
TZ
275 test_create_commit "$test_count" main1 &&
276 test_create_commit "$test_count/subproj" sub1 &&
277 (
278 cd "$test_count" &&
914d5125 279 git fetch ./subproj HEAD &&
d16031ca
TZ
280 git subtree add --prefix=subdir/ FETCH_HEAD
281 ) &&
282 test_create_commit "$test_count/subproj" sub2 &&
283 (
284 cd "$test_count" &&
914d5125 285 git fetch ./subproj HEAD &&
d16031ca 286 git subtree merge --prefix=subdir/ FETCH_HEAD &&
db6952b2 287 test "$(last_commit_subject)" = "Merge commit '\''$(git rev-parse FETCH_HEAD)'\''"
d16031ca
TZ
288 )
289'
290
0d330673
PB
291test_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"
296'
297
43711746
TZ
298#
299# Tests for 'git subtree split'
300#
4f96fcc9 301
b0638aa2 302test_expect_success 'split requires option --prefix' '
f2bb7fef
LS
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 &&
43711746 307 (
f2bb7fef 308 cd "$test_count" &&
914d5125 309 git fetch ./"sub proj" HEAD &&
43711746 310 git subtree add --prefix="sub dir" FETCH_HEAD &&
5626a9e2 311 echo "fatal: you must provide the --prefix option." >expected &&
f7004069 312 test_must_fail git subtree split >actual 2>&1 &&
43711746
TZ
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
318 )
d3a04e06
DG
319'
320
b0638aa2 321test_expect_success 'split requires path given by option --prefix must exist' '
f2bb7fef
LS
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 &&
43711746 326 (
f2bb7fef 327 cd "$test_count" &&
914d5125 328 git fetch ./"sub proj" HEAD &&
43711746 329 git subtree add --prefix="sub dir" FETCH_HEAD &&
5626a9e2 330 echo "fatal: '\''non-existent-directory'\'' does not exist; use '\''git subtree add'\''" >expected &&
f7004069 331 test_must_fail git subtree split --prefix=non-existent-directory >actual 2>&1 &&
43711746
TZ
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
337 )
d3a04e06
DG
338'
339
9a3e3ca2
LS
340test_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 &&
345 (
346 cd "$test_count" &&
347 git fetch ./"sub proj" HEAD &&
348 git subtree add --prefix="sub dir" FETCH_HEAD
349 ) &&
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 &&
354 (
355 cd "$test_count" &&
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
361 )
362'
363
4fe2e33c 364test_expect_success 'split sub dir/ with --rejoin' '
f2bb7fef
LS
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 &&
43711746 369 (
f2bb7fef 370 cd "$test_count" &&
914d5125 371 git fetch ./"sub proj" HEAD &&
43711746
TZ
372 git subtree add --prefix="sub dir" FETCH_HEAD
373 ) &&
f2bb7fef
LS
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 &&
43711746 378 (
f2bb7fef 379 cd "$test_count" &&
914d5125 380 git fetch ./"sub proj" HEAD &&
43711746
TZ
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 &&
db6952b2 384 test "$(last_commit_subject)" = "Split '\''sub dir/'\'' into commit '\''$split_hash'\''"
43711746 385 )
f7004069 386'
4fe2e33c 387
0f12c7d4 388test_expect_success 'split sub dir/ with --rejoin from scratch' '
f2bb7fef
LS
389 subtree_test_create_repo "$test_count" &&
390 test_create_commit "$test_count" main1 &&
0f12c7d4 391 (
f2bb7fef 392 cd "$test_count" &&
0f12c7d4
DA
393 mkdir "sub dir" &&
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 &&
db6952b2 399 test "$(last_commit_subject)" = "Split '\''sub dir/'\'' into commit '\''$split_hash'\''"
0f12c7d4 400 )
f7004069 401'
0f12c7d4 402
4fe2e33c 403test_expect_success 'split sub dir/ with --rejoin and --message' '
f2bb7fef
LS
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 &&
43711746 408 (
f2bb7fef 409 cd "$test_count" &&
914d5125 410 git fetch ./"sub proj" HEAD &&
43711746
TZ
411 git subtree add --prefix="sub dir" FETCH_HEAD
412 ) &&
f2bb7fef
LS
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 &&
43711746 417 (
f2bb7fef 418 cd "$test_count" &&
914d5125 419 git fetch ./"sub proj" HEAD &&
43711746
TZ
420 git subtree merge --prefix="sub dir" FETCH_HEAD &&
421 git subtree split --prefix="sub dir" --message="Split & rejoin" --annotate="*" --rejoin &&
db6952b2 422 test "$(last_commit_subject)" = "Split & rejoin"
43711746 423 )
d3a04e06
DG
424'
425
cb655144
LS
426test_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 &&
431 (
432 cd "$test_count" &&
433 git fetch ./"sub proj" HEAD &&
434 git subtree add --prefix="sub dir" --squash FETCH_HEAD
435 ) &&
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 &&
440 (
441 cd "$test_count" &&
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) &&
445
446 SPLIT=$(git subtree split --prefix="sub dir" --annotate="*" --rejoin --squash) &&
447
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'\''"
458 )
459'
460
461test_expect_success 'split then pull "sub dir"/ with --rejoin and --squash' '
462 # 1. "add"
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 &&
468
469 # 2. commit from parent
470 test_create_commit "$test_count" "sub dir"/main-sub1 &&
471
472 # 3. "split --rejoin --squash"
473 git -C "$test_count" subtree --prefix="sub dir" split --rejoin --squash &&
474
475 # 4. "pull --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 &&
478
479 test_must_fail git merge-base HEAD FETCH_HEAD
480'
481
43711746 482test_expect_success 'split "sub dir"/ with --branch' '
f2bb7fef
LS
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 &&
43711746 487 (
f2bb7fef 488 cd "$test_count" &&
914d5125 489 git fetch ./"sub proj" HEAD &&
43711746
TZ
490 git subtree add --prefix="sub dir" FETCH_HEAD
491 ) &&
f2bb7fef
LS
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 &&
43711746 496 (
f2bb7fef 497 cd "$test_count" &&
914d5125 498 git fetch ./"sub proj" HEAD &&
43711746
TZ
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 &&
c4566ab4 502 test "$(git rev-parse subproj-br)" = "$split_hash"
43711746 503 )
d3a04e06
DG
504'
505
43711746 506test_expect_success 'check hash of split' '
f2bb7fef
LS
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 &&
43711746 511 (
f2bb7fef 512 cd "$test_count" &&
914d5125 513 git fetch ./"sub proj" HEAD &&
43711746
TZ
514 git subtree add --prefix="sub dir" FETCH_HEAD
515 ) &&
f2bb7fef
LS
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 &&
43711746 520 (
f2bb7fef 521 cd "$test_count" &&
914d5125 522 git fetch ./"sub proj" HEAD &&
43711746
TZ
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 &&
c4566ab4 526 test "$(git rev-parse subproj-br)" = "$split_hash" &&
43711746
TZ
527 # Check hash of split
528 new_hash=$(git rev-parse subproj-br^2) &&
529 (
530 cd ./"sub proj" &&
531 subdir_hash=$(git rev-parse HEAD) &&
63ac4f1a 532 test "$new_hash" = "$subdir_hash"
43711746
TZ
533 )
534 )
d3a04e06
DG
535'
536
43711746 537test_expect_success 'split "sub dir"/ with --branch for an existing branch' '
f2bb7fef
LS
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 &&
43711746 542 (
f2bb7fef 543 cd "$test_count" &&
914d5125 544 git fetch ./"sub proj" HEAD &&
43711746
TZ
545 git branch subproj-br FETCH_HEAD &&
546 git subtree add --prefix="sub dir" FETCH_HEAD
547 ) &&
f2bb7fef
LS
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 &&
43711746 552 (
f2bb7fef 553 cd "$test_count" &&
914d5125 554 git fetch ./"sub proj" HEAD &&
43711746
TZ
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 &&
c4566ab4 558 test "$(git rev-parse subproj-br)" = "$split_hash"
43711746 559 )
d3a04e06
DG
560'
561
43711746 562test_expect_success 'split "sub dir"/ with --branch for an incompatible branch' '
f2bb7fef
LS
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 &&
43711746 567 (
f2bb7fef 568 cd "$test_count" &&
43711746 569 git branch init HEAD &&
914d5125 570 git fetch ./"sub proj" HEAD &&
43711746
TZ
571 git subtree add --prefix="sub dir" FETCH_HEAD
572 ) &&
f2bb7fef
LS
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 &&
43711746 577 (
f2bb7fef 578 cd "$test_count" &&
914d5125 579 git fetch ./"sub proj" HEAD &&
43711746
TZ
580 git subtree merge --prefix="sub dir" FETCH_HEAD &&
581 test_must_fail git subtree split --prefix="sub dir" --branch init
582 )
d3a04e06 583'
847e8681 584
1762382a
PB
585test_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"
589'
590
b04538d9
LS
591#
592# Tests for 'git subtree pull'
593#
594
595test_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 &&
600 (
601 cd "$test_count" &&
602 git fetch ./"sub proj" HEAD &&
603 git subtree add --prefix="sub dir" FETCH_HEAD
604 ) &&
605 test_create_commit "$test_count/sub proj" sub2 &&
606 (
607 cd "$test_count" &&
608 test_must_fail git subtree pull ./"sub proj" HEAD >out 2>err &&
609
5626a9e2 610 echo "fatal: you must provide the --prefix option." >expected &&
b04538d9
LS
611 test_must_be_empty out &&
612 test_cmp expected err
613 )
614'
615
616test_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 &&
621 (
622 test_must_fail git subtree pull --prefix="sub dir" ./"sub proj" HEAD >out 2>err &&
623
5626a9e2 624 echo "fatal: '\''sub dir'\'' does not exist; use '\''git subtree add'\''" >expected &&
b04538d9
LS
625 test_must_be_empty out &&
626 test_cmp expected err
627 )
628'
629
630test_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 &&
635 (
636 cd "$test_count" &&
637 git fetch ./"sub proj" HEAD &&
638 git subtree add --prefix="sub dir" FETCH_HEAD
639 ) &&
640 test_create_commit "$test_count/sub proj" sub2 &&
641 (
642 cd "$test_count" &&
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") &&
646 test "$act" = "$exp"
647 )
648'
649
9a3e3ca2
LS
650test_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 &&
655 (
656 cd "$test_count" &&
657 git fetch ./"sub proj" HEAD &&
658 git subtree add --prefix="sub dir" FETCH_HEAD
659 ) &&
660 test_create_commit "$test_count/sub proj" sub2 &&
661 (
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
667 )
668'
669
0d330673
PB
670test_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
673'
674
b04538d9
LS
675#
676# Tests for 'git subtree push'
677#
678
679test_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 &&
684 (
685 cd "$test_count" &&
686 git fetch ./"sub proj" HEAD &&
687 git subtree add --prefix="sub dir" FETCH_HEAD &&
5626a9e2 688 echo "fatal: you must provide the --prefix option." >expected &&
b04538d9
LS
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
695 )
696'
697
698test_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 &&
703 (
704 cd "$test_count" &&
705 git fetch ./"sub proj" HEAD &&
706 git subtree add --prefix="sub dir" FETCH_HEAD &&
5626a9e2 707 echo "fatal: '\''non-existent-directory'\'' does not exist; use '\''git subtree add'\''" >expected &&
b04538d9
LS
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
714 )
715'
716
9a3e3ca2
LS
717test_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 &&
722 (
723 cd "$test_count" &&
724 git fetch ./"sub proj" HEAD &&
725 git subtree add --prefix="sub dir" FETCH_HEAD
726 ) &&
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 &&
731 (
732 cd "$test_count" &&
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
737 )
738'
739
b04538d9
LS
740test_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 &&
745 (
746 cd "$test_count" &&
747 git fetch ./"sub proj" HEAD &&
748 git subtree add --prefix="sub dir" FETCH_HEAD
749 ) &&
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 &&
754 (
755 cd "$test_count" &&
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)"
763 )
764'
765
94389e7c
LS
766test_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 &&
771 (
772 cd "$test_count" &&
773 git fetch ./"sub proj" HEAD &&
774 git subtree add --prefix="sub dir" FETCH_HEAD
775 ) &&
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 &&
780 (
781 cd "$test_count" &&
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)"
788 )
789'
790
791test_expect_success 'push sub dir/ with --rejoin from scratch' '
792 subtree_test_create_repo "$test_count" &&
793 test_create_commit "$test_count" main1 &&
794 (
795 cd "$test_count" &&
796 mkdir "sub dir" &&
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)"
805 )
806'
807
808test_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 &&
813 (
814 cd "$test_count" &&
815 git fetch ./"sub proj" HEAD &&
816 git subtree add --prefix="sub dir" FETCH_HEAD
817 ) &&
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 &&
822 (
823 cd "$test_count" &&
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)"
830 )
831'
832
833test_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 &&
838 (
839 cd "$test_count" &&
840 git fetch ./"sub proj" HEAD &&
841 git subtree add --prefix="sub dir" --squash FETCH_HEAD
842 ) &&
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 &&
847 (
848 cd "$test_count" &&
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) &&
852
853 SPLIT=$(git subtree split --prefix="sub dir" --annotate="*") &&
854 git subtree push --prefix="sub dir" --annotate="*" --rejoin --squash ./"sub proj" from-mainline &&
855
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)"
867 )
868'
869
870test_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 &&
875 (
876 cd "$test_count" &&
877 git fetch ./"sub proj" HEAD &&
878 git subtree add --prefix="sub dir" FETCH_HEAD
879 ) &&
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 &&
884 (
885 cd "$test_count" &&
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)"
892 )
893'
894
895test_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 &&
900 (
901 cd "$test_count" &&
902 git fetch ./"sub proj" HEAD &&
903 git subtree add --prefix="sub dir" FETCH_HEAD
904 ) &&
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 &&
909 (
910 cd "$test_count" &&
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) &&
918 (
919 cd ./"sub proj" &&
920 subdir_hash=$(git rev-parse HEAD) &&
921 test "$new_hash" = "$subdir_hash"
922 ) &&
923 test "$split_hash" = "$(git -C "sub proj" rev-parse --verify refs/heads/from-mainline)"
924 )
925'
926
927test_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 &&
932 (
933 cd "$test_count" &&
934 git fetch ./"sub proj" HEAD &&
935 git branch subproj-br FETCH_HEAD &&
936 git subtree add --prefix="sub dir" FETCH_HEAD
937 ) &&
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 &&
942 (
943 cd "$test_count" &&
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)"
950 )
951'
952
953test_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 &&
958 (
959 cd "$test_count" &&
960 git branch init HEAD &&
961 git fetch ./"sub proj" HEAD &&
962 git subtree add --prefix="sub dir" FETCH_HEAD
963 ) &&
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 &&
968 (
969 cd "$test_count" &&
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
973 )
974'
975
49470cd4
LS
976test_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 &&
981 (
982 cd "$test_count" &&
983 git fetch ./"sub proj" HEAD &&
984 git subtree add --prefix="sub dir" FETCH_HEAD
985 ) &&
986 test_create_commit "$test_count" "sub dir"/main-sub1 &&
987 test_create_commit "$test_count" "sub dir"/main-sub2 &&
988 (
989 cd "$test_count" &&
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"
995 )
996'
997
1762382a
PB
998test_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
1002'
1003
43711746
TZ
1004#
1005# Validity checking
1006#
b0638aa2 1007
43711746 1008test_expect_success 'make sure exactly the right set of files ends up in the subproj' '
f2bb7fef
LS
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 &&
43711746 1013 (
f2bb7fef 1014 cd "$test_count" &&
914d5125 1015 git fetch ./"sub proj" HEAD &&
43711746
TZ
1016 git subtree add --prefix="sub dir" FETCH_HEAD
1017 ) &&
f2bb7fef
LS
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 &&
43711746 1022 (
f2bb7fef 1023 cd "$test_count" &&
914d5125 1024 git fetch ./"sub proj" HEAD &&
43711746
TZ
1025 git subtree merge --prefix="sub dir" FETCH_HEAD &&
1026 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
1027 ) &&
f2bb7fef
LS
1028 test_create_commit "$test_count/sub proj" sub3 &&
1029 test_create_commit "$test_count" "sub dir"/main-sub3 &&
43711746 1030 (
f2bb7fef 1031 cd "$test_count/sub proj" &&
43711746
TZ
1032 git fetch .. subproj-br &&
1033 git merge FETCH_HEAD
1034 ) &&
f2bb7fef 1035 test_create_commit "$test_count/sub proj" sub4 &&
43711746 1036 (
f2bb7fef 1037 cd "$test_count" &&
43711746
TZ
1038 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
1039 ) &&
f2bb7fef 1040 test_create_commit "$test_count" "sub dir"/main-sub4 &&
43711746 1041 (
f2bb7fef 1042 cd "$test_count" &&
43711746
TZ
1043 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
1044 ) &&
1045 (
f2bb7fef 1046 cd "$test_count/sub proj" &&
43711746
TZ
1047 git fetch .. subproj-br &&
1048 git merge FETCH_HEAD &&
1049
6a8ad880
JN
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
43711746 1054 )
d3a04e06 1055'
b0638aa2 1056
43711746 1057test_expect_success 'make sure the subproj *only* contains commits that affect the "sub dir"' '
f2bb7fef
LS
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 &&
43711746 1062 (
f2bb7fef 1063 cd "$test_count" &&
914d5125 1064 git fetch ./"sub proj" HEAD &&
43711746
TZ
1065 git subtree add --prefix="sub dir" FETCH_HEAD
1066 ) &&
f2bb7fef
LS
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 &&
43711746 1071 (
f2bb7fef 1072 cd "$test_count" &&
914d5125 1073 git fetch ./"sub proj" HEAD &&
43711746
TZ
1074 git subtree merge --prefix="sub dir" FETCH_HEAD &&
1075 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
1076 ) &&
f2bb7fef
LS
1077 test_create_commit "$test_count/sub proj" sub3 &&
1078 test_create_commit "$test_count" "sub dir"/main-sub3 &&
43711746 1079 (
f2bb7fef 1080 cd "$test_count/sub proj" &&
43711746
TZ
1081 git fetch .. subproj-br &&
1082 git merge FETCH_HEAD
1083 ) &&
f2bb7fef 1084 test_create_commit "$test_count/sub proj" sub4 &&
43711746 1085 (
f2bb7fef 1086 cd "$test_count" &&
43711746
TZ
1087 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
1088 ) &&
f2bb7fef 1089 test_create_commit "$test_count" "sub dir"/main-sub4 &&
43711746 1090 (
f2bb7fef 1091 cd "$test_count" &&
43711746
TZ
1092 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
1093 ) &&
1094 (
f2bb7fef 1095 cd "$test_count/sub proj" &&
43711746
TZ
1096 git fetch .. subproj-br &&
1097 git merge FETCH_HEAD &&
1098
6a8ad880
JN
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
43711746 1104 )
d3a04e06 1105'
1490e154 1106
d3a04e06 1107test_expect_success 'make sure exactly the right set of files ends up in the mainline' '
f2bb7fef
LS
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 &&
43711746 1112 (
f2bb7fef 1113 cd "$test_count" &&
914d5125 1114 git fetch ./"sub proj" HEAD &&
43711746
TZ
1115 git subtree add --prefix="sub dir" FETCH_HEAD
1116 ) &&
f2bb7fef
LS
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 &&
43711746 1121 (
f2bb7fef 1122 cd "$test_count" &&
914d5125 1123 git fetch ./"sub proj" HEAD &&
43711746
TZ
1124 git subtree merge --prefix="sub dir" FETCH_HEAD &&
1125 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
1126 ) &&
f2bb7fef
LS
1127 test_create_commit "$test_count/sub proj" sub3 &&
1128 test_create_commit "$test_count" "sub dir"/main-sub3 &&
43711746 1129 (
f2bb7fef 1130 cd "$test_count/sub proj" &&
43711746
TZ
1131 git fetch .. subproj-br &&
1132 git merge FETCH_HEAD
1133 ) &&
f2bb7fef 1134 test_create_commit "$test_count/sub proj" sub4 &&
43711746 1135 (
f2bb7fef 1136 cd "$test_count" &&
43711746
TZ
1137 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
1138 ) &&
f2bb7fef 1139 test_create_commit "$test_count" "sub dir"/main-sub4 &&
43711746 1140 (
f2bb7fef 1141 cd "$test_count" &&
43711746
TZ
1142 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
1143 ) &&
1144 (
f2bb7fef 1145 cd "$test_count/sub proj" &&
43711746
TZ
1146 git fetch .. subproj-br &&
1147 git merge FETCH_HEAD
1148 ) &&
1149 (
f2bb7fef 1150 cd "$test_count" &&
914d5125 1151 git subtree pull --prefix="sub dir" ./"sub proj" HEAD &&
43711746 1152
6a8ad880
JN
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 &&
1158
1159 cat chkm chkms_sub chks_sub >expect &&
1160 git ls-files >actual &&
1161 test_cmp expect actual
1162 )
d3a04e06
DG
1163'
1164
d3a04e06 1165test_expect_success 'make sure each filename changed exactly once in the entire history' '
f2bb7fef
LS
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 &&
43711746 1170 (
f2bb7fef 1171 cd "$test_count" &&
ad6eee36 1172 git config log.date relative &&
914d5125 1173 git fetch ./"sub proj" HEAD &&
43711746
TZ
1174 git subtree add --prefix="sub dir" FETCH_HEAD
1175 ) &&
f2bb7fef
LS
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 &&
43711746 1180 (
f2bb7fef 1181 cd "$test_count" &&
914d5125 1182 git fetch ./"sub proj" HEAD &&
43711746
TZ
1183 git subtree merge --prefix="sub dir" FETCH_HEAD &&
1184 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
1185 ) &&
f2bb7fef
LS
1186 test_create_commit "$test_count/sub proj" sub3 &&
1187 test_create_commit "$test_count" "sub dir"/main-sub3 &&
43711746 1188 (
f2bb7fef 1189 cd "$test_count/sub proj" &&
43711746
TZ
1190 git fetch .. subproj-br &&
1191 git merge FETCH_HEAD
1192 ) &&
f2bb7fef 1193 test_create_commit "$test_count/sub proj" sub4 &&
43711746 1194 (
f2bb7fef 1195 cd "$test_count" &&
43711746
TZ
1196 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
1197 ) &&
f2bb7fef 1198 test_create_commit "$test_count" "sub dir"/main-sub4 &&
43711746 1199 (
f2bb7fef 1200 cd "$test_count" &&
43711746
TZ
1201 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
1202 ) &&
1203 (
f2bb7fef 1204 cd "$test_count/sub proj" &&
43711746
TZ
1205 git fetch .. subproj-br &&
1206 git merge FETCH_HEAD
1207 ) &&
1208 (
f2bb7fef 1209 cd "$test_count" &&
914d5125 1210 git subtree pull --prefix="sub dir" ./"sub proj" HEAD &&
43711746 1211
6a8ad880
JN
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 &&
43711746
TZ
1216
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.
6a8ad880
JN
1220 git log --name-only --pretty=format:"" >log &&
1221 sort <log >sorted-log &&
1222 sed "/^$/ d" sorted-log >actual &&
1223
1224 cat chkms chkm chks chkms_sub >expect-unsorted &&
1225 sort expect-unsorted >expect &&
1226 test_cmp expect actual
43711746 1227 )
d3a04e06
DG
1228'
1229
d3a04e06 1230test_expect_success 'make sure the --rejoin commits never make it into subproj' '
f2bb7fef
LS
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 &&
43711746 1235 (
f2bb7fef 1236 cd "$test_count" &&
914d5125 1237 git fetch ./"sub proj" HEAD &&
43711746
TZ
1238 git subtree add --prefix="sub dir" FETCH_HEAD
1239 ) &&
f2bb7fef
LS
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 &&
43711746 1244 (
f2bb7fef 1245 cd "$test_count" &&
914d5125 1246 git fetch ./"sub proj" HEAD &&
43711746
TZ
1247 git subtree merge --prefix="sub dir" FETCH_HEAD &&
1248 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
1249 ) &&
f2bb7fef
LS
1250 test_create_commit "$test_count/sub proj" sub3 &&
1251 test_create_commit "$test_count" "sub dir"/main-sub3 &&
43711746 1252 (
f2bb7fef 1253 cd "$test_count/sub proj" &&
43711746
TZ
1254 git fetch .. subproj-br &&
1255 git merge FETCH_HEAD
1256 ) &&
f2bb7fef 1257 test_create_commit "$test_count/sub proj" sub4 &&
43711746 1258 (
f2bb7fef 1259 cd "$test_count" &&
43711746
TZ
1260 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
1261 ) &&
f2bb7fef 1262 test_create_commit "$test_count" "sub dir"/main-sub4 &&
43711746 1263 (
f2bb7fef 1264 cd "$test_count" &&
43711746
TZ
1265 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
1266 ) &&
1267 (
f2bb7fef 1268 cd "$test_count/sub proj" &&
43711746
TZ
1269 git fetch .. subproj-br &&
1270 git merge FETCH_HEAD
1271 ) &&
1272 (
f2bb7fef 1273 cd "$test_count" &&
914d5125 1274 git subtree pull --prefix="sub dir" ./"sub proj" HEAD &&
c4566ab4 1275 test "$(git log --pretty=format:"%s" HEAD^2 | grep -i split)" = ""
43711746 1276 )
d3a04e06
DG
1277'
1278
d3a04e06 1279test_expect_success 'make sure no "git subtree" tagged commits make it into subproj' '
f2bb7fef
LS
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 &&
43711746 1284 (
f2bb7fef 1285 cd "$test_count" &&
914d5125 1286 git fetch ./"sub proj" HEAD &&
43711746
TZ
1287 git subtree add --prefix="sub dir" FETCH_HEAD
1288 ) &&
f2bb7fef
LS
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 &&
43711746 1293 (
f2bb7fef 1294 cd "$test_count" &&
914d5125 1295 git fetch ./"sub proj" HEAD &&
43711746
TZ
1296 git subtree merge --prefix="sub dir" FETCH_HEAD &&
1297 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
1298 ) &&
f2bb7fef
LS
1299 test_create_commit "$test_count/sub proj" sub3 &&
1300 test_create_commit "$test_count" "sub dir"/main-sub3 &&
43711746 1301 (
f2bb7fef 1302 cd "$test_count/sub proj" &&
43711746
TZ
1303 git fetch .. subproj-br &&
1304 git merge FETCH_HEAD
1305 ) &&
f2bb7fef 1306 test_create_commit "$test_count/sub proj" sub4 &&
43711746 1307 (
f2bb7fef 1308 cd "$test_count" &&
43711746
TZ
1309 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
1310 ) &&
f2bb7fef 1311 test_create_commit "$test_count" "sub dir"/main-sub4 &&
43711746 1312 (
f2bb7fef 1313 cd "$test_count" &&
43711746
TZ
1314 git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
1315 ) &&
1316 (
f2bb7fef 1317 cd "$test_count/sub proj" &&
43711746
TZ
1318 git fetch .. subproj-br &&
1319 git merge FETCH_HEAD
1320 ) &&
1321 (
f2bb7fef 1322 cd "$test_count" &&
914d5125 1323 git subtree pull --prefix="sub dir" ./"sub proj" HEAD &&
43711746
TZ
1324
1325 # They are meaningless to subproj since one side of the merge refers to the mainline
c4566ab4 1326 test "$(git log --pretty=format:"%s%n%b" HEAD^2 | grep "git-subtree.*:")" = ""
43711746 1327 )
d3a04e06
DG
1328'
1329
43711746
TZ
1330#
1331# A new set of tests
1332#
d3a04e06 1333
43711746 1334test_expect_success 'make sure "git subtree split" find the correct parent' '
f2bb7fef
LS
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 &&
43711746 1339 (
f2bb7fef 1340 cd "$test_count" &&
914d5125 1341 git fetch ./"sub proj" HEAD &&
43711746
TZ
1342 git subtree add --prefix="sub dir" FETCH_HEAD
1343 ) &&
f2bb7fef 1344 test_create_commit "$test_count/sub proj" sub2 &&
43711746 1345 (
f2bb7fef 1346 cd "$test_count" &&
914d5125 1347 git fetch ./"sub proj" HEAD &&
43711746
TZ
1348 git branch subproj-ref FETCH_HEAD &&
1349 git subtree merge --prefix="sub dir" FETCH_HEAD
1350 ) &&
f2bb7fef 1351 test_create_commit "$test_count" "sub dir"/main-sub1 &&
43711746 1352 (
f2bb7fef 1353 cd "$test_count" &&
43711746
TZ
1354 git subtree split --prefix="sub dir" --branch subproj-br &&
1355
1356 # at this point, the new commit parent should be subproj-ref, if it is
914d5125 1357 # not, something went wrong (the "newparent" of "HEAD~" commit should
43711746
TZ
1358 # have been sub2, but it was not, because its cache was not set to
1359 # itself)
c4566ab4 1360 test "$(git log --pretty=format:%P -1 subproj-br)" = "$(git rev-parse subproj-ref)"
43711746 1361 )
d3a04e06
DG
1362'
1363
43711746 1364test_expect_success 'split a new subtree without --onto option' '
f2bb7fef
LS
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 &&
43711746 1369 (
f2bb7fef 1370 cd "$test_count" &&
914d5125 1371 git fetch ./"sub proj" HEAD &&
43711746
TZ
1372 git subtree add --prefix="sub dir" FETCH_HEAD
1373 ) &&
f2bb7fef 1374 test_create_commit "$test_count/sub proj" sub2 &&
43711746 1375 (
f2bb7fef 1376 cd "$test_count" &&
914d5125 1377 git fetch ./"sub proj" HEAD &&
43711746
TZ
1378 git subtree merge --prefix="sub dir" FETCH_HEAD
1379 ) &&
f2bb7fef 1380 test_create_commit "$test_count" "sub dir"/main-sub1 &&
43711746 1381 (
f2bb7fef 1382 cd "$test_count" &&
43711746
TZ
1383 git subtree split --prefix="sub dir" --branch subproj-br
1384 ) &&
f2bb7fef
LS
1385 mkdir "$test_count"/"sub dir2" &&
1386 test_create_commit "$test_count" "sub dir2"/main-sub2 &&
43711746 1387 (
f2bb7fef 1388 cd "$test_count" &&
43711746
TZ
1389
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,
2e3a16b2 1392 # then the new subtree has accidentally been attached to something
43711746 1393 git subtree split --prefix="sub dir2" --branch subproj2-br &&
c4566ab4 1394 test "$(git log --pretty=format:%P -1 subproj2-br)" = ""
43711746 1395 )
d3a04e06 1396'
13ea2b5e 1397
d3a04e06 1398test_expect_success 'verify one file change per commit' '
f2bb7fef
LS
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 &&
43711746 1403 (
f2bb7fef 1404 cd "$test_count" &&
914d5125 1405 git fetch ./"sub proj" HEAD &&
43711746
TZ
1406 git branch sub1 FETCH_HEAD &&
1407 git subtree add --prefix="sub dir" sub1
1408 ) &&
f2bb7fef 1409 test_create_commit "$test_count/sub proj" sub2 &&
43711746 1410 (
f2bb7fef 1411 cd "$test_count" &&
914d5125 1412 git fetch ./"sub proj" HEAD &&
43711746
TZ
1413 git subtree merge --prefix="sub dir" FETCH_HEAD
1414 ) &&
f2bb7fef 1415 test_create_commit "$test_count" "sub dir"/main-sub1 &&
43711746 1416 (
f2bb7fef 1417 cd "$test_count" &&
43711746
TZ
1418 git subtree split --prefix="sub dir" --branch subproj-br
1419 ) &&
f2bb7fef
LS
1420 mkdir "$test_count"/"sub dir2" &&
1421 test_create_commit "$test_count" "sub dir2"/main-sub2 &&
43711746 1422 (
f2bb7fef 1423 cd "$test_count" &&
43711746
TZ
1424 git subtree split --prefix="sub dir2" --branch subproj2-br &&
1425
f1cd2d93
LS
1426 git log --format="%H" >commit-list &&
1427 while read commit
1428 do
1429 git log -n1 --format="" --name-only "$commit" >file-list &&
1430 test_line_count -le 1 file-list || return 1
1431 done <commit-list
b0638aa2 1432 )
d3a04e06
DG
1433'
1434
43711746 1435test_expect_success 'push split to subproj' '
f2bb7fef
LS
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 &&
43711746 1440 (
f2bb7fef 1441 cd "$test_count" &&
914d5125 1442 git fetch ./"sub proj" HEAD &&
43711746
TZ
1443 git subtree add --prefix="sub dir" FETCH_HEAD
1444 ) &&
f2bb7fef
LS
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 &&
43711746 1449 (
f2bb7fef 1450 cd $test_count/"sub proj" &&
f7004069
LS
1451 git branch sub-branch-1 &&
1452 cd .. &&
914d5125 1453 git fetch ./"sub proj" HEAD &&
43711746
TZ
1454 git subtree merge --prefix="sub dir" FETCH_HEAD
1455 ) &&
f2bb7fef 1456 test_create_commit "$test_count" "sub dir"/main-sub3 &&
f7004069 1457 (
f2bb7fef 1458 cd "$test_count" &&
f7004069
LS
1459 git subtree push ./"sub proj" --prefix "sub dir" sub-branch-1 &&
1460 cd ./"sub proj" &&
1461 git checkout sub-branch-1 &&
db6952b2 1462 test "$(last_commit_subject)" = "sub dir/main-sub3"
43711746 1463 )
5b6ab38b
AS
1464'
1465
933cfeb9
DW
1466#
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
1473#
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)
1477#
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
1483# set of commits.
1484#
1485
933cfeb9 1486test_expect_success 'subtree descendant check' '
f2bb7fef
LS
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 &&
933cfeb9 1490 (
f2bb7fef 1491 cd "$test_count" &&
933cfeb9
DW
1492 git branch branch
1493 ) &&
f2bb7fef
LS
1494 test_create_commit "$test_count" folder_subtree/0 &&
1495 test_create_commit "$test_count" folder_subtree/b &&
c576868e 1496 cherry=$(cd "$test_count" && git rev-parse HEAD) &&
933cfeb9 1497 (
f2bb7fef 1498 cd "$test_count" &&
933cfeb9
DW
1499 git checkout branch
1500 ) &&
f2bb7fef 1501 test_create_commit "$test_count" commit_on_branch &&
933cfeb9 1502 (
f2bb7fef 1503 cd "$test_count" &&
933cfeb9 1504 git cherry-pick $cherry &&
914d5125 1505 git checkout $defaultBranch &&
933cfeb9
DW
1506 git merge -m "merge should be kept on subtree" branch &&
1507 git branch no_subtree_work_branch
1508 ) &&
f2bb7fef 1509 test_create_commit "$test_count" folder_subtree/d &&
933cfeb9 1510 (
f2bb7fef 1511 cd "$test_count" &&
933cfeb9
DW
1512 git checkout no_subtree_work_branch
1513 ) &&
f2bb7fef 1514 test_create_commit "$test_count" not_a_subtree_change &&
933cfeb9 1515 (
f2bb7fef 1516 cd "$test_count" &&
914d5125 1517 git checkout $defaultBranch &&
933cfeb9
DW
1518 git merge -m "merge should be skipped on subtree" no_subtree_work_branch &&
1519
914d5125 1520 git subtree split --prefix folder_subtree/ --branch subtree_tip $defaultBranch &&
933cfeb9 1521 git subtree split --prefix folder_subtree/ --branch subtree_branch branch &&
c4566ab4 1522 test $(git rev-list --count subtree_tip..subtree_branch) = 0
933cfeb9
DW
1523 )
1524'
1525
d3a04e06 1526test_done