/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_conflicts.py

  • Committer: Vincent Ladeuil
  • Date: 2010-02-05 10:27:33 UTC
  • mto: (5008.1.1 integration)
  • mto: This revision was merged to the branch mainline in revision 5009.
  • Revision ID: v.ladeuil+lp@free.fr-20100205102733-8wpjnqz6g4nvrbfu
All Conflict action method names start with 'action_' to avoid potential namespace collisions

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2005, 2006, 2007, 2008, 2009 Canonical Ltd
 
2
#
 
3
# This program is free software; you can redistribute it and/or modify
 
4
# it under the terms of the GNU General Public License as published by
 
5
# the Free Software Foundation; either version 2 of the License, or
 
6
# (at your option) any later version.
 
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.  See the
 
11
# GNU General Public License for more details.
 
12
#
 
13
# You should have received a copy of the GNU General Public License
 
14
# along with this program; if not, write to the Free Software
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
16
 
 
17
 
 
18
import os
 
19
 
 
20
from bzrlib import (
 
21
    bzrdir,
 
22
    conflicts,
 
23
    errors,
 
24
    option,
 
25
    tests,
 
26
    )
 
27
from bzrlib.tests import script
 
28
 
 
29
 
 
30
# TODO: Test commit with some added, and added-but-missing files
 
31
# RBC 20060124 is that not tested in test_commit.py ?
 
32
 
 
33
# The order of 'path' here is important - do not let it
 
34
# be a sorted list.
 
35
# u'\xe5' == a with circle
 
36
# '\xc3\xae' == u'\xee' == i with hat
 
37
# So these are u'path' and 'id' only with a circle and a hat. (shappo?)
 
38
example_conflicts = conflicts.ConflictList(
 
39
    [conflicts.MissingParent('Not deleting', u'p\xe5thg', '\xc3\xaedg'),
 
40
     conflicts.ContentsConflict(u'p\xe5tha', None, '\xc3\xaeda'),
 
41
     conflicts.TextConflict(u'p\xe5tha'),
 
42
     conflicts.PathConflict(u'p\xe5thb', u'p\xe5thc', '\xc3\xaedb'),
 
43
     conflicts.DuplicateID('Unversioned existing file',
 
44
                           u'p\xe5thc', u'p\xe5thc2',
 
45
                           '\xc3\xaedc', '\xc3\xaedc'),
 
46
    conflicts.DuplicateEntry('Moved existing file to',
 
47
                             u'p\xe5thdd.moved', u'p\xe5thd',
 
48
                             '\xc3\xaedd', None),
 
49
    conflicts.ParentLoop('Cancelled move', u'p\xe5the', u'p\xe5th2e',
 
50
                         None, '\xc3\xaed2e'),
 
51
    conflicts.UnversionedParent('Versioned directory',
 
52
                                u'p\xe5thf', '\xc3\xaedf'),
 
53
    conflicts.NonDirectoryParent('Created directory',
 
54
                                 u'p\xe5thg', '\xc3\xaedg'),
 
55
])
 
56
 
 
57
 
 
58
class TestConflicts(tests.TestCaseWithTransport):
 
59
 
 
60
    def test_conflicts(self):
 
61
        """Conflicts are detected properly"""
 
62
        # Use BzrDirFormat6 so we can fake conflicts
 
63
        tree = self.make_branch_and_tree('.', format=bzrdir.BzrDirFormat6())
 
64
        self.build_tree_contents([('hello', 'hello world4'),
 
65
                                  ('hello.THIS', 'hello world2'),
 
66
                                  ('hello.BASE', 'hello world1'),
 
67
                                  ('hello.OTHER', 'hello world3'),
 
68
                                  ('hello.sploo.BASE', 'yellowworld'),
 
69
                                  ('hello.sploo.OTHER', 'yellowworld2'),
 
70
                                  ])
 
71
        tree.lock_read()
 
72
        self.assertEqual(6, len(list(tree.list_files())))
 
