5
5
#
6
6
test_description=' Basic porcelain support for subtrees
7
7
8
- This test verifies the basic operation of the merge , pull, add
8
+ This test verifies the basic operation of the add , pull, merge
9
9
and split subcommands of git subtree.
10
10
'
11
11
@@ -20,7 +20,6 @@ create()
20
20
git add " $1 "
21
21
}
22
22
23
-
24
23
check_equal ()
25
24
{
26
25
test_debug ' echo'
@@ -38,6 +37,30 @@ undo()
38
37
git reset --hard HEAD~
39
38
}
40
39
40
+ # Make sure no patch changes more than one file.
41
+ # The original set of commits changed only one file each.
42
+ # A multi-file change would imply that we pruned commits
43
+ # too aggressively.
44
+ join_commits ()
45
+ {
46
+ commit=
47
+ all=
48
+ while read x y; do
49
+ if [ -z " $x " ]; then
50
+ continue
51
+ elif [ " $x " = " commit:" ]; then
52
+ if [ -n " $commit " ]; then
53
+ echo " $commit $all "
54
+ all=
55
+ fi
56
+ commit=" $y "
57
+ else
58
+ all=" $all $y "
59
+ fi
60
+ done
61
+ echo " $commit $all "
62
+ }
63
+
41
64
last_commit_message ()
42
65
{
43
66
git log --pretty=format:%s -1
@@ -123,9 +146,11 @@ test_expect_success 'add subproj to mainline' '
123
146
check_equal ' ' "$(last_commit_message)"' ' "Add ' " 'sub dir/'" ' from commit ' " '" ' ' ' "$(git rev-parse sub1)"' ' ' " '" ' "
124
147
'
125
148
126
- # this shouldn't actually do anything, since FETCH_HEAD is already a parent
127
- test_expect_success ' merge fetched subproj' '
128
- git merge -m "merge -s -ours" -s ours FETCH_HEAD
149
+ test_expect_success ' merge the added subproj again, should do nothing' '
150
+ # this shouldn not actually do anything, since FETCH_HEAD
151
+ # is already a parent
152
+ result=$(git merge -s ours -m "merge -s -ours" FETCH_HEAD) &&
153
+ check_equal "${result}" "Already up-to-date."
129
154
'
130
155
131
156
test_expect_success ' add main-sub5' '
@@ -167,7 +192,7 @@ test_expect_success 'merge new subproj history into subdir' '
167
192
undo
168
193
'
169
194
170
- test_expect_success ' Check that prefix argument is required for split ' '
195
+ test_expect_success ' split requires option --prefix ' '
171
196
echo "You must provide the --prefix option." > expected &&
172
197
test_must_fail git subtree split > actual 2>&1 &&
173
198
test_debug "printf ' " '" ' expected: ' " '" ' " &&
@@ -178,15 +203,15 @@ test_expect_success 'Check that prefix argument is required for split' '
178
203
rm -f expected actual
179
204
'
180
205
181
- test_expect_success ' Check that the <prefix> exists for a split ' '
182
- echo "' " ' " ' non-existent-directory' " ' " ' " does not exist\ ; use " ' " ' " ' git subtree add' " ' " ' " > expected &&
206
+ test_expect_success ' split requires path given by option --prefix must exist ' '
207
+ echo "' \' ' non-existent-directory' \' ' does not exist; use ' \' ' git subtree add' \' ' " > expected &&
183
208
test_must_fail git subtree split --prefix=non-existent-directory > actual 2>&1 &&
184
209
test_debug "printf ' " '" ' expected: ' " '" ' " &&
185
210
test_debug "cat expected" &&
186
211
test_debug "printf ' " '" ' actual: ' " '" ' " &&
187
212
test_debug "cat actual" &&
188
- test_cmp expected actual
189
- # rm -f expected actual
213
+ test_cmp expected actual &&
214
+ rm -f expected actual
190
215
'
191
216
192
217
test_expect_success ' check if --message works for split+rejoin' '
@@ -279,18 +304,22 @@ test_expect_success 'merge split into subproj' '
279
304
280
305
chkm=" main4
281
306
main6"
307
+
282
308
chkms=" main-sub10
283
309
main-sub5
284
310
main-sub7
285
311
main-sub8"
312
+
286
313
chkms_sub=$( cat << TXT | sed 's,^,sub dir/,'
287
314
$chkms
288
315
TXT
289
316
)
317
+
290
318
chks=" sub1
291
319
sub2
292
320
sub3
293
321
sub9"
322
+
294
323
chks_sub=$( cat << TXT | sed 's,^,sub dir/,'
295
324
$chks
296
325
TXT
@@ -301,6 +330,7 @@ test_expect_success 'make sure exactly the right set of files ends up in the sub
301
330
check_equal "$subfiles" "$chkms
302
331
$chks"
303
332
'
333
+
304
334
test_expect_success ' make sure the subproj history *only* contains commits that affect the subdir' '
305
335
allchanges=' ' "$(git log --name-only --pretty=format:' " ''" ' | sort | sed "/^$/d")"' ' &&
306
336
check_equal "$allchanges" "$chkms
@@ -324,26 +354,27 @@ $chks_sub"
324
354
'
325
355
326
356
test_expect_success ' make sure each filename changed exactly once in the entire history' '
327
- # main-sub?? and /subdir /main-sub?? both change, because those are the
328
- # changes that were split into their own history. And subdir /sub?? never
357
+ # main-sub?? and sub dir /main-sub?? both change, because those are the
358
+ # changes that were split into their own history. And sub dir /sub?? never
329
359
# change, since they were *only* changed in the subtree branch.
330
360
allchanges=' ' "$(git log --name-only --pretty=format:' " ''" ' | sort | sed "/^$/d")"' ' &&
331
- check_equal "$allchanges" ' ' "$(cat <<TXT | sort
361
+ expected= ' ' "$(cat <<TXT | sort
332
362
$chkms
333
363
$chkm
334
364
$chks
335
365
$chkms_sub
336
366
TXT
337
- )"' '
367
+ )"' ' &&
368
+ check_equal "$allchanges" "$expected"
338
369
'
339
370
340
371
test_expect_success ' make sure the --rejoin commits never make it into subproj' '
341
- check_equal ' ' "$(git log --pretty=format:' " '%s' " ' HEAD^2 | grep -i split)"' ' ""
372
+ check_equal "$(git log --pretty=format:"%s" HEAD^2 | grep -i split)" ""
342
373
'
343
374
344
375
test_expect_success ' make sure no "git subtree" tagged commits make it into subproj' '
345
376
# They are meaningless to subproj since one side of the merge refers to the mainline
346
- check_equal ' ' "$(git log --pretty=format:' " ' %s%n%b' " ' HEAD^2 | grep "git-subtree.*:")"' ' ""
377
+ check_equal "$(git log --pretty=format:" %s%n%b" HEAD^2 | grep "git-subtree.*:")" ""
347
378
'
348
379
349
380
# prepare second pair of repositories
@@ -408,13 +439,13 @@ test_expect_success 'split for main-sub4 without --onto' '
408
439
git subtree split --prefix "sub dir" --branch mainsub4
409
440
'
410
441
411
- # at this point, the new commit parent should be sub3 if it is not,
442
+ # At this point, the new commit parent should be sub3. If it is not,
412
443
# something went wrong (the "newparent" of "master~" commit should
413
444
# have been sub3, but it was not, because its cache was not set to
414
- # itself)
445
+ # itself).
415
446
416
447
test_expect_success ' check that the commit parent is sub3' '
417
- check_equal ' ' "$(git log --pretty=format:%P -1 mainsub4)"' ' ' ' "$(git rev-parse sub3)"' '
448
+ check_equal "$(git log --pretty=format:%P -1 mainsub4)" "$(git rev-parse sub3)"
418
449
'
419
450
420
451
test_expect_success ' add main-sub5' '
@@ -431,52 +462,28 @@ test_expect_success 'split for main-sub5 without --onto' '
431
462
check_equal ' ' "$(git log --pretty=format:%P -1 mainsub5)"' ' ""
432
463
'
433
464
434
- # make sure no patch changes more than one file. The original set of commits
435
- # changed only one file each. A multi-file change would imply that we pruned
436
- # commits too aggressively.
437
- joincommits ()
438
- {
439
- commit=
440
- all=
441
- while read x y; do
442
- # echo "{$x}" >&2
443
- if [ -z " $x " ]; then
444
- continue
445
- elif [ " $x " = " commit:" ]; then
446
- if [ -n " $commit " ]; then
447
- echo " $commit $all "
448
- all=
449
- fi
450
- commit=" $y "
451
- else
452
- all=" $all $y "
453
- fi
454
- done
455
- echo " $commit $all "
456
- }
457
-
458
465
test_expect_success ' verify one file change per commit' '
459
466
x= &&
460
- list=' ' "$(git log --pretty=format:' " 'commit: %H'" ' | joincommits )"' ' &&
467
+ list=' ' "$(git log --pretty=format:' " 'commit: %H'" ' | join_commits )"' ' &&
461
468
# test_debug "echo HERE" &&
462
469
# test_debug "echo ' ' "$list"' ' " &&
463
- ( git log --pretty=format:' " 'commit: %H'" ' | joincommits |
470
+ git log --pretty=format:' " 'commit: %H'" ' | join_commits |
464
471
( while read commit a b; do
465
472
test_debug "echo Verifying commit "' ' "$commit"' '
466
473
test_debug "echo a: "' ' "$a"' '
467
474
test_debug "echo b: "' ' "$b"' '
468
475
check_equal "$b" ""
469
476
x=1
470
477
done
471
- check_equal "$x" 1
472
- ))
478
+ check_equal "$x" "1"
479
+ )
473
480
'
474
481
475
482
# test push
476
483
477
484
cd ../..
478
485
479
- mkdir test-push
486
+ mkdir -p test-push
480
487
481
488
cd test-push
482
489
0 commit comments