/brz/remove-bazaar

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

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_merge.py

  • Committer: John Arbash Meinel
  • Date: 2008-10-08 21:56:12 UTC
  • mto: This revision was merged to the branch mainline in revision 3773.
  • Revision ID: john@arbash-meinel.com-20081008215612-y9v94tqxreqoangx
Simplify the --raw mode.

I didn't realize, but the only node that is special cased is the 'root' node,
and to read it, you actually have to parse it directly, because the
compressed bytes start immediately after the end of the header, rather than
having any padding before the zlib bytes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
 
1
# Copyright (C) 2006, 2007 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
#
17
17
# Author: Aaron Bentley <aaron.bentley@utoronto.ca>
18
18
 
21
21
 
22
22
import os
23
23
 
24
 
from bzrlib import (
25
 
    branch,
26
 
    bzrdir,
27
 
    conflicts,
28
 
    errors,
29
 
    merge_directive,
30
 
    osutils,
31
 
    tests,
32
 
    urlutils,
33
 
    workingtree,
34
 
    )
35
 
 
36
 
 
37
 
class TestMerge(tests.TestCaseWithTransport):
 
24
from bzrlib import merge_directive
 
25
from bzrlib.branch import Branch
 
26
from bzrlib.bzrdir import BzrDir
 
27
from bzrlib.conflicts import ConflictList, ContentsConflict
 
28
from bzrlib.osutils import abspath, file_kind, pathjoin
 
29
from bzrlib.tests.blackbox import ExternalBase
 
30
import bzrlib.urlutils as urlutils
 
31
from bzrlib.workingtree import WorkingTree
 
32
 
 
33
 
 
34
class TestMerge(ExternalBase):
38
35
 
39
36
    def example_branch(self, path='.'):
40
37
        tree = self.make_branch_and_tree(path)
41
38
        self.build_tree_contents([
42
 
            (osutils.pathjoin(path, 'hello'), 'foo'),
43
 
            (osutils.pathjoin(path, 'goodbye'), 'baz')])
 
39
            (pathjoin(path, 'hello'), 'foo'),
 
40
            (pathjoin(path, 'goodbye'), 'baz')])
44
41
        tree.add('hello')
45
42
        tree.commit(message='setup')
46
43
        tree.add('goodbye')
66
63
        return tree, other
67
64
 
68
65
    def test_merge_reprocess(self):
69
 
        d = bzrdir.BzrDir.create_standalone_workingtree('.')
 
66
        d = BzrDir.create_standalone_workingtree('.')
70
67
        d.commit('h')
71
68
        self.run_bzr('merge . --reprocess --merge-type weave')
72
69
 
73
70
    def test_merge(self):
 
71
        from bzrlib.branch import Branch
 
72
 
74
73
        a_tree = self.example_branch('a')
75
74
        ancestor = a_tree.branch.revno()
76
75
        b_tree = a_tree.bzrdir.sprout('b').open_workingtree()
81
80
        # We can't merge when there are in-tree changes
82
81
        os.chdir('a')
83
82
        self.run_bzr('merge ../b', retcode=3)
84
 
        a = workingtree.WorkingTree.open('.')
 
83
        a = WorkingTree.open('.')
85
84
        a_tip = a.commit("Like an epidemic of u's")
86
85
        self.run_bzr('merge ../b -r last:1..last:1 --merge-type blooof',
87
86
                    retcode=3)
100
99
        self.run_bzr('merge ../b -r last:1')
101
100
        self.check_file_contents('goodbye', 'quux')
102
101
        # Merging a branch pulls its revision into the tree
103
 
        b = branch.Branch.open('../b')
 
102
        b = Branch.open('../b')
104
103
        b_tip = b.last_revision()
105
104
        self.failUnless(a.branch.repository.has_revision(b_tip))
106
105
        self.assertEqual([a_tip, b_tip], a.get_parent_ids())
109
108
        self.assertTrue("Not a branch" in err)