73
        tree.unlock()
 
74
        tree_conflicts = tree.conflicts()
 
75
        self.assertEqual(2, len(tree_conflicts))
 
76
        self.assertTrue('hello' in tree_conflicts[0].path)
 
77
        self.assertTrue('hello.sploo' in tree_conflicts[1].path)
 
78
        conflicts.restore('hello')
 
79
        conflicts.restore('hello.sploo')
 
80
        self.assertEqual(0, len(tree.conflicts()))
 
81
        self.assertFileEqual('hello world2', 'hello')
 
82
        self.assertFalse(os.path.lexists('hello.sploo'))
 
83
        self.assertRaises(errors.NotConflicted, conflicts.restore, 'hello')
 
84
        self.assertRaises(errors.NotConflicted,
 
85
                          conflicts.restore, 'hello.sploo')
 
86
 
 
87
    def test_resolve_conflict_dir(self):
 
88
        tree = self.make_branch_and_tree('.')
 
89
        self.build_tree_contents([('hello', 'hello world4'),
 
90
                                  ('hello.THIS', 'hello world2'),
 
91
                                  ('hello.BASE', 'hello world1'),
 
92
                                  ])
 
93
        os.mkdir('hello.OTHER')
 
94
        tree.add('hello', 'q')
 
95
        l = conflicts.ConflictList([conflicts.TextConflict('hello')])
 
96
        l.remove_files(tree)
 
97
 
 
98
    def test_select_conflicts(self):
 
99
        tree = self.make_branch_and_tree('.')
 
100
        clist = conflicts.ConflictList
 
101
 
 
102
        def check_select(not_selected, selected, paths, **kwargs):
 
103
            self.assertEqual(
 
104
                (not_selected, selected),
 
105
                tree_conflicts.select_conflicts(tree, paths, **kwargs))
 
106
 
 
107
        foo = conflicts.ContentsConflict('foo')
 
108
        bar = conflicts.ContentsConflict('bar')
 
109
        tree_conflicts = clist([foo, bar])
 
110
 
 
111
        check_select(clist([bar]), clist([foo]), ['foo'])
 
112
        check_select(clist(), tree_conflicts,
 
113
                     [''], ignore_misses=True, recurse=True)
 
114
 
 
115
        foobaz  = conflicts.ContentsConflict('foo/baz')
 
116
        tree_conflicts = clist([foobaz, bar])
 
117
 
 
118
        check_select(clist([bar]), clist([foobaz]),
 
119
                     ['foo'], ignore_misses=True, recurse=True)
 
120
 
 
121
        qux = conflicts.PathConflict('qux', 'foo/baz')
 
122
        tree_conflicts = clist([qux])
 
123
 
 
124
        check_select(clist(), tree_conflicts,
 
125
                     ['foo'], ignore_misses=True, recurse=True)
 
126
        check_select (tree_conflicts, clist(), ['foo'], ignore_misses=True)
 
127
 
 
128
    def test_resolve_conflicts_recursive(self):
 
129
        tree = self.make_branch_and_tree('.')
 
130
        self.build_tree(['dir/', 'dir/hello'])
 
131
        tree.add(['dir', 'dir/hello'])
 
132
 
 
133
        dirhello = conflicts.ConflictList([conflicts.TextConflict('dir/hello')])
 
134
        tree.set_conflicts(dirhello)
 
135
 
 
136
        conflicts.resolve(tree, ['dir'], recursive=False, ignore_misses=True)
 
137
        self.assertEqual(dirhello, tree.conflicts())
 
138
 
 
139
        conflicts.resolve(tree, ['dir'], recursive=True, ignore_misses=True)
 
140
        self.assertEqual(conflicts.ConflictList([]), tree.conflicts())
 
141
 
 
142
 
 
143
class TestConflictStanzas(tests.TestCase):
 
144
 
 
145
    def test_stanza_roundtrip(self):
 
146
        # write and read our example stanza.
 
