/brz/remove-bazaar

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