@matheusbsbs / matheus-bagliano / commits / 13ea2b5e07
Fork 0

added tests for recent changes

Jakub Suder committed Jan 12, 2010 at 23:04 UTC 13ea2b5e0786e70780f91637fb82ca18dd03a730
1 file changed +104 -2
test.sh
+104 -2
@@ -53,6 +53,16 @@ multiline()
53 done
54 }
55
56 +undo()
57 +{
58 + git reset --hard HEAD~
59 +}
60 +
61 +last_commit_message()
62 +{
63 + git log --format=%s -1
64 +}
65 +
66 rm -rf mainline subproj
67 mkdir mainline subproj
68
@@ -82,7 +92,24 @@ git branch subdir
92
93 git fetch ../subproj sub1
94 git branch sub1 FETCH_HEAD
95 +
96 +# check if --message works for add
97 +git subtree add --prefix=subdir --message="Added subproject" sub1
98 +check_equal "$(last_commit_message)" "Added subproject"
99 +undo
100 +
101 +# check if --message works as -m and --prefix as -P
102 +git subtree add -P subdir -m "Added subproject using git subtree" sub1
103 +check_equal "$(last_commit_message)" "Added subproject using git subtree"
104 +undo
105 +
106 +# check if --message works with squash too
107 +git subtree add -P subdir -m "Added subproject with squash" --squash sub1
108 +check_equal "$(last_commit_message)" "Added subproject with squash"
109 +undo
110 +
111 git subtree add --prefix=subdir/ FETCH_HEAD
112 +check_equal "$(last_commit_message)" "Add 'subdir/' from commit '$(git rev-parse sub1)'"
113
114 # this shouldn't actually do anything, since FETCH_HEAD is already a parent
115 git merge -m 'merge -s -ours' -s ours FETCH_HEAD
@@ -98,13 +125,44 @@ git commit -m 'main-sub7'
125
126 git fetch ../subproj sub2
127 git branch sub2 FETCH_HEAD
128 +
129 +# check if --message works for merge
130 +git subtree merge --prefix=subdir -m "Merged changes from subproject" sub2
131 +check_equal "$(last_commit_message)" "Merged changes from subproject"
132 +undo
133 +
134 +# check if --message for merge works with squash too
135 +git subtree merge --prefix subdir -m "Merged changes from subproject using squash" --squash sub2
136 +check_equal "$(last_commit_message)" "Merged changes from subproject using squash"
137 +undo
138 +
139 git subtree merge --prefix=subdir FETCH_HEAD
140 git branch pre-split
141 +check_equal "$(last_commit_message)" "Merge commit '$(git rev-parse sub2)' into mainline"
142
104 -spl1=$(git subtree split --annotate='*' \
105 - --prefix subdir --onto FETCH_HEAD --rejoin)
143 +# check if --message works for split+rejoin
144 +spl1=$(git subtree split --annotate='*' --prefix subdir --onto FETCH_HEAD --message "Split & rejoin" --rejoin)
145 echo "spl1={$spl1}"
146 git branch spl1 "$spl1"
147 +check_equal "$(last_commit_message)" "Split & rejoin"
148 +undo
149 +
150 +# check split with --branch
151 +git subtree split --annotate='*' --prefix subdir --onto FETCH_HEAD --branch splitbr1
152 +check_equal "$(git rev-parse splitbr1)" "$spl1"
153 +
154 +# check split with --branch for an existing branch
155 +git branch splitbr2 sub1
156 +git subtree split --annotate='*' --prefix subdir --onto FETCH_HEAD --branch splitbr2
157 +check_equal "$(git rev-parse splitbr2)" "$spl1"
158 +
159 +# check split with --branch for an incompatible branch
160 +result=$(git subtree split --prefix subdir --onto FETCH_HEAD --branch subdir || echo "caught error")
161 +check_equal "$result" "caught error"
162 +
163 +
164 +git subtree split --annotate='*' --prefix subdir --onto FETCH_HEAD --rejoin
165 +check_equal "$(last_commit_message)" "Split 'subdir/' into commit '$spl1'"
166
167 create subdir/main-sub8
168 git commit -m 'main-sub8'
@@ -170,6 +228,50 @@ check_equal "$(git log --pretty=format:'%s' HEAD^2 | grep -i split)" ""
228 # meaningless to subproj since one side of the merge refers to the mainline)
229 check_equal "$(git log --pretty=format:'%s%n%b' HEAD^2 | grep 'git-subtree.*:')" ""
230
231 +
232 +# check if split can find proper base without --onto
233 +# prepare second pair of repositories
234 +mkdir test2
235 +cd test2
236 +
237 +mkdir main
238 +cd main
239 +git init
240 +create main1
241 +git commit -m "main1"
242 +
243 +cd ..
244 +mkdir sub
245 +cd sub
246 +git init
247 +create sub2
248 +git commit -m "sub2"
249 +
250 +cd ../main
251 +git fetch ../sub master
252 +git branch sub2 FETCH_HEAD
253 +git subtree add --prefix subdir sub2
254 +
255 +cd ../sub
256 +create sub3
257 +git commit -m "sub3"
258 +
259 +cd ../main
260 +git fetch ../sub master
261 +git branch sub3 FETCH_HEAD
262 +git subtree merge --prefix subdir sub3
263 +
264 +create subdir/main-sub4
265 +git commit -m "main-sub4"
266 +git subtree split --prefix subdir --branch mainsub4
267 +
268 +# at this point, the new commit's parent should be sub3
269 +# if it's not, something went wrong (the "newparent" of "master~" commit should have been sub3,
270 +# but it wasn't, because it's cache was not set to itself)
271 +check_equal "$(git log --format=%P -1 mainsub4)" "$(git rev-parse sub3)"
272 +
273 +
274 +
275 # make sure no patch changes more than one file. The original set of commits
276 # changed only one file each. A multi-file change would imply that we pruned
277 # commits too aggressively.