147
        stanza_iter = example_conflicts.to_stanzas()
 
148
        processed = conflicts.ConflictList.from_stanzas(stanza_iter)
 
149
        for o, p in zip(processed, example_conflicts):
 
150
            self.assertEqual(o, p)
 
151
 
 
152
            self.assertIsInstance(o.path, unicode)
 
153
 
 
154
            if o.file_id is not None:
 
155
                self.assertIsInstance(o.file_id, str)
 
156
 
 
157
            conflict_path = getattr(o, 'conflict_path', None)
 
158
            if conflict_path is not None:
 
159
                self.assertIsInstance(conflict_path, unicode)
 
160
 
 
161
            conflict_file_id = getattr(o, 'conflict_file_id', None)
 
162
            if conflict_file_id is not None:
 
163
                self.assertIsInstance(conflict_file_id, str)
 
164
 
 
165
    def test_stanzification(self):
 
166
        for stanza in example_conflicts.to_stanzas():
 
167
            if 'file_id' in stanza:
 
168
                # In Stanza form, the file_id has to be unicode.
 
169
                self.assertStartsWith(stanza['file_id'], u'\xeed')
 
170
            self.assertStartsWith(stanza['path'], u'p\xe5th')
 
171
            if 'conflict_path' in stanza:
 
172
                self.assertStartsWith(stanza['conflict_path'], u'p\xe5th')
 
173
            if 'conflict_file_id' in stanza:
 
174
                self.assertStartsWith(stanza['conflict_file_id'], u'\xeed')
 
175
 
 
176
 
 
177
# FIXME: Tests missing for DuplicateID conflict type
 
178
class TestResolveConflicts(script.TestCaseWithTransportAndScript):
 
179
 
 
180
    preamble = None # The setup script set by daughter classes
 
181
 
 
182
    def setUp(self):
 
183
        super(TestResolveConflicts, self).setUp()
 
184
        self.run_script(self.preamble)
 
185
 
 
186
 
 
187
class TestResolveTextConflicts(TestResolveConflicts):
 
188
    # TBC
 
189
    pass
 
190
 
 
191
 
 
192
class TestResolveContentConflicts(TestResolveConflicts):
 
193
 
 
194
    # FIXME: We need to add the reverse case (delete in trunk, modify in
 
195
    # branch) but that could wait until the resolution mechanism is implemented.
 
196
 
 
197
    preamble = """
 
198
$ bzr init trunk
 
199
$ cd trunk
 
200
$ echo 'trunk content' >file
 
201
$ bzr add file
 
202
$ bzr commit -m 'Create trunk'
 
203
 
 
204
$ bzr branch . ../branch
 
205
$ cd ../branch
 
206
$ bzr rm file
 
207
$ bzr commit -m 'Delete file'
 
208
 
 
209
$ cd ../trunk
 
210
$ echo 'more content' >>file
 
211
$ bzr commit -m 'Modify file'
 
212
 
 
213
$ cd ../branch
 
214
$ bzr merge ../trunk
 
215
2>+N  file.OTHER
 
216
2>Contents conflict in file
 
217
2>1 conflicts encountered.
 
218
"""
 
219
 
 
220
    def test_take_this(self):
 
221
        self.run_script("""
 
222
$ bzr rm file.OTHER --force # a simple rm file.OTHER is valid too
 
223
$ bzr resolve file
 
224
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
225
""")
 
226
 
 
227
    def test_take_other(self):
 
228
        self.run_script("""
 
229
$ bzr mv file.OTHER file
 
230
$ bzr resolve file
 
231
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
232
""")
 
233
 
 
234
    def test_resolve_taking_this(self):
 
235
        self.run_script("""
 
236
$ bzr resolve --take-this file
 
237
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
238
""")
 
239
 
 
240
    def test_resolve_taking_other(self):
 
241
        self.run_script("""
 
242
$ bzr resolve --take-other file
 
243
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
244
""")
 
