/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
4988.10.5 by John Arbash Meinel
Merge bzr.dev 5021 to resolve NEWS
1
# Copyright (C) 2005-2010 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 (
4597.2.23 by Vincent Ladeuil
Start translating blackbox tests into whitebox ones.
21
    branchbuilder,
4597.2.2 by Vincent Ladeuil
Cleanup conflict tests.
22
    bzrdir,
23
    conflicts,
24
    errors,
4597.3.51 by Vincent Ladeuil
Implement conflicts.ResolveActionOption.
25
    option,
4597.2.2 by Vincent Ladeuil
Cleanup conflict tests.
26
    tests,
4597.2.23 by Vincent Ladeuil
Start translating blackbox tests into whitebox ones.
27
    workingtree,
4597.2.2 by Vincent Ladeuil
Cleanup conflict tests.
28
    )
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
29
from bzrlib.tests import script
1185.14.8 by Aaron Bentley
Added test_commit.py
30
1534.10.4 by Aaron Bentley
Implemented conflict serialization
31
4597.2.26 by Vincent Ladeuil
Fix bug #529968 by renaming the kept file on content conflicts.
32
def load_tests(standard_tests, module, loader):
33
    result = loader.suiteClass()
34
35
    sp_tests, remaining_tests = tests.split_suite_by_condition(
36
        standard_tests, tests.condition_isinstance((
37
                TestResolveContentConflicts,
38
                )))
39
    tests.multiply_tests(sp_tests, content_conflict_scenarios(), result)
40
41
    # No parametrization for the remaining tests
42
    result.addTests(remaining_tests)
43
44
    return result
45
46
1185.14.8 by Aaron Bentley
Added test_commit.py
47
# 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.
48
# RBC 20060124 is that not tested in test_commit.py ?
1185.14.8 by Aaron Bentley
Added test_commit.py
49
1666.1.4 by Robert Collins
* 'Metadir' is now the default disk format. This improves behaviour in
50
# The order of 'path' here is important - do not let it
51
# 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.
52
# u'\xe5' == a with circle
53
# '\xc3\xae' == u'\xee' == i with hat
4597.2.2 by Vincent Ladeuil
Cleanup conflict tests.
54
# So these are u'path' and 'id' only with a circle and a hat. (shappo?)
55
example_conflicts = conflicts.ConflictList(
56
    [conflicts.MissingParent('Not deleting', u'p\xe5thg', '\xc3\xaedg'),
57
     conflicts.ContentsConflict(u'p\xe5tha', None, '\xc3\xaeda'),
58
     conflicts.TextConflict(u'p\xe5tha'),
59
     conflicts.PathConflict(u'p\xe5thb', u'p\xe5thc', '\xc3\xaedb'),
60
     conflicts.DuplicateID('Unversioned existing file',
61
                           u'p\xe5thc', u'p\xe5thc2',
62
                           '\xc3\xaedc', '\xc3\xaedc'),
63
    conflicts.DuplicateEntry('Moved existing file to',
64
                             u'p\xe5thdd.moved', u'p\xe5thd',
65
                             '\xc3\xaedd', None),
66
    conflicts.ParentLoop('Cancelled move', u'p\xe5the', u'p\xe5th2e',
67
                         None, '\xc3\xaed2e'),
68
    conflicts.UnversionedParent('Versioned directory',
69
                                u'p\xe5thf', '\xc3\xaedf'),
70
    conflicts.NonDirectoryParent('Created directory',
71
                                 u'p\xe5thg', '\xc3\xaedg'),
1534.10.22 by Aaron Bentley
Got ConflictList implemented
72
])
1534.10.4 by Aaron Bentley
Implemented conflict serialization
73
74
4597.2.2 by Vincent Ladeuil
Cleanup conflict tests.
75
class TestConflicts(tests.TestCaseWithTransport):
1185.14.8 by Aaron Bentley
Added test_commit.py
76
77
    def test_conflicts(self):
78
        """Conflicts are detected properly"""
4597.2.3 by Vincent Ladeuil
More cleanup.
79
        # Use BzrDirFormat6 so we can fake conflicts
80
        tree = self.make_branch_and_tree('.', format=bzrdir.BzrDirFormat6())
81
        self.build_tree_contents([('hello', 'hello world4'),
82
                                  ('hello.THIS', 'hello world2'),
83
                                  ('hello.BASE', 'hello world1'),
84
                                  ('hello.OTHER', 'hello world3'),
85
                                  ('hello.sploo.BASE', 'yellowworld'),
86
                                  ('hello.sploo.OTHER', 'yellowworld2'),
87
                                  ])
2255.2.61 by John Arbash Meinel
Find callers of list_files() and make sure the tree is always locked.
88
        tree.lock_read()
4597.2.28 by Vincent Ladeuil
Use assertLength where appropriate.
89
        self.assertLength(6, list(tree.list_files()))
2255.2.61 by John Arbash Meinel
Find callers of list_files() and make sure the tree is always locked.
90
        tree.unlock()