110
109
        self.run_bzr('merge -r revno:%d:./..revno:%d:../b'
111
110
                    %(ancestor,b.revno()))
112
 
        self.assertEquals(a.get_parent_ids(),
 
111
        self.assertEquals(a.get_parent_ids(), 
113
112
                          [a.branch.last_revision(), b.last_revision()])
114
113
        self.check_file_contents('goodbye', 'quux')
115
114
        a_tree.revert(backups=False)
211
210
        self.failUnlessExists('sub/a.txt.OTHER')
212
211
        self.failUnlessExists('sub/a.txt.BASE')
213
212
 
214
 
    def test_conflict_leaves_base_this_other_files(self):
215
 
        tree, other = self.create_conflicting_branches()
216
 
        self.run_bzr('merge ../other', working_dir='tree',
217
 
                     retcode=1)
218
 
        self.assertFileEqual('a\nb\nc\n', 'tree/fname.BASE')
219
 
        self.assertFileEqual('a\nB\nD\n', 'tree/fname.OTHER')
220
 
        self.assertFileEqual('a\nB\nC\n', 'tree/fname.THIS')
221
 
 
222
 
    def test_weave_conflict_leaves_base_this_other_files(self):
223
 
        tree, other = self.create_conflicting_branches()
224
 
        self.run_bzr('merge ../other --weave', working_dir='tree',
225
 
                     retcode=1)
226
 
        self.assertFileEqual('a\nb\nc\n', 'tree/fname.BASE')
227
 
        self.assertFileEqual('a\nB\nD\n', 'tree/fname.OTHER')
228
 
        self.assertFileEqual('a\nB\nC\n', 'tree/fname.THIS')
229
 
 
230
213
    def test_merge_remember(self):
231
214
        """Merge changes from one branch to another, test submit location."""
232
215
        tree_a = self.make_branch_and_tree('branch_a')
253
236
        out = self.run_bzr('merge', retcode=3)
254
237
        self.assertEquals(out,
255
238
                ('','bzr: ERROR: No location specified or remembered\n'))
256
 
 
257
 
        # test uncommitted changes
 
239
        # test implicit --remember when no parent set, this merge conflicts
258
240
        self.build_tree(['d'])
259
241
        tree_b.add('d')
260
242
        self.run_bzr_error(['Working tree ".*" has uncommitted changes'],
261
 
                           'merge')
262
 
 
263
 
        # merge should now pass and implicitly remember merge location
 
243
                           'merge ../branch_a')
 
244
        self.assertEquals(abspath(branch_b.get_submit_branch()),
 
245
                          abspath(parent))
 
246
        # test implicit --remember after resolving conflict
264
247
        tree_b.commit('commit d')
265
 
        out, err = self.run_bzr('merge ../branch_a')
266
 
 
 
248
        out, err = self.run_bzr('merge')
 
249
        
267
250
        base = urlutils.local_path_from_url(branch_a.base)
268
 
        self.assertEndsWith(err, '+N  b\nAll changes applied successfully.\n')
269
 
        self.assertEquals(osutils.abspath(branch_b.get_submit_branch()),
270
 
                          osutils.abspath(parent))
271
 
        # test implicit --remember when committing new file
272
 
        self.build_tree(['e'])
273
 
        tree_b.add('e')
274
 
        tree_b.commit('commit e')
275
 
        out, err = self.run_bzr('merge')
276
251
        self.assertStartsWith(err,
277
252
                          'Merging from remembered submit location %s\n' % (base,))
 
253
        self.assertEndsWith(err, '+N  b\nAll changes applied successfully.\n')
 
254
        self.assertEquals(abspath(branch_b.get_submit_branch()),
 
255
                          abspath(parent))
278
256
        # re-open tree as external run_bzr modified it
279
257
        tree_b = branch_b.bzrdir.open_workingtree()
280
258
        tree_b.commit('merge branch_a')
