1- #! /bin/bash -x
1+ #! /bin/bash
22. shellopts.sh
33set -e
44
@@ -8,6 +8,50 @@ create()
88 git add " $1 "
99}
1010
11+ check ()
12+ {
13+ echo
14+ echo " check:" " $@ "
15+ if " $@ " ; then
16+ echo ok
17+ return 0
18+ else
19+ echo FAILED
20+ exit 1
21+ fi
22+ }
23+
24+ check_equal ()
25+ {
26+ echo
27+ echo " check a:" " $1 "
28+ echo " b:" " $2 "
29+ if [ " $1 " = " $2 " ]; then
30+ return 0
31+ else
32+ echo FAILED
33+ exit 1
34+ fi
35+ }
36+
37+ fixnl ()
38+ {
39+ t=" "
40+ while read x; do
41+ t=" $t$x "
42+ done
43+ echo $t
44+ }
45+
46+ multiline ()
47+ {
48+ while read x; do
49+ set -- $x
50+ for d in " $@ " ; do
51+ echo " $d "
52+ done
53+ done
54+ }
1155
1256rm -rf mainline subproj
1357mkdir mainline subproj
@@ -19,6 +63,7 @@ create sub1
1963git commit -m ' sub1'
2064git branch sub1
2165git branch -m master subproj
66+ check true
2267
2368create sub2
2469git commit -m ' sub2'
@@ -86,7 +131,33 @@ git branch split3 FETCH_HEAD
86131git merge FETCH_HEAD
87132git branch subproj-merge-split3
88133
134+ chkm=" main4 main6"
135+ chkms=" main-sub10 main-sub5 main-sub7 main-sub8"
136+ chkms_sub=$( echo $chkms | multiline | sed ' s,^,subdir/,' | fixnl)
137+ chks=" sub1 sub2 sub3 sub9"
138+ chks_sub=$( echo $chks | multiline | sed ' s,^,subdir/,' | fixnl)
139+
140+ # make sure exactly the right set of files ends up in the subproj
141+ subfiles=$( git ls-files | fixnl)
142+ check_equal " $subfiles " " $chkms $chks "
143+
144+ # make sure the subproj history *only* contains commits that affect the subdir.
145+ allchanges=$( git log --name-only --pretty=format:' ' | sort | fixnl)
146+ check_equal " $allchanges " " $chkms $chks "
147+
89148cd ../mainline
90149git fetch ../subproj subproj-merge-split3
91150git branch subproj-merge-split3 FETCH_HEAD
92151git subtree pull --prefix=subdir ../subproj subproj-merge-split3
152+
153+ # make sure exactly the right set of files ends up in the mainline
154+ mainfiles=$( git ls-files | fixnl)
155+ check_equal " $mainfiles " " $chkm $chkms_sub $chks_sub "
156+
157+ # make sure each filename changed exactly once in the entire history.
158+ # 'main-sub??' and '/subdir/main-sub??' both change, because those are the
159+ # changes that were split into their own history. And 'subdir/sub??' never
160+ # change, since they were *only* changed in the subtree branch.
161+ allchanges=$( git log --name-only --pretty=format:' ' | sort | fixnl)
162+ check_equal " $allchanges " " $chkm $chkms $chks $chkms_sub "
163+
0 commit comments