4597.2.3 by Vincent Ladeuil
More cleanup.
91
        tree_conflicts = tree.conflicts()
4597.2.28 by Vincent Ladeuil
Use assertLength where appropriate.
92
        self.assertLength(2, tree_conflicts)
4597.2.3 by Vincent Ladeuil
More cleanup.
93
        self.assertTrue('hello' in tree_conflicts[0].path)
94
        self.assertTrue('hello.sploo' in tree_conflicts[1].path)
95
        conflicts.restore('hello')
96
        conflicts.restore('hello.sploo')
4597.2.28 by Vincent Ladeuil
Use assertLength where appropriate.
97
        self.assertLength(0, tree.conflicts())
1185.35.1 by Aaron Bentley
Implemented conflicts.restore
98
        self.assertFileEqual('hello world2', 'hello')
3376.2.4 by Martin Pool
Remove every assert statement from bzrlib!
99
        self.assertFalse(os.path.lexists('hello.sploo'))
4597.2.3 by Vincent Ladeuil
More cleanup.
100
        self.assertRaises(errors.NotConflicted, conflicts.restore, 'hello')
101
        self.assertRaises(errors.NotConflicted,
102
                          conflicts.restore, 'hello.sploo')
1534.10.4 by Aaron Bentley
Implemented conflict serialization
103
1558.12.9 by Aaron Bentley
Handle resolving conflicts with directories properly
104
    def test_resolve_conflict_dir(self):
105
        tree = self.make_branch_and_tree('.')
4597.2.3 by Vincent Ladeuil
More cleanup.
106
        self.build_tree_contents([('hello', 'hello world4'),
107
                                  ('hello.THIS', 'hello world2'),
108
                                  ('hello.BASE', 'hello world1'),
109
                                  ])
110
        os.mkdir('hello.OTHER')
1558.12.9 by Aaron Bentley
Handle resolving conflicts with directories properly
111
        tree.add('hello', 'q')
4597.2.3 by Vincent Ladeuil
More cleanup.
112
        l = conflicts.ConflictList([conflicts.TextConflict('hello')])
1558.12.9 by Aaron Bentley
Handle resolving conflicts with directories properly
113
        l.remove_files(tree)