282
260
        out, err = self.run_bzr('merge ../branch_c --remember')
283
261
        self.assertEquals(out, '')
284
262
        self.assertEquals(err, '+N  c\nAll changes applied successfully.\n')
285
 
        self.assertEquals(osutils.abspath(branch_b.get_submit_branch()),
286
 
                          osutils.abspath(branch_c.bzrdir.root_transport.base))
 
263
        self.assertEquals(abspath(branch_b.get_submit_branch()),
 
264
                          abspath(branch_c.bzrdir.root_transport.base))
287
265
        # re-open tree as external run_bzr modified it
288
266
        tree_b = branch_b.bzrdir.open_workingtree()
289
267
        tree_b.commit('merge branch_c')
311
289
                                              tree_b.get_parent_ids()[0])
312
290
        self.assertEqualDiff(testament_a.as_text(),
313
291
                         testament_b.as_text())
314
 
        tree_a.set_conflicts(conflicts.ConflictList())
 
292
        tree_a.set_conflicts(ConflictList())
315
293
        tree_a.commit('message')
316
294
        # it is legal to attempt to merge an already-merged bundle
317
295
        output = self.run_bzr('merge ../bundle')[1]
366
344
        os.chdir('a')
367
345
        (out, err) = self.run_bzr('merge --pull ../b')
368
346
        self.assertContainsRe(out, 'Now on revision 2\\.')
369
 
        tree_a = workingtree.WorkingTree.open('.')
 
347
        tree_a = WorkingTree.open('.')
370
348
        self.assertEqual([self.id2], tree_a.get_parent_ids())
371
349
 
372
350
    def test_merge_kind_change(self):
380
358
        tree_a.commit('changed file to directory')
381
359
        os.chdir('tree_b')
382
360
        self.run_bzr('merge ../tree_a')
383
 
        self.assertEqual('directory', osutils.file_kind('file'))
 
361
        self.assertEqual('directory', file_kind('file'))
384
362
        tree_b.revert()
385
 
        self.assertEqual('file', osutils.file_kind('file'))
 
363
        self.assertEqual('file', file_kind('file'))
386
364
        self.build_tree_contents([('file', 'content_2')])
387
365
        tree_b.commit('content change')
388
366
        self.run_bzr('merge ../tree_a', retcode=1)
389
367
        self.assertEqual(tree_b.conflicts(),
390
 
                         [conflicts.ContentsConflict('file',
391
 
                                                     file_id='file-id')])
 
368
                         [ContentsConflict('file', file_id='file-id')])
392
369
 
393
370
    def test_directive_cherrypick(self):
394
371
        source = self.make_branch_and_tree('source')
395
 
        source.commit("nothing")
396
 
        # see https://bugs.edge.launchpad.net/bzr/+bug/409688 - trying to
397
 
        # cherrypick from one branch into another unrelated branch with a
398
 
        # different root id will give shape conflicts.  as a workaround we
399
 
        # make sure they share the same root id.
400
 
        target = source.bzrdir.sprout('target').open_workingtree()
401
372
        self.build_tree(['source/a'])
402
373
        source.add('a')
403
374
        source.commit('Added a', rev_id='rev1')
404
375
        self.build_tree(['source/b'])
405
376
        source.add('b')
406
377
        source.commit('Added b', rev_id='rev2')
 
378
        target = self.make_branch_and_tree('target')
407
379
        target.commit('empty commit')
408
380
        self.write_directive('directive', source.branch, 'target', 'rev2',
409
381
                             'rev1')
466
438
 
467
439
    def assertDirectoryContent(self, directory, entries, message=''):
468
440
        """Assert whether entries (file or directories) exist in a directory.
469
 
 
 
441
        
470
442
        It also checks that there are no extra entries.
471
443
        """
472
444
        ondisk = os.listdir(directory)
566
538
        tree_a.merge_from_branch(tree_b.branch)
