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