245
 
 
246
 
 
247
class TestResolveDuplicateEntry(TestResolveConflicts):
 
248
 
 
249
    preamble = """
 
250
$ bzr init trunk
 
251
$ cd trunk
 
252
$ echo 'trunk content' >file
 
253
$ bzr add file
 
254
$ bzr commit -m 'Create trunk'
 
255
$ echo 'trunk content too' >file2
 
256
$ bzr add file2
 
257
$ bzr commit -m 'Add file2 in trunk'
 
258
 
 
259
$ bzr branch . -r 1 ../branch
 
260
$ cd ../branch
 
261
$ echo 'branch content' >file2
 
262
$ bzr add file2
 
263
$ bzr commit -m 'Add file2 in branch'
 
264
 
 
265
$ bzr merge ../trunk
 
266
2>+N  file2
 
267
2>R   file2 => file2.moved
 
268
2>Conflict adding file file2.  Moved existing file to file2.moved.
 
269
2>1 conflicts encountered.
 
270
"""
 
271
 
 
272
    def test_keep_this(self):
 
273
        self.run_script("""
 
274
$ bzr rm file2  --force
 
275
$ bzr mv file2.moved file2
 
276
$ bzr resolve file2
 
277
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
278
""")
 
279
 
 
280
    def test_keep_other(self):
 
281
        self.failIfExists('branch/file2.moved')
 
282
        self.run_script("""
 
283
$ bzr rm file2.moved --force
 
284
$ bzr resolve file2
 
285
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
286
""")
 
287
        self.failIfExists('branch/file2.moved')
 
288
 
 
289
    def test_resolve_taking_this(self):
 
290
        self.run_script("""
 
291
$ bzr resolve --take-this file2
 
292
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
293
""")
 
294
 
 
295
    def test_resolve_taking_other(self):
 
296
        self.run_script("""
 
297
$ bzr resolve --take-other file2
 
298
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
299
""")
 
300
 
 
301
 
 
302
class TestResolveUnversionedParent(TestResolveConflicts):
 
303
 
 
304
    # FIXME: Add the reverse tests: dir deleted in trunk, file added in branch
 
305
 
 
306
    # FIXME: While this *creates* UnversionedParent conflicts, this really only
 
307
    # tests MissingParent resolution :-/
 
308
    preamble = """
 
309
$ bzr init trunk
 
310
$ cd trunk
 
311
$ mkdir dir
 
312
$ bzr add dir
 
313
$ bzr commit -m 'Create trunk'
 
314
$ echo 'trunk content' >dir/file
 
315
$ bzr add dir/file
 
316
$ bzr commit -m 'Add dir/file in trunk'
 
317
 
 
318
$ bzr branch . -r 1 ../branch
 
319
$ cd ../branch
 
320
$ bzr rm dir
 
321
$ bzr commit -m 'Remove dir in branch'
 
322
 
 
323
$ bzr merge ../trunk
 
324
2>+N  dir/
 
325
2>+N  dir/file
 
326
2>Conflict adding files to dir.  Created directory.
 
327
2>Conflict because dir is not versioned, but has versioned children.  Versioned directory.
 
328
2>2 conflicts encountered.
 
329
"""
 
330
 
 
331
    def test_take_this(self):
 
332
        self.run_script("""
 
333
$ bzr rm dir  --force
 
334
$ bzr resolve dir
 
335
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
336
""")
 
337
 
 
338
    def test_take_other(self):
 
339
        self.run_script("""
 
340
$ bzr resolve dir
 
341
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
342
""")
 
343
 
 
344
 
 
345
class TestResolveMissingParent(TestResolveConflicts):
 