114
1551.15.58 by Aaron Bentley
Status honours selected paths for conflicts (#127606)
115
    def test_select_conflicts(self):
116
        tree = self.make_branch_and_tree('.')
4597.2.3 by Vincent Ladeuil
More cleanup.
117
        clist = conflicts.ConflictList
118
119
        def check_select(not_selected, selected, paths, **kwargs):
120
            self.assertEqual(
121
                (not_selected, selected),
122
                tree_conflicts.select_conflicts(tree, paths, **kwargs))
123
124
        foo = conflicts.ContentsConflict('foo')
125
        bar = conflicts.ContentsConflict('bar')
126
        tree_conflicts = clist([foo, bar])
127
128
        check_select(clist([bar]), clist([foo]), ['foo'])
129
        check_select(clist(), tree_conflicts,
130
                     [''], ignore_misses=True, recurse=True)
131
132
        foobaz  = conflicts.ContentsConflict('foo/baz')
133
        tree_conflicts = clist([foobaz, bar])
134
135
        check_select(clist([bar]), clist([foobaz]),
136
                     ['foo'], ignore_misses=True, recurse=True)
137
138
        qux = conflicts.PathConflict('qux', 'foo/baz')
139
        tree_conflicts = clist([qux])
140
141
        check_select(clist(), tree_conflicts,
142
                     ['foo'], ignore_misses=True, recurse=True)
143
        check_select (tree_conflicts, clist(), ['foo'], ignore_misses=True)
1551.15.58 by Aaron Bentley
Status honours selected paths for conflicts (#127606)
144
3017.2.1 by Aaron Bentley
Revert now resolves conflicts recursively (#102739)
145
    def test_resolve_conflicts_recursive(self):
146
        tree = self.make_branch_and_tree('.')
147
        self.build_tree(['dir/', 'dir/hello'])
148
        tree.add(['dir', 'dir/hello'])
4597.2.3 by Vincent Ladeuil
More cleanup.
149
150
        dirhello = conflicts.ConflictList([conflicts.TextConflict('dir/hello')])
151
        tree.set_conflicts(dirhello)
152
153
        conflicts.resolve(tree, ['dir'], recursive=False, ignore_misses=True)
154
        self.assertEqual(dirhello, tree.conflicts())
155
156
        conflicts.resolve(tree, ['dir'], recursive=True, ignore_misses=True)
157
        self.assertEqual(conflicts.ConflictList([]), tree.conflicts())
4773.1.1 by Vincent Ladeuil
Cleanup imports in test_conflicts
158
159
4597.3.43 by Vincent Ladeuil
Cleanups, ready to record.
160
class TestConflictStanzas(tests.TestCase):
161
162
    def test_stanza_roundtrip(self):
163
        # write and read our example stanza.
164
        stanza_iter = example_conflicts.to_stanzas()
165
        processed = conflicts.ConflictList.from_stanzas(stanza_iter)
166
        for o, p in zip(processed, example_conflicts):
167
            self.assertEqual(o, p)
168
169
            self.assertIsInstance(o.path, unicode)
170
171
            if o.file_id is not None:
172
                self.assertIsInstance(o.file_id, str)
173
174
            conflict_path = getattr(o, 'conflict_path', None)
175
            if conflict_path is not None:
176
                self.assertIsInstance(conflict_path, unicode)
177
178
            conflict_file_id = getattr(o, 'conflict_file_id', None)
179
            if conflict_file_id is not None:
180
                self.assertIsInstance(conflict_file_id, str)
181
182
    def test_stanzification(self):
183
        for stanza in example_conflicts.to_stanzas():
184
            if 'file_id' in stanza:
185
                # In Stanza form, the file_id has to be unicode.
186
                self.assertStartsWith(stanza['file_id'], u'\xeed')
187
            self.assertStartsWith(stanza['path'], u'p\xe5th')
188
            if 'conflict_path' in stanza:
189
                self.assertStartsWith(stanza['conflict_path'], u'p\xe5th')
190
            if 'conflict_file_id' in stanza:
191
                self.assertStartsWith(stanza['conflict_file_id'], u'\xeed')
192
193
4597.3.74 by Vincent Ladeuil
Add a FIXME about rewriting shell-like tests into real whitebox tests.
194
# FIXME: The shell-like tests should be converted to real whitebox tests... or
195
# moved to a blackbox module -- vila 20100205
196
4597.3.31 by Vincent Ladeuil
Implement --interactive for MissingParent.
197
# FIXME: Tests missing for DuplicateID conflict type
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
198
class TestResolveConflicts(script.TestCaseWithTransportAndScript):
199
200
    preamble = None # The setup script set by daughter classes
201
202
    def setUp(self):
203
        super(TestResolveConflicts, self).setUp()
204
        self.run_script(self.preamble)
205
206
207
class TestResolveTextConflicts(TestResolveConflicts):
208
    # TBC
209
    pass
210
211
4597.2.26 by Vincent Ladeuil
Fix bug #529968 by renaming the kept file on content conflicts.
212
def content_conflict_scenarios():
213
    return [('file,None', dict(_this_actions='modify_file',
214
                               _check_this='file_has_more_content',
215
                               _other_actions='delete_file',
216
                               _check_other='file_doesnt_exist',
217
                               )),
218
            ('None,file', dict(_this_actions='delete_file',
219
                               _check_this='file_doesnt_exist',
220
                               _other_actions='modify_file',
221
                               _check_other='file_has_more_content',
222
                               )),
223
            ]
224
225
4597.2.23 by Vincent Ladeuil
Start translating blackbox tests into whitebox ones.
226
class TestResolveContentConflicts(tests.TestCaseWithTransport):
227
4597.2.26 by Vincent Ladeuil
Fix bug #529968 by renaming the kept file on content conflicts.
228
    # Set by load_tests
229
    this_actions = None
230
    other_actions = None
4597.2.25 by Vincent Ladeuil
Reproduce bug #529968.
231
4597.2.23 by Vincent Ladeuil
Start translating blackbox tests into whitebox ones.
232
    def setUp(self):
233
        super(TestResolveContentConflicts, self).setUp()
234
        builder = self.make_branch_builder('trunk')
235
        builder.start_series()
236
        # Create an empty trunk
237
        builder.build_snapshot('start', None, [
238
                ('add', ('', 'root-id', 'directory', ''))])
239
        # Add a minimal base content
240
        builder.build_snapshot('base', ['start'], [
241
                ('add', ('file', 'file-id', 'file', 'trunk content\n'))])
242
        # Modify the base content in branch
4597.2.26 by Vincent Ladeuil
Fix bug #529968 by renaming the kept file on content conflicts.
243
        other_actions = self._get_actions(self._other_actions)
244
        builder.build_snapshot('other', ['base'], other_actions())
4597.2.23 by Vincent Ladeuil
Start translating blackbox tests into whitebox ones.
245
        # Modify the base content in trunk
4597.2.26 by Vincent Ladeuil
Fix bug #529968 by renaming the kept file on content conflicts.
246
        this_actions = self._get_actions(self._this_actions)
247
        builder.build_snapshot('this', ['base'], this_actions())
4597.2.23 by Vincent Ladeuil
Start translating blackbox tests into whitebox ones.
248
        builder.finish_series()
249
        self.builder = builder
250
4597.2.26 by Vincent Ladeuil
Fix bug #529968 by renaming the kept file on content conflicts.
251
    def _get_actions(self, name):
252
        return getattr(self, 'do_%s' % name)
253
254
    def _get_check(self, name):
255
        return getattr(self, 'check_%s' % name)
256
257
    def do_modify_file(self):
258
        return [('modify', ('file-id', 'trunk content\nmore content\n'))]
259
260
    def check_file_has_more_content(self):
261
        self.assertFileEqual('trunk content\nmore content\n', 'branch/file')
262
263
    def do_delete_file(self):
264
        return [('unversion', 'file-id')]
265
266
    def check_file_doesnt_exist(self):
267
        self.failIfExists('branch/file')
268
4597.2.24 by Vincent Ladeuil
Translate one more test.
269
    def _merge_other_into_this(self):
4597.2.23 by Vincent Ladeuil
Start translating blackbox tests into whitebox ones.
270
        b = self.builder.get_branch()
271
        wt = b.bzrdir.sprout('branch').open_workingtree()
272
        wt.merge_from_branch(b, 'other')
4597.2.24 by Vincent Ladeuil
Translate one more test.
273
        return wt
274
275
    def assertConflict(self, wt, ctype, **kwargs):
4597.2.23 by Vincent Ladeuil
Start translating blackbox tests into whitebox ones.
276
        confs = wt.conflicts()
4597.2.28 by Vincent Ladeuil
Use assertLength where appropriate.
277
        self.assertLength(1, confs)
4597.2.23 by Vincent Ladeuil
Start translating blackbox tests into whitebox ones.
278
        c = confs[0]
4597.2.24 by Vincent Ladeuil
Translate one more test.
279
        self.assertIsInstance(c, ctype)
280
        sentinel = object() # An impossible value
281
        for k, v in kwargs.iteritems():
282
            self.assertEqual(v, getattr(c, k, sentinel))
283
4597.2.28 by Vincent Ladeuil
Use assertLength where appropriate.
284
    def check_resolved(self, wt, item, action):
4597.2.24 by Vincent Ladeuil
Translate one more test.
285
        conflicts.resolve(wt, [item], action=action)
4597.2.23 by Vincent Ladeuil
Start translating blackbox tests into whitebox ones.
286
        # Check that we don't have any conflicts nor unknown left
4597.2.28 by Vincent Ladeuil
Use assertLength where appropriate.
287
        self.assertLength(0, wt.conflicts())
288
        self.assertLength(0, list(wt.unknowns()))
4597.2.23 by Vincent Ladeuil
Start translating blackbox tests into whitebox ones.
289
4597.2.24 by Vincent Ladeuil
Translate one more test.
290
    def test_resolve_taking_this(self):
291
        wt = self._merge_other_into_this()
292
        self.assertConflict(wt, conflicts.ContentsConflict,
293
                            path='file', file_id='file-id',)
4597.2.28 by Vincent Ladeuil
Use assertLength where appropriate.
294
        self.check_resolved(wt, 'file', 'take_this')
4597.2.26 by Vincent Ladeuil
Fix bug #529968 by renaming the kept file on content conflicts.
295
        check_this = self._get_check(self._check_this)
296
        check_this()
4597.2.24 by Vincent Ladeuil
Translate one more test.
297
298
    def test_resolve_taking_other(self):
299
        wt = self._merge_other_into_this()
300
        self.assertConflict(wt, conflicts.ContentsConflict,
301
                            path='file', file_id='file-id',)
4597.2.28 by Vincent Ladeuil
Use assertLength where appropriate.
302
        self.check_resolved(wt, 'file', 'take_other')
4597.2.26 by Vincent Ladeuil
Fix bug #529968 by renaming the kept file on content conflicts.
303
        check_other = self._get_check(self._check_other)
304
        check_other()
4597.3.28 by Vincent Ladeuil
Implement --interactive for ContentsConflict.
305
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
306
4597.3.31 by Vincent Ladeuil
Implement --interactive for MissingParent.
307
class TestResolveDuplicateEntry(TestResolveConflicts):
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
308
309
    preamble = """
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
310
$ bzr init trunk
311
$ cd trunk
312
$ echo 'trunk content' >file
313
$ bzr add file
314
$ bzr commit -m 'Create trunk'
4597.2.23 by Vincent Ladeuil
Start translating blackbox tests into whitebox ones.
315
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
316
$ echo 'trunk content too' >file2
317
$ bzr add file2
318
$ bzr commit -m 'Add file2 in trunk'
319
320
$ bzr branch . -r 1 ../branch
321
$ cd ../branch
322
$ echo 'branch content' >file2
323
$ bzr add file2
324
$ bzr commit -m 'Add file2 in branch'
325
326
$ bzr merge ../trunk
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
327
2>+N  file2
328
2>R   file2 => file2.moved
329
2>Conflict adding file file2.  Moved existing file to file2.moved.
330
2>1 conflicts encountered.
331
"""
332
333
    def test_keep_this(self):
334
        self.run_script("""
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
335
$ bzr rm file2  --force
336
$ bzr mv file2.moved file2
337
$ bzr resolve file2
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
341
    def test_keep_other(self):
342
        self.failIfExists('branch/file2.moved')
343
        self.run_script("""
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
344
$ bzr rm file2.moved --force
345
$ bzr resolve file2
346
$ 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.
347
""")
348
        self.failIfExists('branch/file2.moved')
349
4597.3.67 by Vincent Ladeuil
Settle with --take-this and --take-other as action names.
350
    def test_resolve_taking_this(self):
4597.3.19 by Vincent Ladeuil
Some failing tests.
351
        self.run_script("""
4597.3.67 by Vincent Ladeuil
Settle with --take-this and --take-other as action names.
352
$ bzr resolve --take-this file2
4597.3.19 by Vincent Ladeuil
Some failing tests.
353
$ bzr commit --strict -m 'No more conflicts nor unknown files'
354
""")
355
4597.3.67 by Vincent Ladeuil
Settle with --take-this and --take-other as action names.
356
    def test_resolve_taking_other(self):
4597.3.19 by Vincent Ladeuil
Some failing tests.
357
        self.run_script("""
4597.3.67 by Vincent Ladeuil
Settle with --take-this and --take-other as action names.
358
$ bzr resolve --take-other file2
4597.3.19 by Vincent Ladeuil
Some failing tests.
359
$ bzr commit --strict -m 'No more conflicts nor unknown files'
360
""")
361
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
362
363
class TestResolveUnversionedParent(TestResolveConflicts):
364
4597.3.29 by Vincent Ladeuil
Fix bogus tests.
365
    # FIXME: Add the reverse tests: dir deleted in trunk, file added in branch
366
4597.3.30 by Vincent Ladeuil
Light changes learned while starting to understand multiple conflicts on
367
    # FIXME: While this *creates* UnversionedParent conflicts, this really only
368
    # tests MissingParent resolution :-/
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
369
    preamble = """
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
370
$ bzr init trunk
371
$ cd trunk
4597.3.29 by Vincent Ladeuil
Fix bogus tests.
372
$ mkdir dir
373
$ bzr add dir
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
374
$ bzr commit -m 'Create trunk'
4597.2.23 by Vincent Ladeuil
Start translating blackbox tests into whitebox ones.
375
4597.3.29 by Vincent Ladeuil
Fix bogus tests.
376
$ echo 'trunk content' >dir/file
377
$ bzr add dir/file
378
$ bzr commit -m 'Add dir/file in trunk'
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
379
380
$ bzr branch . -r 1 ../branch
381
$ cd ../branch
4597.3.29 by Vincent Ladeuil
Fix bogus tests.
382
$ bzr rm dir
383
$ bzr commit -m 'Remove dir in branch'
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
384
385
$ bzr merge ../trunk
4597.3.29 by Vincent Ladeuil
Fix bogus tests.
386
2>+N  dir/
387
2>+N  dir/file
388
2>Conflict adding files to dir.  Created directory.
389
2>Conflict because dir is not versioned, but has versioned children.  Versioned directory.
390
2>2 conflicts encountered.
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
391
"""
392
4597.3.67 by Vincent Ladeuil
Settle with --take-this and --take-other as action names.
393
    def test_take_this(self):
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
394
        self.run_script("""
4597.3.29 by Vincent Ladeuil
Fix bogus tests.
395
$ bzr rm dir  --force
396
$ bzr resolve dir
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
397
$ 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.
398
""")
399
4597.3.67 by Vincent Ladeuil
Settle with --take-this and --take-other as action names.
400
    def test_take_other(self):
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
401
        self.run_script("""
4597.3.29 by Vincent Ladeuil
Fix bogus tests.
402
$ bzr resolve dir
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
403
$ 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.
404
""")
405
406
407
class TestResolveMissingParent(TestResolveConflicts):
408
409
    preamble = """
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
410
$ bzr init trunk
411
$ cd trunk
412
$ mkdir dir
413
$ echo 'trunk content' >dir/file
414
$ bzr add
415
$ bzr commit -m 'Create trunk'
4597.2.23 by Vincent Ladeuil
Start translating blackbox tests into whitebox ones.
416
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
417
$ echo 'trunk content' >dir/file2
418
$ bzr add dir/file2
419
$ bzr commit -m 'Add dir/file2 in branch'
420
421
$ bzr branch . -r 1 ../branch
422
$ cd ../branch
423
$ bzr rm dir/file --force
424
$ bzr rm dir
425
$ bzr commit -m 'Remove dir/file'
426
427
$ bzr merge ../trunk
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
428
2>+N  dir/
429
2>+N  dir/file2
430
2>Conflict adding files to dir.  Created directory.
431
2>Conflict because dir is not versioned, but has versioned children.  Versioned directory.
432
2>2 conflicts encountered.
433
"""
434
435
    def test_keep_them_all(self):
436
        self.run_script("""
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
437
$ bzr resolve dir
438
$ 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.
439
""")
440
441
    def test_adopt_child(self):
442
        self.run_script("""
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
443
$ bzr mv dir/file2 file2
444
$ bzr rm dir --force
445
$ bzr resolve dir
446
$ 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.
447
""")
448
449
    def test_kill_them_all(self):
450
        self.run_script("""
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
451
$ bzr rm dir --force
452
$ bzr resolve dir
453
$ 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.
454
""")
455
4597.3.67 by Vincent Ladeuil
Settle with --take-this and --take-other as action names.
456
    def test_resolve_taking_this(self):
4597.3.31 by Vincent Ladeuil
Implement --interactive for MissingParent.
457
        self.run_script("""
4597.3.67 by Vincent Ladeuil
Settle with --take-this and --take-other as action names.
458
$ bzr resolve --take-this dir
4597.3.31 by Vincent Ladeuil
Implement --interactive for MissingParent.
459
$ bzr commit --strict -m 'No more conflicts nor unknown files'
460
""")
461
4597.3.67 by Vincent Ladeuil
Settle with --take-this and --take-other as action names.
462
    def test_resolve_taking_other(self):
4597.3.31 by Vincent Ladeuil
Implement --interactive for MissingParent.
463
        self.run_script("""
4597.3.67 by Vincent Ladeuil
Settle with --take-this and --take-other as action names.
464
$ bzr resolve --take-other dir
4597.3.31 by Vincent Ladeuil
Implement --interactive for MissingParent.
465
$ bzr commit --strict -m 'No more conflicts nor unknown files'
466
""")
467
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
468
469
class TestResolveDeletingParent(TestResolveConflicts):
470
471
    preamble = """
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
472
$ bzr init trunk
473
$ cd trunk
474
$ mkdir dir
475
$ echo 'trunk content' >dir/file
476
$ bzr add
477
$ bzr commit -m 'Create trunk'
4597.2.23 by Vincent Ladeuil
Start translating blackbox tests into whitebox ones.
478
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
479
$ bzr rm dir/file --force
480
$ bzr rm dir --force
481
$ bzr commit -m 'Remove dir/file'
482
483
$ bzr branch . -r 1 ../branch
484
$ cd ../branch
485
$ echo 'branch content' >dir/file2
486
$ bzr add dir/file2
487
$ bzr commit -m 'Add dir/file2 in branch'
488
489
$ bzr merge ../trunk
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
490
2>-D  dir/file
491
2>Conflict: can't delete dir because it is not empty.  Not deleting.
492
2>Conflict because dir is not versioned, but has versioned children.  Versioned directory.
493
2>2 conflicts encountered.
494
"""
495
496
    def test_keep_them_all(self):
497
        self.run_script("""
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
498
$ bzr resolve dir
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_adopt_child(self):
503
        self.run_script("""
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
504
$ bzr mv dir/file2 file2
505
$ bzr rm dir --force
506
$ bzr resolve dir
507
$ 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.
508
""")
509
510
    def test_kill_them_all(self):
511
        self.run_script("""
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
512
$ bzr rm dir --force
513
$ bzr resolve dir
514
$ 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.
515
""")
516
4597.3.67 by Vincent Ladeuil
Settle with --take-this and --take-other as action names.
517
    def test_resolve_taking_this(self):
4597.3.32 by Vincent Ladeuil
Implement --interactive for DeletingParent noting the inconsistency.
518
        self.run_script("""
4597.3.67 by Vincent Ladeuil
Settle with --take-this and --take-other as action names.
519
$ bzr resolve --take-this dir
4597.3.32 by Vincent Ladeuil
Implement --interactive for DeletingParent noting the inconsistency.
520
$ bzr commit --strict -m 'No more conflicts nor unknown files'
521
""")
522
4597.3.67 by Vincent Ladeuil
Settle with --take-this and --take-other as action names.
523
    def test_resolve_taking_other(self):
4597.3.32 by Vincent Ladeuil
Implement --interactive for DeletingParent noting the inconsistency.
524
        self.run_script("""
4597.3.67 by Vincent Ladeuil
Settle with --take-this and --take-other as action names.
525
$ bzr resolve --take-other dir
4597.3.32 by Vincent Ladeuil
Implement --interactive for DeletingParent noting the inconsistency.
526
$ bzr commit --strict -m 'No more conflicts nor unknown files'
527
""")
528
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
529
530
class TestResolvePathConflict(TestResolveConflicts):
531
532
    preamble = """
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
533
$ bzr init trunk
534
$ cd trunk
535
$ echo 'Boo!' >file
536
$ bzr add
537
$ bzr commit -m 'Create trunk'
4597.2.23 by Vincent Ladeuil
Start translating blackbox tests into whitebox ones.
538
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
539
$ bzr mv file file-in-trunk
540
$ bzr commit -m 'Renamed to file-in-trunk'
541
542
$ bzr branch . -r 1 ../branch
543
$ cd ../branch
544
$ bzr mv file file-in-branch
545
$ bzr commit -m 'Renamed to file-in-branch'
546
547
$ bzr merge ../trunk
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
548
2>R   file-in-branch => file-in-trunk
549
2>Path conflict: file-in-branch / file-in-trunk
550
2>1 conflicts encountered.
551
"""
552
553
    def test_keep_source(self):
554
        self.run_script("""
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
555
$ bzr resolve file-in-trunk
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
559
    def test_keep_target(self):
560
        self.run_script("""
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
561
$ bzr mv file-in-trunk file-in-branch
562
$ bzr resolve file-in-branch
563
$ 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.
564
""")
565
4597.3.67 by Vincent Ladeuil
Settle with --take-this and --take-other as action names.
566
    def test_resolve_taking_this(self):
4597.3.33 by Vincent Ladeuil
Implement --interactive for PathConflict.
567
        self.run_script("""
4597.3.67 by Vincent Ladeuil
Settle with --take-this and --take-other as action names.
568
$ bzr resolve --take-this file-in-branch
4597.3.33 by Vincent Ladeuil
Implement --interactive for PathConflict.
569
$ bzr commit --strict -m 'No more conflicts nor unknown files'
570
""")
571
4597.3.67 by Vincent Ladeuil
Settle with --take-this and --take-other as action names.
572
    def test_resolve_taking_other(self):
4597.3.33 by Vincent Ladeuil
Implement --interactive for PathConflict.
573
        self.run_script("""
4597.3.67 by Vincent Ladeuil
Settle with --take-this and --take-other as action names.
574
$ bzr resolve --take-other file-in-branch
4597.3.33 by Vincent Ladeuil
Implement --interactive for PathConflict.
575
$ bzr commit --strict -m 'No more conflicts nor unknown files'
576
""")
577
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
578
579
class TestResolveParentLoop(TestResolveConflicts):
580
581
    preamble = """
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
582
$ bzr init trunk
583
$ cd trunk
584
$ bzr mkdir dir1
585
$ bzr mkdir dir2
586
$ bzr commit -m 'Create trunk'
4597.2.23 by Vincent Ladeuil
Start translating blackbox tests into whitebox ones.
587
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
588
$ bzr mv dir2 dir1
589
$ bzr commit -m 'Moved dir2 into dir1'
590
591
$ bzr branch . -r 1 ../branch
592
$ cd ../branch
593
$ bzr mv dir1 dir2
594
$ bzr commit -m 'Moved dir1 into dir2'
595
596
$ bzr merge ../trunk
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
597
2>Conflict moving dir2/dir1 into dir2.  Cancelled move.
598
2>1 conflicts encountered.
599
"""
600
4597.3.67 by Vincent Ladeuil
Settle with --take-this and --take-other as action names.
601
    def test_take_this(self):
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
602
        self.run_script("""
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
603
$ bzr resolve dir2
604
$ 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.
605
""")
606
4597.3.67 by Vincent Ladeuil
Settle with --take-this and --take-other as action names.
607
    def test_take_other(self):
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
608
        self.run_script("""
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
609
$ bzr mv dir2/dir1 dir1
610
$ bzr mv dir2 dir1
611
$ bzr resolve dir2
612
$ 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.
613
""")
614
4597.3.67 by Vincent Ladeuil
Settle with --take-this and --take-other as action names.
615
    def test_resolve_taking_this(self):
4597.3.34 by Vincent Ladeuil
Implement --interactive for ParentLoop.
616
        self.run_script("""
4597.3.67 by Vincent Ladeuil
Settle with --take-this and --take-other as action names.
617
$ bzr resolve --take-this dir2
4597.3.34 by Vincent Ladeuil
Implement --interactive for ParentLoop.
618
$ bzr commit --strict -m 'No more conflicts nor unknown files'
619
""")
4597.3.64 by Vincent Ladeuil
Fixed as per Aaron's remark.
620
        self.failUnlessExists('dir2')
4597.3.34 by Vincent Ladeuil
Implement --interactive for ParentLoop.
621
4597.3.67 by Vincent Ladeuil
Settle with --take-this and --take-other as action names.
622
    def test_resolve_taking_other(self):
4597.3.34 by Vincent Ladeuil
Implement --interactive for ParentLoop.
623
        self.run_script("""
4597.3.67 by Vincent Ladeuil
Settle with --take-this and --take-other as action names.
624
$ bzr resolve --take-other dir2
4597.3.34 by Vincent Ladeuil
Implement --interactive for ParentLoop.
625
$ bzr commit --strict -m 'No more conflicts nor unknown files'
626
""")
4597.3.64 by Vincent Ladeuil
Fixed as per Aaron's remark.
627
        self.failUnlessExists('dir1')
4597.3.34 by Vincent Ladeuil
Implement --interactive for ParentLoop.
628
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
629
630
class TestResolveNonDirectoryParent(TestResolveConflicts):
631
632
    preamble = """
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
633
$ bzr init trunk
634
$ cd trunk
635
$ bzr mkdir foo
636
$ bzr commit -m 'Create trunk'
637
$ echo "Boing" >foo/bar
638
$ bzr add foo/bar
639
$ bzr commit -m 'Add foo/bar'
640
641
$ bzr branch . -r 1 ../branch
642
$ cd ../branch
643
$ rm -r foo
644
$ echo "Boo!" >foo
645
$ bzr commit -m 'foo is now a file'
646
647
$ bzr merge ../trunk
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
648
2>+N  foo.new/bar
649
2>RK  foo => foo.new/
650
# FIXME: The message is misleading, foo.new *is* a directory when the message
651
# is displayed -- vila 090916
652
2>Conflict: foo.new is not a directory, but has files in it.  Created directory.
653
2>1 conflicts encountered.
654
"""
655
4597.3.67 by Vincent Ladeuil
Settle with --take-this and --take-other as action names.
656
    def test_take_this(self):
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
657
        self.run_script("""
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
658
$ bzr rm foo.new --force
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
659
# FIXME: Isn't it weird that foo is now unkown even if foo.new has been put
660
# aside ? -- vila 090916
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
661
$ bzr add foo
662
$ bzr resolve foo.new
663
$ 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.
664
""")
665
4597.3.67 by Vincent Ladeuil
Settle with --take-this and --take-other as action names.
666
    def test_take_other(self):
4597.3.35 by Vincent Ladeuil
Implement --interactive for NonDirectoryParent, sort of.
667
        self.run_script("""
668
$ bzr rm foo --force
669
$ bzr mv foo.new foo
670
$ bzr resolve foo
671
$ bzr commit --strict -m 'No more conflicts nor unknown files'
672
""")
673
4597.3.67 by Vincent Ladeuil
Settle with --take-this and --take-other as action names.
674
    def test_resolve_taking_this(self):
4597.3.35 by Vincent Ladeuil
Implement --interactive for NonDirectoryParent, sort of.
675
        self.run_script("""
4597.3.67 by Vincent Ladeuil
Settle with --take-this and --take-other as action names.
676
$ bzr resolve --take-this foo.new
4597.3.35 by Vincent Ladeuil
Implement --interactive for NonDirectoryParent, sort of.
677
$ bzr commit --strict -m 'No more conflicts nor unknown files'
678
""")
679
4597.3.67 by Vincent Ladeuil
Settle with --take-this and --take-other as action names.
680
    def test_resolve_taking_other(self):
4597.3.35 by Vincent Ladeuil
Implement --interactive for NonDirectoryParent, sort of.
681
        self.run_script("""
4597.3.67 by Vincent Ladeuil
Settle with --take-this and --take-other as action names.
682
$ bzr resolve --take-other foo.new
4597.3.35 by Vincent Ladeuil
Implement --interactive for NonDirectoryParent, sort of.
683
$ bzr commit --strict -m 'No more conflicts nor unknown files'
684
""")
685
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
686
687
class TestMalformedTransform(script.TestCaseWithTransportAndScript):
688
689
    def test_bug_430129(self):
690
        # This is nearly like TestResolveNonDirectoryParent but with branch and
691
        # trunk switched. As such it should certainly produce the same
692
        # conflict.
693
        self.run_script("""
4597.3.15 by Vincent Ladeuil
Update to new shell-like tests syntax.
694
$ bzr init trunk
695
$ cd trunk
696
$ bzr mkdir foo
697
$ bzr commit -m 'Create trunk'
698
$ rm -r foo
699
$ echo "Boo!" >foo
700
$ bzr commit -m 'foo is now a file'
701
702
$ bzr branch . -r 1 ../branch
703
$ cd ../branch
704
$ echo "Boing" >foo/bar
705
$ bzr add foo/bar
706
$ bzr commit -m 'Add foo/bar'
707
708
$ bzr merge ../trunk
4597.3.12 by Vincent Ladeuil
Start writing tests for all expected conflict resolution actions.
709
2>bzr: ERROR: Tree transform is malformed [('unversioned executability', 'new-1')]
710
""")
4597.3.51 by Vincent Ladeuil
Implement conflicts.ResolveActionOption.
711
712
713
class TestResolveActionOption(tests.TestCase):
714
715
    def setUp(self):
716
        super(TestResolveActionOption, self).setUp()
717
        self.options = [conflicts.ResolveActionOption()]
718
        self.parser = option.get_optparser(dict((o.name, o)
719
                                                for o in self.options))
720
721
    def parse(self, args):
722
        return self.parser.parse_args(args)
723
724
    def test_unknown_action(self):
725
        self.assertRaises(errors.BadOptionValue,
726
                          self.parse, ['--action', 'take-me-to-the-moon'])
727
728
    def test_done(self):
729
        opts, args = self.parse(['--action', 'done'])
730
        self.assertEqual({'action':'done'}, opts)
731
4597.3.67 by Vincent Ladeuil
Settle with --take-this and --take-other as action names.
732
    def test_take_this(self):
733
        opts, args = self.parse(['--action', 'take-this'])
734
        self.assertEqual({'action': 'take_this'}, opts)
735
        opts, args = self.parse(['--take-this'])
736
        self.assertEqual({'action': 'take_this'}, opts)
4597.3.51 by Vincent Ladeuil
Implement conflicts.ResolveActionOption.
737
4597.3.67 by Vincent Ladeuil
Settle with --take-this and --take-other as action names.
738
    def test_take_other(self):
739
        opts, args = self.parse(['--action', 'take-other'])
740
        self.assertEqual({'action': 'take_other'}, opts)
741
        opts, args = self.parse(['--take-other'])
742
        self.assertEqual({'action': 'take_other'}, opts)