567
539
        self.build_tree_contents([('a/file',
568
540
                                   'base-contents\nthis-contents\n')])
569
 
        tree_a.set_conflicts(conflicts.ConflictList())
 
541
        tree_a.set_conflicts(ConflictList())
570
542
        tree_b.merge_from_branch(tree_a.branch)
571
543
        self.build_tree_contents([('b/file',
572
544
                                   'base-contents\nother-contents\n')])
573
 
        tree_b.set_conflicts(conflicts.ConflictList())
 
545
        tree_b.set_conflicts(ConflictList())
574
546
        tree_a.commit('', rev_id='rev3a')
575
547
        tree_b.commit('', rev_id='rev3b')
576
548
        out, err = self.run_bzr(['merge', '-d', 'a', 'b', '--lca'], retcode=1)
593
565
        self.addCleanup(this_tree.unlock)
594
566
        self.assertEqual([],
595
567
                         list(this_tree.iter_changes(this_tree.basis_tree())))
596
 
 
597
 
    def test_merge_missing_second_revision_spec(self):
598
 
        """Merge uses branch basis when the second revision is unspecified."""
599
 
        this = self.make_branch_and_tree('this')
600
 
        this.commit('rev1')
601
 
        other = self.make_branch_and_tree('other')
602
 
        self.build_tree(['other/other_file'])
603
 
        other.add('other_file')
604
 
        other.commit('rev1b')
605
 
        self.run_bzr('merge -d this other -r0..')
606
 
        self.failUnlessExists('this/other_file')
607
 
 
608
 
    def test_merge_interactive_unlocks_branch(self):
609
 
        this = self.make_branch_and_tree('this')
610
 
        other = self.make_branch_and_tree('other')
611
 
        other.commit('empty commit')
612
 
        self.run_bzr('merge -i -d this other')
613
 
        this.lock_write()
614
 
        this.unlock()
615
 
 
616
 
    def test_merge_reversed_revision_range(self):
617
 
        tree = self.make_branch_and_tree(".")
618
 
        for f in ("a", "b"):
619
 
            self.build_tree([f])
620
 
            tree.add(f)
621
 
            tree.commit("added "+f)
622
 
        for context in (".", "", "a"):
623
 
            self.run_bzr("merge -r 1..0 " + context)
624
 
            self.failIfExists("a")
625
 
            tree.revert()
626
 
            self.failUnlessExists("a")
627
 
 
628
 
 
629
 
class TestMergeForce(tests.TestCaseWithTransport):
630
 
 
631
 
    def setUp(self):
632
 
        super(TestMergeForce, self).setUp()
633
 
        self.tree_a = self.make_branch_and_tree('a')
634
 
        self.build_tree(['a/foo'])
635
 
        self.tree_a.add(['foo'])
636
 
        self.tree_a.commit('add file')
637
 
        self.tree_b = self.tree_a.bzrdir.sprout('b').open_workingtree()
638
 
        self.build_tree_contents([('a/foo', 'change 1')])
639
 
        self.tree_a.commit('change file')
640
 
        self.tree_b.merge_from_branch(self.tree_a.branch)
641
 
 
642
 
    def test_merge_force(self):
643
 
        self.tree_a.commit('empty change to allow merge to run')
644
 
        # Second merge on top of the uncommitted one
645
 
        self.run_bzr(['merge', '../a', '--force'], working_dir='b')
646
 
 
647
 
 
648
 
    def test_merge_with_uncommitted_changes(self):
649
 
        self.run_bzr_error(['Working tree .* has uncommitted changes'],
650
 
                           ['merge', '../a'], working_dir='b')
651
 
 
652
 
    def test_merge_with_pending_merges(self):
653
 
        # Revert the changes keeping the pending merge
654
 
        self.run_bzr(['revert', 'b'])
655
 
        self.run_bzr_error(['Working tree .* has uncommitted changes'],
656
 
                           ['merge', '../a'], working_dir='b')