27 echo "check: NOT " "$@"
40 echo "check a:" "{$1}"
42 if [ "$1" = "$2" ]; then
71 git
reset --hard HEAD~
76 git log
--pretty=format
:%s
-1
79 rm -rf mainline subproj
80 mkdir mainline subproj
88 git branch
-m master subproj
102 git commit
-m 'main4'
103 git branch
-m master mainline
106 git fetch ..
/subproj sub1
107 git branch sub1 FETCH_HEAD
109 # check if --message works for add
110 check_not git subtree merge
--prefix=subdir sub1
111 check_not git subtree pull
--prefix=subdir ..
/subproj sub1
112 git subtree add
--prefix=subdir
--message="Added subproject" sub1
113 check_equal
"$(last_commit_message)" "Added subproject"
116 # check if --message works as -m and --prefix as -P
117 git subtree add
-P subdir
-m "Added subproject using git subtree" sub1
118 check_equal
"$(last_commit_message)" "Added subproject using git subtree"
121 # check if --message works with squash too
122 git subtree add
-P subdir
-m "Added subproject with squash" --squash sub1
123 check_equal
"$(last_commit_message)" "Added subproject with squash"
126 git subtree add
--prefix=subdir
/ FETCH_HEAD
127 check_equal
"$(last_commit_message)" "Add 'subdir/' from commit '$(git rev-parse sub1)'"
129 # this shouldn't actually do anything, since FETCH_HEAD is already a parent
130 git merge
-m 'merge -s -ours' -s ours FETCH_HEAD
132 create subdir
/main-sub5
133 git commit
-m 'main-sub5'
136 git commit
-m 'main6 boring'
138 create subdir
/main-sub7
139 git commit
-m 'main-sub7'
141 git fetch ..
/subproj sub2
142 git branch sub2 FETCH_HEAD
144 # check if --message works for merge
145 git subtree merge
--prefix=subdir
-m "Merged changes from subproject" sub2
146 check_equal
"$(last_commit_message)" "Merged changes from subproject"
149 # check if --message for merge works with squash too
150 git subtree merge
--prefix subdir
-m "Merged changes from subproject using squash" --squash sub2
151 check_equal
"$(last_commit_message)" "Merged changes from subproject using squash"
154 git subtree merge
--prefix=subdir FETCH_HEAD
156 check_equal
"$(last_commit_message)" "Merge commit '$(git rev-parse sub2)' into mainline"
158 # Check that prefix argument is required for split (exits with warning and exit status = 1)
159 ! result
=$
(git subtree
split 2>&1)
160 check_equal
"You must provide the --prefix option." "$result"
162 # Check that the <prefix> exists for a split.
163 ! result
=$
(git subtree
split --prefix=non-existent-directory
2>&1)
164 check_equal
"'non-existent-directory' does not exist; use 'git subtree add'" \
167 # check if --message works for split+rejoin
168 spl1
=$
(git subtree
split --annotate='*' --prefix subdir
--onto FETCH_HEAD
--message "Split & rejoin" --rejoin)
170 git branch spl1
"$spl1"
171 check_equal
"$(last_commit_message)" "Split & rejoin"
174 # check split with --branch
175 git subtree
split --annotate='*' --prefix subdir
--onto FETCH_HEAD
--branch splitbr1
176 check_equal
"$(git rev-parse splitbr1)" "$spl1"
178 # check split with --branch for an existing branch
179 git branch splitbr2 sub1
180 git subtree
split --annotate='*' --prefix subdir
--onto FETCH_HEAD
--branch splitbr2
181 check_equal
"$(git rev-parse splitbr2)" "$spl1"
183 # check split with --branch for an incompatible branch
184 result
=$
(git subtree
split --prefix subdir
--onto FETCH_HEAD
--branch subdir ||
echo "caught error")
185 check_equal
"$result" "caught error"
188 git subtree
split --annotate='*' --prefix subdir
--onto FETCH_HEAD
--rejoin
189 check_equal
"$(last_commit_message)" "Split 'subdir/' into commit '$spl1'"
191 create subdir
/main-sub8
192 git commit
-m 'main-sub8'
195 git fetch ..
/mainline spl1
196 git branch spl1 FETCH_HEAD
203 split2
=$
(git subtree
split --annotate='*' --prefix subdir
/ --rejoin)
204 git branch split2
"$split2"
206 create subdir
/main-sub10
207 git commit
-m 'main-sub10'
209 spl3
=$
(git subtree
split --annotate='*' --prefix subdir
--rejoin)
210 git branch spl3
"$spl3"
213 git fetch ..
/mainline spl3
214 git branch spl3 FETCH_HEAD
216 git branch subproj-merge-spl3
219 chkms
="main-sub10 main-sub5 main-sub7 main-sub8"
220 chkms_sub
=$
(echo $chkms | multiline |
sed 's,^,subdir/,' | fixnl
)
221 chks
="sub1 sub2 sub3 sub9"
222 chks_sub
=$
(echo $chks | multiline |
sed 's,^,subdir/,' | fixnl
)
224 # make sure exactly the right set of files ends up in the subproj
225 subfiles
=$
(git ls-files | fixnl
)
226 check_equal
"$subfiles" "$chkms $chks"
228 # make sure the subproj history *only* contains commits that affect the subdir.
229 allchanges
=$
(git log
--name-only --pretty=format
:'' |
sort | fixnl
)
230 check_equal
"$allchanges" "$chkms $chks"
233 git fetch ..
/subproj subproj-merge-spl3
234 git branch subproj-merge-spl3 FETCH_HEAD
235 git subtree pull
--prefix=subdir ..
/subproj subproj-merge-spl3
237 # make sure exactly the right set of files ends up in the mainline
238 mainfiles
=$
(git ls-files | fixnl
)
239 check_equal
"$mainfiles" "$chkm $chkms_sub $chks_sub"
241 # make sure each filename changed exactly once in the entire history.
242 # 'main-sub??' and '/subdir/main-sub??' both change, because those are the
243 # changes that were split into their own history. And 'subdir/sub??' never
244 # change, since they were *only* changed in the subtree branch.
245 allchanges
=$
(git log
--name-only --pretty=format
:'' |
sort | fixnl
)
246 check_equal
"$allchanges" "$(echo $chkms $chkm $chks $chkms_sub | multiline | sort | fixnl)"
248 # make sure the --rejoin commits never make it into subproj
249 check_equal
"$(git log --pretty=format:'%s' HEAD^2 | grep -i split)" ""
251 # make sure no 'git subtree' tagged commits make it into subproj. (They're
252 # meaningless to subproj since one side of the merge refers to the mainline)
253 check_equal
"$(git log --pretty=format:'%s%n%b' HEAD^2 | grep 'git-subtree.*:')" ""
256 # check if split can find proper base without --onto
257 # prepare second pair of repositories
265 git commit
-m "main1"
275 git fetch ..
/sub master
276 git branch sub2 FETCH_HEAD
277 git subtree add
--prefix subdir sub2
284 git fetch ..
/sub master
285 git branch sub3 FETCH_HEAD
286 git subtree merge
--prefix subdir sub3
288 create subdir
/main-sub4
289 git commit
-m "main-sub4"
290 git subtree
split --prefix subdir
--branch mainsub4
292 # at this point, the new commit's parent should be sub3
293 # if it's not, something went wrong (the "newparent" of "master~" commit should have been sub3,
294 # but it wasn't, because it's cache was not set to itself)
295 check_equal
"$(git log --pretty=format:%P -1 mainsub4)" "$(git rev-parse sub3)"
298 create subdir
2/main-sub5
299 git commit
-m "main-sub5"
300 git subtree
split --prefix subdir2
--branch mainsub5
302 # also test that we still can split out an entirely new subtree
303 # if the parent of the first commit in the tree isn't empty,
304 # then the new subtree has accidently been attached to something
305 check_equal
"$(git log --pretty=format:%P -1 mainsub5)" ""
308 # make sure no patch changes more than one file. The original set of commits
309 # changed only one file each. A multi-file change would imply that we pruned
310 # commits too aggressively.
319 elif [ "$x" = "commit:" ]; then
320 if [ -n "$commit" ]; then
332 git log
--pretty=format
:'commit: %H' | joincommits |
333 ( while read commit a b
; do
334 echo "Verifying commit $commit"