346
 
 
347
    preamble = """
 
348
$ bzr init trunk
 
349
$ cd trunk
 
350
$ mkdir dir
 
351
$ echo 'trunk content' >dir/file
 
352
$ bzr add
 
353
$ bzr commit -m 'Create trunk'
 
354
$ echo 'trunk content' >dir/file2
 
355
$ bzr add dir/file2
 
356
$ bzr commit -m 'Add dir/file2 in branch'
 
357
 
 
358
$ bzr branch . -r 1 ../branch
 
359
$ cd ../branch
 
360
$ bzr rm dir/file --force
 
361
$ bzr rm dir
 
362
$ bzr commit -m 'Remove dir/file'
 
363
 
 
364
$ bzr merge ../trunk
 
365
2>+N  dir/
 
366
2>+N  dir/file2
 
367
2>Conflict adding files to dir.  Created directory.
 
368
2>Conflict because dir is not versioned, but has versioned children.  Versioned directory.
 
369
2>2 conflicts encountered.
 
370
"""
 
371
 
 
372
    def test_keep_them_all(self):
 
373
        self.run_script("""
 
374
$ bzr resolve dir
 
375
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
376
""")
 
377
 
 
378
    def test_adopt_child(self):
 
379
        self.run_script("""
 
380
$ bzr mv dir/file2 file2
 
381
$ bzr rm dir --force
 
382
$ bzr resolve dir
 
383
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
384
""")
 
385
 
 
386
    def test_kill_them_all(self):
 
387
        self.run_script("""
 
388
$ bzr rm dir --force
 
389
$ bzr resolve dir
 
390
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
391
""")
 
392
 
 
393
    def test_resolve_taking_this(self):
 
394
        self.run_script("""
 
395
$ bzr resolve --take-this dir
 
396
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
397
""")
 
398
 
 
399
    def test_resolve_taking_other(self):
 
400
        self.run_script("""
 
401
$ bzr resolve --take-other dir
 
402
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
403
""")
 
404
 
 
405
 
 
406
class TestResolveDeletingParent(TestResolveConflicts):
 
407
 
 
408
    preamble = """
 
409
$ bzr init trunk
 
410
$ cd trunk
 
411
$ mkdir dir
 
412
$ echo 'trunk content' >dir/file
 
413
$ bzr add
 
414
$ bzr commit -m 'Create trunk'
 
415
$ bzr rm dir/file --force
 
416
$ bzr rm dir --force
 
417
$ bzr commit -m 'Remove dir/file'
 
418
 
 
419
$ bzr branch . -r 1 ../branch
 
420
$ cd ../branch
 
421
$ echo 'branch content' >dir/file2
 
422
$ bzr add dir/file2
 
423
$ bzr commit -m 'Add dir/file2 in branch'
 
424
 
 
425
$ bzr merge ../trunk
 
426
2>-D  dir/file
 
427
2>Conflict: can't delete dir because it is not empty.  Not deleting.
 
428
2>Conflict because dir is not versioned, but has versioned children.  Versioned directory.
 
429
2>2 conflicts encountered.
 
430
"""
 
431
 
 
432
    def test_keep_them_all(self):
 
433
        self.run_script("""
 
434
$ bzr resolve dir
 
435
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
436
""")
 
437
 
 
438
    def test_adopt_child(self):
 
439
        self.run_script("""
 
440
$ bzr mv dir/file2 file2
 
441
$ bzr rm dir --force
 
442
$ bzr resolve dir
 
443
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
444
""")
 
445
 
 
446
    def test_kill_them_all(self):
 
447
        self.run_script("""
 
448
$ bzr rm dir --force
 
449
$ bzr resolve dir
 
450
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
451
""")
 
452
 
 
453
    def test_resolve_taking_this(self):
 
454
        self.run_script("""
 
455
$ bzr resolve --take-this dir
 
456
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
457
""")
 
458
 
 
459
    def test_resolve_taking_other(self):
 
460
        self.run_script("""
 
461
$ bzr resolve --take-other dir
 
462
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
463
""")
 
464
 
 
465
 
 
466
class TestResolvePathConflict(TestResolveConflicts):
 
