1#
2# Copyright (c) 2010 D. Richard Hipp
3#
4# This program is free software; you can redistribute it and/or
5# modify it under the terms of the Simplified BSD License (also
6# known as the "2-Clause License" or "FreeBSD License".)
7#
8# This program is distributed in the hope that it will be useful,
9# but without any warranty; without even the implied warranty of
10# merchantability or fitness for a particular purpose.
11#
12# Author contact information:
13#   drh@hwaci.com
14#   http://www.hwaci.com/drh/
15#
16############################################################################
17#
18# Tests of the "merge" command
19#
20
21puts "Skipping Merge5 tests"
22protOut {
23fossil sqlite3 --no-repository reacts badly to SQL dumped from
24repositories created from fossil older than version 2.0.
25}
26test merge5-sqlite3-issue false knownBug
27test_cleanup_then_return
28
29# Verify the results of a check-out
30#
31proc checkout-test {testid expected_content} {
32  set flist {}
33  foreach {status filename} [exec $::fossilexe ls -l] {
34    if {$status!="DELETED"} {lappend flist $filename}
35  }
36  eval fossil sha1sum [lsort $flist]
37  global RESULT
38  regsub -all {\n *} [string trim $expected_content] "\n    " expected
39  regsub -all {\n *} [string trim $RESULT] "\n    " result
40  if {$result!=$expected} {
41    protOut "  Expected:\n    $expected"
42    protOut "  Got:\n    $result"
43    test merge5-$testid 0
44  } else {
45    test merge5-$testid 1
46  }
47}
48
49require_no_open_checkout; test_setup ""
50
51# Construct a test repository
52#
53exec $::fossilexe sqlite3 --no-repository m5.fossil <$testdir/${testfile}_repo.sql
54fossil rebuild m5.fossil
55fossil open m5.fossil
56fossil user default drh --user drh
57fossil update baseline
58checkout-test 10 {
59  da5c8346496f3421cb58f84b6e59e9531d9d424d  one.txt
60  ed24d19d726d173f18dbf4a9a0f8514daa3e3ca4  three.txt
61  278a402316510f6ae4a77186796a6bde78c7dbc1  two.txt
62}
63
64# Update to the tip of the trunk
65#
66fossil update trunk
67checkout-test 20 {
68  6f525ab779ad66e24474d845c5fb7938be42d50d  one.txt
69  64a8a5c7320fccfa4b2e5dfc5fd20a5381a86c5b  three.txt
70  b262fee89ed8a27a23a5e09d3917e0bebe22cd24  two.txt
71}
72
73# Merge in the change that adds file four.txt
74#
75fossil merge br1
76checkout-test 30 {
77  35815cf5804e8933eab64ae34e00bbb381be72c5  four.txt
78  6f525ab779ad66e24474d845c5fb7938be42d50d  one.txt
79  64a8a5c7320fccfa4b2e5dfc5fd20a5381a86c5b  three.txt
80  b262fee89ed8a27a23a5e09d3917e0bebe22cd24  two.txt
81}
82
83# Undo the merge.  Verify restoration of former state.
84#
85fossil undo
86checkout-test 40 {
87  6f525ab779ad66e24474d845c5fb7938be42d50d  one.txt
88  64a8a5c7320fccfa4b2e5dfc5fd20a5381a86c5b  three.txt
89  b262fee89ed8a27a23a5e09d3917e0bebe22cd24  two.txt
90}
91
92# Now switch to br1 then merge in the trunk.  Verify that the result
93# is the same as merging br1 into trunk.
94#
95fossil update br1
96fossil merge trunk
97checkout-test 50 {
98  35815cf5804e8933eab64ae34e00bbb381be72c5  four.txt
99  6f525ab779ad66e24474d845c5fb7938be42d50d  one.txt
100  64a8a5c7320fccfa4b2e5dfc5fd20a5381a86c5b  three.txt
101  b262fee89ed8a27a23a5e09d3917e0bebe22cd24  two.txt
102}
103fossil undo
104fossil update trunk
105checkout-test 60 {
106  6f525ab779ad66e24474d845c5fb7938be42d50d  one.txt
107  64a8a5c7320fccfa4b2e5dfc5fd20a5381a86c5b  three.txt
108  b262fee89ed8a27a23a5e09d3917e0bebe22cd24  two.txt
109}
110
111# Go back to the tip of the trunk and merge branch br1 again.  This
112# time do a check-in of the merge.  Verify that the same content appears
113# after the merge.
114#
115fossil update chng3
116fossil merge br1
117checkout-test 70 {
118  35815cf5804e8933eab64ae34e00bbb381be72c5  four.txt
119  6f525ab779ad66e24474d845c5fb7938be42d50d  one.txt
120  64a8a5c7320fccfa4b2e5dfc5fd20a5381a86c5b  three.txt
121  b262fee89ed8a27a23a5e09d3917e0bebe22cd24  two.txt
122}
123fossil commit -tag m1 -m {merge with br1} -nosign -f
124checkout-test 71 {
125  35815cf5804e8933eab64ae34e00bbb381be72c5  four.txt
126  6f525ab779ad66e24474d845c5fb7938be42d50d  one.txt
127  64a8a5c7320fccfa4b2e5dfc5fd20a5381a86c5b  three.txt
128  b262fee89ed8a27a23a5e09d3917e0bebe22cd24  two.txt
129}
130fossil update chng3
131checkout-test 72 {
132  6f525ab779ad66e24474d845c5fb7938be42d50d  one.txt
133  64a8a5c7320fccfa4b2e5dfc5fd20a5381a86c5b  three.txt
134  b262fee89ed8a27a23a5e09d3917e0bebe22cd24  two.txt
135}
136fossil update m1
137checkout-test 73 {
138  35815cf5804e8933eab64ae34e00bbb381be72c5  four.txt
139  6f525ab779ad66e24474d845c5fb7938be42d50d  one.txt
140  64a8a5c7320fccfa4b2e5dfc5fd20a5381a86c5b  three.txt
141  b262fee89ed8a27a23a5e09d3917e0bebe22cd24  two.txt
142}
143
144# Merge br2 into the trunk.  br2 contains some independent change to the
145# two.txt file.  Verify that these are merge in correctly.
146#
147fossil update m1
148fossil merge br2
149checkout-test 80 {
150  8f09bc55a60eb8ca06f10a3b577aafa869b31695  five.txt
151  35815cf5804e8933eab64ae34e00bbb381be72c5  four.txt
152  6f525ab779ad66e24474d845c5fb7938be42d50d  one.txt
153  64a8a5c7320fccfa4b2e5dfc5fd20a5381a86c5b  three.txt
154  68eeee8b843eaea76e33d3911f416b745d0e5e5c  two.txt
155}
156fossil undo
157checkout-test 81 {
158  35815cf5804e8933eab64ae34e00bbb381be72c5  four.txt
159  6f525ab779ad66e24474d845c5fb7938be42d50d  one.txt
160  64a8a5c7320fccfa4b2e5dfc5fd20a5381a86c5b  three.txt
161  b262fee89ed8a27a23a5e09d3917e0bebe22cd24  two.txt
162}
163
164# Now merge trunk into br2.  Verify that the same set of changes result.
165#
166fossil update br2
167fossil merge trunk
168checkout-test 90 {
169  8f09bc55a60eb8ca06f10a3b577aafa869b31695  five.txt
170  35815cf5804e8933eab64ae34e00bbb381be72c5  four.txt
171  6f525ab779ad66e24474d845c5fb7938be42d50d  one.txt
172  64a8a5c7320fccfa4b2e5dfc5fd20a5381a86c5b  three.txt
173  68eeee8b843eaea76e33d3911f416b745d0e5e5c  two.txt
174}
175fossil undo
176checkout-test 91 {
177  8f09bc55a60eb8ca06f10a3b577aafa869b31695  five.txt
178  da5c8346496f3421cb58f84b6e59e9531d9d424d  one.txt
179  ed24d19d726d173f18dbf4a9a0f8514daa3e3ca4  three.txt
180  85286cb3bc6d9e6f2f586eb5532f6065678f75b9  two.txt
181}
182
183# Starting from chng3, merge in br4.  The one file is deleted from br4, so
184# the merge should cause the one file to disappear from the checkout.
185#
186fossil update chng3
187checkout-test 100 {
188  6f525ab779ad66e24474d845c5fb7938be42d50d  one.txt
189  64a8a5c7320fccfa4b2e5dfc5fd20a5381a86c5b  three.txt
190  b262fee89ed8a27a23a5e09d3917e0bebe22cd24  two.txt
191}
192fossil merge br4
193checkout-test 101 {
194  6e167b139c294bed560e2e30b352361b101e1f39  four.txt
195  64a8a5c7320fccfa4b2e5dfc5fd20a5381a86c5b  three.txt
196  b262fee89ed8a27a23a5e09d3917e0bebe22cd24  two.txt
197}
198fossil undo
199checkout-test 102 {
200  6f525ab779ad66e24474d845c5fb7938be42d50d  one.txt
201  64a8a5c7320fccfa4b2e5dfc5fd20a5381a86c5b  three.txt
202  b262fee89ed8a27a23a5e09d3917e0bebe22cd24  two.txt
203}
204
205# Do the same merge of br4 into chng3, but this time check it in as a new
206# branch.
207#
208fossil update chng3
209fossil merge br4
210fossil commit -nosign -branch br4-b -m {merge in br4} -tag m2
211checkout-test 110 {
212  6e167b139c294bed560e2e30b352361b101e1f39  four.txt
213  64a8a5c7320fccfa4b2e5dfc5fd20a5381a86c5b  three.txt
214  b262fee89ed8a27a23a5e09d3917e0bebe22cd24  two.txt
215}
216
217# Branches br1 and br4 both add file four.txt.  So if we merge them together,
218# the version of file four.txt in the original should be preserved.
219#
220fossil update br1
221checkout-test 120 {
222  35815cf5804e8933eab64ae34e00bbb381be72c5  four.txt
223  da5c8346496f3421cb58f84b6e59e9531d9d424d  one.txt
224  ed24d19d726d173f18dbf4a9a0f8514daa3e3ca4  three.txt
225  278a402316510f6ae4a77186796a6bde78c7dbc1  two.txt
226}
227fossil merge br4 -expectError
228checkout-test 121 {
229  35815cf5804e8933eab64ae34e00bbb381be72c5  four.txt
230  ed24d19d726d173f18dbf4a9a0f8514daa3e3ca4  three.txt
231  278a402316510f6ae4a77186796a6bde78c7dbc1  two.txt
232}
233fossil undo
234fossil update br4
235checkout-test 122 {
236  6e167b139c294bed560e2e30b352361b101e1f39  four.txt
237  ed24d19d726d173f18dbf4a9a0f8514daa3e3ca4  three.txt
238  278a402316510f6ae4a77186796a6bde78c7dbc1  two.txt
239}
240fossil merge br1 -expectError
241checkout-test 123 {
242  6e167b139c294bed560e2e30b352361b101e1f39  four.txt
243  ed24d19d726d173f18dbf4a9a0f8514daa3e3ca4  three.txt
244  278a402316510f6ae4a77186796a6bde78c7dbc1  two.txt
245}
246fossil undo
247
248# Merge br5 (which includes a file rename) into chng3
249#
250fossil update chng3
251checkout-test 130 {
252  6f525ab779ad66e24474d845c5fb7938be42d50d  one.txt
253  64a8a5c7320fccfa4b2e5dfc5fd20a5381a86c5b  three.txt
254  b262fee89ed8a27a23a5e09d3917e0bebe22cd24  two.txt
255}
256fossil merge br5
257checkout-test 131 {
258  7eaf64a2c9141277b4c24259c7766d6a77047af7  one.txt
259  98e47f99bb9fed4fdcd407f553615ca7f15a38a2  three.txt
260  e58c5da3e6007d0e30600ea31611813093ad180f  two-rename.txt
261}
262fossil undo
263checkout-test 132 {
264  6f525ab779ad66e24474d845c5fb7938be42d50d  one.txt
265  64a8a5c7320fccfa4b2e5dfc5fd20a5381a86c5b  three.txt
266  b262fee89ed8a27a23a5e09d3917e0bebe22cd24  two.txt
267}
268fossil merge br5
269checkout-test 133 {
270  7eaf64a2c9141277b4c24259c7766d6a77047af7  one.txt
271  98e47f99bb9fed4fdcd407f553615ca7f15a38a2  three.txt
272  e58c5da3e6007d0e30600ea31611813093ad180f  two-rename.txt
273}
274fossil commit -nosign -m {merge with rename} -branch {trunk+br5}
275checkout-test 134 {
276  7eaf64a2c9141277b4c24259c7766d6a77047af7  one.txt
277  98e47f99bb9fed4fdcd407f553615ca7f15a38a2  three.txt
278  e58c5da3e6007d0e30600ea31611813093ad180f  two-rename.txt
279}
280fossil update chng3
281checkout-test 135 {
282  6f525ab779ad66e24474d845c5fb7938be42d50d  one.txt
283  64a8a5c7320fccfa4b2e5dfc5fd20a5381a86c5b  three.txt
284  b262fee89ed8a27a23a5e09d3917e0bebe22cd24  two.txt
285}
286fossil update trunk+br5
287checkout-test 136 {
288  7eaf64a2c9141277b4c24259c7766d6a77047af7  one.txt
289  98e47f99bb9fed4fdcd407f553615ca7f15a38a2  three.txt
290  e58c5da3e6007d0e30600ea31611813093ad180f  two-rename.txt
291}
292
293# Merge the chng3 check-in into br5, verifying that the change to two.txt
294# from chng3 are applies to two-rename.txt in br5.
295#
296fossil update br5
297checkout-test 140 {
298  e866bb885d5184cba497cfb6a4eb281688519521  one.txt
299  e09593950837f76e70ca2f8ff2272ae3df0ba017  three.txt
300  5ebb3c9ad50740a7382902657b84a6105c32fc7b  two-rename.txt
301}
302fossil merge chng3
303checkout-test 141 {
304  7eaf64a2c9141277b4c24259c7766d6a77047af7  one.txt
305  98e47f99bb9fed4fdcd407f553615ca7f15a38a2  three.txt
306  e58c5da3e6007d0e30600ea31611813093ad180f  two-rename.txt
307}
308fossil commit -nosign -m {change to two} -branch br5-2
309checkout-test 142 {
310  7eaf64a2c9141277b4c24259c7766d6a77047af7  one.txt
311  98e47f99bb9fed4fdcd407f553615ca7f15a38a2  three.txt
312  e58c5da3e6007d0e30600ea31611813093ad180f  two-rename.txt
313}
314
315###############################################################################
316
317test_cleanup
318