55#
66test_description=' Basic porcelain support for subtrees
77
8- This test verifies the basic operation of the merge , pull, add
8+ This test verifies the basic operation of the add , pull, merge
99and split subcommands of git subtree.
1010'
1111
@@ -20,7 +20,6 @@ create()
2020 git add " $1 "
2121}
2222
23-
2423check_equal ()
2524{
2625 test_debug ' echo'
@@ -38,6 +37,30 @@ undo()
3837 git reset --hard HEAD~
3938}
4039
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+
4164last_commit_message ()
4265{
4366 git log --pretty=format:%s -1
@@ -123,9 +146,11 @@ test_expect_success 'add subproj to mainline' '
123146 check_equal ' ' "$(last_commit_message)"' ' "Add ' " 'sub dir/'" ' from commit ' " '" ' ' ' "$(git rev-parse sub1)"' ' ' " '" ' "
124147'
125148
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."
129154'
130155
131156test_expect_success ' add main-sub5' '
@@ -167,7 +192,7 @@ test_expect_success 'merge new subproj history into subdir' '
167192 undo
168193'
169194
170- test_expect_success ' Check that prefix argument is required for split ' '
195+ test_expect_success ' split requires option --prefix ' '
171196 echo "You must provide the --prefix option." > expected &&
172197 test_must_fail git subtree split > actual 2>&1 &&
173198 test_debug "printf ' " '" ' expected: ' " '" ' " &&
@@ -178,15 +203,15 @@ test_expect_success 'Check that prefix argument is required for split' '
178203 rm -f expected actual
179204'
180205
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 &&
183208 test_must_fail git subtree split --prefix=non-existent-directory > actual 2>&1 &&
184209 test_debug "printf ' " '" ' expected: ' " '" ' " &&
185210 test_debug "cat expected" &&
186211 test_debug "printf ' " '" ' actual: ' " '" ' " &&
187212 test_debug "cat actual" &&
188- test_cmp expected actual
189- # rm -f expected actual
213+ test_cmp expected actual &&
214+ rm -f expected actual
190215'
191216
192217test_expect_success ' check if --message works for split+rejoin' '
@@ -279,18 +304,22 @@ test_expect_success 'merge split into subproj' '
279304
280305chkm=" main4
281306main6"
307+
282308chkms=" main-sub10
283309main-sub5
284310main-sub7
285311main-sub8"
312+
286313chkms_sub=$( cat << TXT | sed 's,^,sub dir/,'
287314$chkms
288315TXT
289316)
317+
290318chks=" sub1
291319sub2
292320sub3
293321sub9"
322+
294323chks_sub=$( cat << TXT | sed 's,^,sub dir/,'
295324$chks
296325TXT
@@ -301,6 +330,7 @@ test_expect_success 'make sure exactly the right set of files ends up in the sub
301330 check_equal "$subfiles" "$chkms
302331$chks"
303332'
333+
304334test_expect_success ' make sure the subproj history *only* contains commits that affect the subdir' '
305335 allchanges=' ' "$(git log --name-only --pretty=format:' " ''" ' | sort | sed "/^$/d")"' ' &&
306336 check_equal "$allchanges" "$chkms
@@ -324,26 +354,27 @@ $chks_sub"
324354'
325355
326356test_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
329359 # change, since they were *only* changed in the subtree branch.
330360 allchanges=' ' "$(git log --name-only --pretty=format:' " ''" ' | sort | sed "/^$/d")"' ' &&
331- check_equal "$allchanges" ' ' "$(cat <<TXT | sort
361+ expected= ' ' "$(cat <<TXT | sort
332362$chkms
333363$chkm
334364$chks
335365$chkms_sub
336366TXT
337- )"' '
367+ )"' ' &&
368+ check_equal "$allchanges" "$expected"
338369'
339370
340371test_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)" ""
342373'
343374
344375test_expect_success ' make sure no "git subtree" tagged commits make it into subproj' '
345376 # 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.*:")" ""
347378'
348379
349380# prepare second pair of repositories
@@ -408,13 +439,13 @@ test_expect_success 'split for main-sub4 without --onto' '
408439 git subtree split --prefix "sub dir" --branch mainsub4
409440'
410441
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,
412443# something went wrong (the "newparent" of "master~" commit should
413444# have been sub3, but it was not, because its cache was not set to
414- # itself)
445+ # itself).
415446
416447test_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)"
418449'
419450
420451test_expect_success ' add main-sub5' '
@@ -431,52 +462,28 @@ test_expect_success 'split for main-sub5 without --onto' '
431462 check_equal ' ' "$(git log --pretty=format:%P -1 mainsub5)"' ' ""
432463'
433464
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-
458465test_expect_success ' verify one file change per commit' '
459466 x= &&
460- list=' ' "$(git log --pretty=format:' " 'commit: %H'" ' | joincommits )"' ' &&
467+ list=' ' "$(git log --pretty=format:' " 'commit: %H'" ' | join_commits )"' ' &&
461468# test_debug "echo HERE" &&
462469# test_debug "echo ' ' "$list"' ' " &&
463- ( git log --pretty=format:' " 'commit: %H'" ' | joincommits |
470+ git log --pretty=format:' " 'commit: %H'" ' | join_commits |
464471 ( while read commit a b; do
465472 test_debug "echo Verifying commit "' ' "$commit"' '
466473 test_debug "echo a: "' ' "$a"' '
467474 test_debug "echo b: "' ' "$b"' '
468475 check_equal "$b" ""
469476 x=1
470477 done
471- check_equal "$x" 1
472- ))
478+ check_equal "$x" "1"
479+ )
473480'
474481
475482# test push
476483
477484cd ../..
478485
479- mkdir test-push
486+ mkdir -p test-push
480487
481488cd test-push
482489
0 commit comments