467
 
 
468
    preamble = """
 
469
$ bzr init trunk
 
470
$ cd trunk
 
471
$ echo 'Boo!' >file
 
472
$ bzr add
 
473
$ bzr commit -m 'Create trunk'
 
474
$ bzr mv file file-in-trunk
 
475
$ bzr commit -m 'Renamed to file-in-trunk'
 
476
 
 
477
$ bzr branch . -r 1 ../branch
 
478
$ cd ../branch
 
479
$ bzr mv file file-in-branch
 
480
$ bzr commit -m 'Renamed to file-in-branch'
 
481
 
 
482
$ bzr merge ../trunk
 
483
2>R   file-in-branch => file-in-trunk
 
484
2>Path conflict: file-in-branch / file-in-trunk
 
485
2>1 conflicts encountered.
 
486
"""
 
487
 
 
488
    def test_keep_source(self):
 
489
        self.run_script("""
 
490
$ bzr resolve file-in-trunk
 
491
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
492
""")
 
493
 
 
494
    def test_keep_target(self):
 
495
        self.run_script("""
 
496
$ bzr mv file-in-trunk file-in-branch
 
497
$ bzr resolve file-in-branch
 
498
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
499
""")
 
500
 
 
501
    def test_resolve_taking_this(self):
 
502
        self.run_script("""
 
503
$ bzr resolve --take-this file-in-branch
 
504
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
505
""")
 
506
 
 
507
    def test_resolve_taking_other(self):
 
508
        self.run_script("""
 
509
$ bzr resolve --take-other file-in-branch
 
510
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
511
""")
 
512
 
 
513
 
 
514
class TestResolveParentLoop(TestResolveConflicts):
 
515
 
 
516
    preamble = """
 
517
$ bzr init trunk
 
518
$ cd trunk
 
519
$ bzr mkdir dir1
 
520
$ bzr mkdir dir2
 
521
$ bzr commit -m 'Create trunk'
 
522
$ bzr mv dir2 dir1
 
523
$ bzr commit -m 'Moved dir2 into dir1'
 
524
 
 
525
$ bzr branch . -r 1 ../branch
 
526
$ cd ../branch
 
527
$ bzr mv dir1 dir2
 
528
$ bzr commit -m 'Moved dir1 into dir2'
 
529
 
 
530
$ bzr merge ../trunk
 
531
2>Conflict moving dir2/dir1 into dir2.  Cancelled move.
 
532
2>1 conflicts encountered.
 
533
"""
 
534
 
 
535
    def test_take_this(self):
 
536
        self.run_script("""
 
537
$ bzr resolve dir2
 
538
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
539
""")
 
540
 
 
541
    def test_take_other(self):
 
542
        self.run_script("""
 
543
$ bzr mv dir2/dir1 dir1
 
544
$ bzr mv dir2 dir1
 
545
$ bzr resolve dir2
 
546
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
547
""")
 
548
 
 
549
    def test_resolve_taking_this(self):
 
550
        self.run_script("""
 
551
$ bzr resolve --take-this dir2
 
552
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
553
""")
 
554
        self.failUnlessExists('dir2')
 
555
 
 
556
    def test_resolve_taking_other(self):
 
557
        self.run_script("""
 
558
$ bzr resolve --take-other dir2
 
559
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
560
""")
 
561
        self.failUnlessExists('dir1')
 
562
 
 
563
 
 
564
class TestResolveNonDirectoryParent(TestResolveConflicts):
 
565
 
 
566
    preamble = """
 
567
$ bzr init trunk
 
568
$ cd trunk
 
569
$ bzr mkdir foo
 
570
$ bzr commit -m 'Create trunk'
 
571
$ echo "Boing" >foo/bar
 
572
$ bzr add foo/bar
 
573
$ bzr commit -m 'Add foo/bar'
 
574
 
 
575
$ bzr branch . -r 1 ../branch
 
576
$ cd ../branch
 
577
$ rm -r foo
 
578
$ echo "Boo!" >foo
 
579
$ bzr commit -m 'foo is now a file'
 
580
 
 
581
$ bzr merge ../trunk
 
582
2>+N  foo.new/bar
 
583
2>RK  foo => foo.new/
 
584
# FIXME: The message is misleading, foo.new *is* a directory when the message
 
585
# is displayed -- vila 090916
 
586
2>Conflict: foo.new is not a directory, but has files in it.  Created directory.
 
587
2>1 conflicts encountered.
 
588
"""
 
