Blob


1 #!/bin/sh
2 #
3 # Copyright (c) 2019 Stefan Sperling <stsp@openbsd.org>
4 #
5 # Permission to use, copy, modify, and distribute this software for any
6 # purpose with or without fee is hereby granted, provided that the above
7 # copyright notice and this permission notice appear in all copies.
8 #
9 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 . ./common.sh
19 function test_integrate_basic {
20 local testroot=`test_init integrate_basic`
22 (cd $testroot/repo && git checkout -q -b newbranch)
23 echo "modified delta on branch" > $testroot/repo/gamma/delta
24 git_commit $testroot/repo -m "committing to delta on newbranch"
26 echo "modified alpha on branch" > $testroot/repo/alpha
27 (cd $testroot/repo && git rm -q beta)
28 echo "new file on branch" > $testroot/repo/epsilon/new
29 (cd $testroot/repo && git add epsilon/new)
30 git_commit $testroot/repo -m "committing more changes on newbranch"
32 local orig_commit1=`git_show_parent_commit $testroot/repo`
33 local orig_commit2=`git_show_head $testroot/repo`
35 (cd $testroot/repo && git checkout -q master)
36 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
37 git_commit $testroot/repo -m "committing to zeta on master"
38 local master_commit=`git_show_head $testroot/repo`
40 got checkout $testroot/repo $testroot/wt > /dev/null
41 ret="$?"
42 if [ "$ret" != "0" ]; then
43 test_done "$testroot" "$ret"
44 return 1
45 fi
47 (cd $testroot/wt && got rebase newbranch > /dev/null)
48 ret="$?"
49 if [ "$ret" != "0" ]; then
50 echo "got rebase failed unexpectedly"
51 test_done "$testroot" "$ret"
52 return 1
53 fi
55 (cd $testroot/repo && git checkout -q newbranch)
56 local new_commit1=`git_show_parent_commit $testroot/repo`
57 local new_commit2=`git_show_head $testroot/repo`
59 (cd $testroot/wt && got update -b master > /dev/null)
60 ret="$?"
61 if [ "$ret" != "0" ]; then
62 echo "got update failed unexpectedly"
63 test_done "$testroot" "$ret"
64 return 1
65 fi
67 (cd $testroot/wt && got integrate newbranch > $testroot/stdout)
69 echo "U alpha" > $testroot/stdout.expected
70 echo "D beta" >> $testroot/stdout.expected
71 echo "A epsilon/new" >> $testroot/stdout.expected
72 echo "U gamma/delta" >> $testroot/stdout.expected
73 echo "Integrated refs/heads/newbranch into refs/heads/master" \
74 >> $testroot/stdout.expected
75 cmp -s $testroot/stdout.expected $testroot/stdout
76 ret="$?"
77 if [ "$ret" != "0" ]; then
78 diff -u $testroot/stdout.expected $testroot/stdout
79 test_done "$testroot" "$ret"
80 return 1
81 fi
83 echo "modified delta on branch" > $testroot/content.expected
84 cat $testroot/wt/gamma/delta > $testroot/content
85 cmp -s $testroot/content.expected $testroot/content
86 ret="$?"
87 if [ "$ret" != "0" ]; then
88 diff -u $testroot/content.expected $testroot/content
89 test_done "$testroot" "$ret"
90 return 1
91 fi
93 echo "modified alpha on branch" > $testroot/content.expected
94 cat $testroot/wt/alpha > $testroot/content
95 cmp -s $testroot/content.expected $testroot/content
96 ret="$?"
97 if [ "$ret" != "0" ]; then
98 diff -u $testroot/content.expected $testroot/content
99 test_done "$testroot" "$ret"
100 return 1
101 fi
103 if [ -e $testroot/wt/beta ]; then
104 echo "removed file beta still exists on disk" >&2
105 test_done "$testroot" "1"
106 return 1
107 fi
109 echo "new file on branch" > $testroot/content.expected
110 cat $testroot/wt/epsilon/new > $testroot/content
111 cmp -s $testroot/content.expected $testroot/content
112 ret="$?"
113 if [ "$ret" != "0" ]; then
114 diff -u $testroot/content.expected $testroot/content
115 test_done "$testroot" "$ret"
116 return 1
117 fi
119 (cd $testroot/wt && got status > $testroot/stdout)
121 echo -n > $testroot/stdout.expected
122 cmp -s $testroot/stdout.expected $testroot/stdout
123 ret="$?"
124 if [ "$ret" != "0" ]; then
125 diff -u $testroot/stdout.expected $testroot/stdout
126 test_done "$testroot" "$ret"
127 return 1
128 fi
130 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
131 echo "commit $new_commit2 (master, newbranch)" \
132 > $testroot/stdout.expected
133 echo "commit $new_commit1" >> $testroot/stdout.expected
134 echo "commit $master_commit" >> $testroot/stdout.expected
135 cmp -s $testroot/stdout.expected $testroot/stdout
136 ret="$?"
137 if [ "$ret" != "0" ]; then
138 diff -u $testroot/stdout.expected $testroot/stdout
139 fi
140 test_done "$testroot" "$ret"
143 function test_integrate_requires_rebase_first {
144 local testroot=`test_init integrate_requires_rebase_first`
145 local init_commit=`git_show_head $testroot/repo`
147 (cd $testroot/repo && git checkout -q -b newbranch)
148 echo "modified delta on branch" > $testroot/repo/gamma/delta
149 git_commit $testroot/repo -m "committing to delta on newbranch"
151 echo "modified alpha on branch" > $testroot/repo/alpha
152 (cd $testroot/repo && git rm -q beta)
153 echo "new file on branch" > $testroot/repo/epsilon/new
154 (cd $testroot/repo && git add epsilon/new)
155 git_commit $testroot/repo -m "committing more changes on newbranch"
157 local orig_commit1=`git_show_parent_commit $testroot/repo`
158 local orig_commit2=`git_show_head $testroot/repo`
160 (cd $testroot/repo && git checkout -q master)
161 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
162 git_commit $testroot/repo -m "committing to zeta on master"
163 local master_commit=`git_show_head $testroot/repo`
165 (cd $testroot/repo && git checkout -q newbranch)
166 local new_commit1=`git_show_parent_commit $testroot/repo`
167 local new_commit2=`git_show_head $testroot/repo`
169 got checkout -b master $testroot/repo $testroot/wt > /dev/null
170 ret="$?"
171 if [ "$ret" != "0" ]; then
172 test_done "$testroot" "$ret"
173 return 1
174 fi
176 (cd $testroot/wt && got integrate newbranch \
177 > $testroot/stdout 2> $testroot/stderr)
178 ret="$?"
179 if [ "$ret" == "0" ]; then
180 echo "got integrate succeeded unexpectedly"
181 test_done "$testroot" "$ret"
182 return 1
183 fi
185 echo -n > $testroot/stdout.expected
186 cmp -s $testroot/stdout.expected $testroot/stdout
187 ret="$?"
188 if [ "$ret" != "0" ]; then
189 diff -u $testroot/stdout.expected $testroot/stdout
190 test_done "$testroot" "$ret"
191 return 1
192 fi
194 echo "got: specified branch must be rebased first" \
195 > $testroot/stderr.expected
196 cmp -s $testroot/stderr.expected $testroot/stderr
197 ret="$?"
198 if [ "$ret" != "0" ]; then
199 diff -u $testroot/stderr.expected $testroot/stderr
200 test_done "$testroot" "$ret"
201 return 1
202 fi
204 (cd $testroot/repo && got log -c master | \
205 grep ^commit > $testroot/stdout)
206 echo "commit $master_commit (master)" > $testroot/stdout.expected
207 echo "commit $init_commit" >> $testroot/stdout.expected
208 cmp -s $testroot/stdout.expected $testroot/stdout
209 ret="$?"
210 if [ "$ret" != "0" ]; then
211 diff -u $testroot/stdout.expected $testroot/stdout
212 test_done "$testroot" "$ret"
213 return 1
214 fi
216 (cd $testroot/repo && got log -c newbranch | \
217 grep ^commit > $testroot/stdout)
218 echo "commit $new_commit2 (newbranch)" \
219 > $testroot/stdout.expected
220 echo "commit $new_commit1" >> $testroot/stdout.expected
221 echo "commit $init_commit" >> $testroot/stdout.expected
222 cmp -s $testroot/stdout.expected $testroot/stdout
223 cmp -s $testroot/stdout.expected $testroot/stdout
224 ret="$?"
225 if [ "$ret" != "0" ]; then
226 diff -u $testroot/stdout.expected $testroot/stdout
227 fi
228 test_done "$testroot" "$ret"
231 function test_integrate_path_prefix {
232 local testroot=`test_init integrate_path_prefix`
234 (cd $testroot/repo && git checkout -q -b newbranch)
235 echo "modified delta on branch" > $testroot/repo/gamma/delta
236 git_commit $testroot/repo -m "committing to delta on newbranch"
238 echo "modified alpha on branch" > $testroot/repo/alpha
239 (cd $testroot/repo && git rm -q beta)
240 echo "new file on branch" > $testroot/repo/epsilon/new
241 (cd $testroot/repo && git add epsilon/new)
242 git_commit $testroot/repo -m "committing more changes on newbranch"
244 local orig_commit1=`git_show_parent_commit $testroot/repo`
245 local orig_commit2=`git_show_head $testroot/repo`
247 (cd $testroot/repo && git checkout -q master)
248 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
249 git_commit $testroot/repo -m "committing to zeta on master"
250 local master_commit=`git_show_head $testroot/repo`
252 got checkout $testroot/repo $testroot/wt > /dev/null
253 ret="$?"
254 if [ "$ret" != "0" ]; then
255 test_done "$testroot" "$ret"
256 return 1
257 fi
259 (cd $testroot/wt && got rebase newbranch > /dev/null)
260 ret="$?"
261 if [ "$ret" != "0" ]; then
262 echo "got rebase failed unexpectedly"
263 test_done "$testroot" "$ret"
264 return 1
265 fi
267 (cd $testroot/repo && git checkout -q newbranch)
268 local new_commit1=`git_show_parent_commit $testroot/repo`
269 local new_commit2=`git_show_head $testroot/repo`
271 rm -r $testroot/wt
272 got checkout -b master -p epsilon $testroot/repo $testroot/wt \
273 > /dev/null
274 ret="$?"
275 if [ "$ret" != "0" ]; then
276 echo "got checkout failed unexpectedly"
277 test_done "$testroot" "$ret"
278 return 1
279 fi
281 (cd $testroot/wt && got integrate newbranch > $testroot/stdout)
283 echo "A new" > $testroot/stdout.expected
284 echo "Integrated refs/heads/newbranch into refs/heads/master" \
285 >> $testroot/stdout.expected
286 cmp -s $testroot/stdout.expected $testroot/stdout
287 ret="$?"
288 if [ "$ret" != "0" ]; then
289 diff -u $testroot/stdout.expected $testroot/stdout
290 fi
291 test_done "$testroot" "$ret"
294 function test_integrate_backwards_in_time {
295 local testroot=`test_init integrate_backwards_in_time`
297 (cd $testroot/repo && git checkout -q -b newbranch)
298 echo "modified delta on branch" > $testroot/repo/gamma/delta
299 git_commit $testroot/repo -m "committing to delta on newbranch"
301 echo "modified alpha on branch" > $testroot/repo/alpha
302 (cd $testroot/repo && git rm -q beta)
303 echo "new file on branch" > $testroot/repo/epsilon/new
304 (cd $testroot/repo && git add epsilon/new)
305 git_commit $testroot/repo -m "committing more changes on newbranch"
307 local orig_commit1=`git_show_parent_commit $testroot/repo`
308 local orig_commit2=`git_show_head $testroot/repo`
310 (cd $testroot/repo && git checkout -q master)
311 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
312 git_commit $testroot/repo -m "committing to zeta on master"
313 local master_commit=`git_show_head $testroot/repo`
315 got checkout $testroot/repo $testroot/wt > /dev/null
316 ret="$?"
317 if [ "$ret" != "0" ]; then
318 test_done "$testroot" "$ret"
319 return 1
320 fi
322 (cd $testroot/wt && got rebase newbranch > /dev/null)
323 ret="$?"
324 if [ "$ret" != "0" ]; then
325 echo "got rebase failed unexpectedly"
326 test_done "$testroot" "$ret"
327 return 1
328 fi
330 (cd $testroot/repo && git checkout -q newbranch)
331 local new_commit1=`git_show_parent_commit $testroot/repo`
332 local new_commit2=`git_show_head $testroot/repo`
334 # attempt to integrate master into newbranch (wrong way around)
335 (cd $testroot/wt && got update -b newbranch > /dev/null)
336 ret="$?"
337 if [ "$ret" != "0" ]; then
338 echo "got update failed unexpectedly"
339 test_done "$testroot" "$ret"
340 return 1
341 fi
343 (cd $testroot/wt && got integrate master \
344 > $testroot/stdout 2> $testroot/stderr)
345 ret="$?"
346 if [ "$ret" == "0" ]; then
347 echo "got integrate succeeded unexpectedly"
348 test_done "$testroot" "$ret"
349 return 1
350 fi
352 echo -n > $testroot/stdout.expected
353 cmp -s $testroot/stdout.expected $testroot/stdout
354 ret="$?"
355 if [ "$ret" != "0" ]; then
356 diff -u $testroot/stdout.expected $testroot/stdout
357 test_done "$testroot" "$ret"
358 return 1
359 fi
361 echo "got: specified branch must be rebased first" \
362 > $testroot/stderr.expected
363 cmp -s $testroot/stderr.expected $testroot/stderr
364 ret="$?"
365 if [ "$ret" != "0" ]; then
366 diff -u $testroot/stderr.expected $testroot/stderr
367 fi
368 test_done "$testroot" "$ret"
371 run_test test_integrate_basic
372 run_test test_integrate_requires_rebase_first
373 run_test test_integrate_path_prefix
374 run_test test_integrate_backwards_in_time