589
 
 
590
    def test_take_this(self):
 
591
        self.run_script("""
 
592
$ bzr rm foo.new --force
 
593
# FIXME: Isn't it weird that foo is now unkown even if foo.new has been put
 
594
# aside ? -- vila 090916
 
595
$ bzr add foo
 
596
$ bzr resolve foo.new
 
597
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
598
""")
 
599
 
 
600
    def test_take_other(self):
 
601
        self.run_script("""
 
602
$ bzr rm foo --force
 
603
$ bzr mv foo.new foo
 
604
$ bzr resolve foo
 
605
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
606
""")
 
607
 
 
608
    def test_resolve_taking_this(self):
 
609
        self.run_script("""
 
610
$ bzr resolve --take-this foo.new
 
611
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
612
""")
 
613
 
 
614
    def test_resolve_taking_other(self):
 
615
        self.run_script("""
 
616
$ bzr resolve --take-other foo.new
 
617
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
618
""")
 
619
 
 
620
 
 
621
class TestMalformedTransform(script.TestCaseWithTransportAndScript):
 
622
 
 
623
    def test_bug_430129(self):
 
624
        # This is nearly like TestResolveNonDirectoryParent but with branch and
 
625
        # trunk switched. As such it should certainly produce the same
 
626
        # conflict.
 
627
        self.run_script("""
 
628
$ bzr init trunk
 
629
$ cd trunk
 
630
$ bzr mkdir foo
 
631
$ bzr commit -m 'Create trunk'
 
632
$ rm -r foo
 
633
$ echo "Boo!" >foo
 
634
$ bzr commit -m 'foo is now a file'
 
635
 
 
636
$ bzr branch . -r 1 ../branch
 
637
$ cd ../branch
 
638
$ echo "Boing" >foo/bar
 
639
$ bzr add foo/bar
 
640
$ bzr commit -m 'Add foo/bar'
 
641
 
 
642
$ bzr merge ../trunk
 
643
2>bzr: ERROR: Tree transform is malformed [('unversioned executability', 'new-1')]
 
644
""")
 
645
 
 
646
 
 
647
class TestResolveActionOption(tests.TestCase):
 
648
 
 
649
    def setUp(self):
 
650
        super(TestResolveActionOption, self).setUp()
 
651
        self.options = [conflicts.ResolveActionOption()]
 
652
        self.parser = option.get_optparser(dict((o.name, o)
 
653
                                                for o in self.options))
 
654
 
 
655
    def parse(self, args):
 
656
        return self.parser.parse_args(args)
 
657
 
 
658
    def test_unknown_action(self):
 
659
        self.assertRaises(errors.BadOptionValue,
 
660
                          self.parse, ['--action', 'take-me-to-the-moon'])
 
661
 
 
662
    def test_done(self):
 
663
        opts, args = self.parse(['--action', 'done'])
 
664
        self.assertEqual({'action':'done'}, opts)
 
665
 
 
666
    def test_take_this(self):
 
667
        opts, args = self.parse(['--action', 'take-this'])
 
668
        self.assertEqual({'action': 'take_this'}, opts)
 
669
        opts, args = self.parse(['--take-this'])
 
670
        self.assertEqual({'action': 'take_this'}, opts)
 
671
 
 
672
    def test_take_other(self):
 
673
        opts, args = self.parse(['--action', 'take-other'])
 
674
        self.assertEqual({'action': 'take_other'}, opts)
 
675
        opts, args = self.parse(['--take-other'])
 
676
        self.assertEqual({'action': 'take_other'}, opts)