~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

Merge from bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
67
67
        self.run_bzr('merge ../b -r last:1..last:1 --merge-type blooof',
68
68
                    retcode=3)
69
69
        self.run_bzr('merge ../b -r last:1..last:1 --merge-type merge3')
70
 
        a_tree.revert([], backups=False)
 
70
        a_tree.revert(backups=False)
71
71
        self.run_bzr('merge ../b -r last:1..last:1 --merge-type weave')
72
 
        a_tree.revert([], backups=False)
 
72
        a_tree.revert(backups=False)
73
73
        self.run_bzr_error(['Show-base is not supported for this merge type'],
74
74
                           'merge ../b -r last:1..last:1 --merge-type weave'
75
75
                           ' --show-base')
76
 
        a_tree.revert([], backups=False)
 
76
        a_tree.revert(backups=False)
77
77
        self.run_bzr('merge ../b -r last:1..last:1 --reprocess')
78
 
        a_tree.revert([], backups=False)
 
78
        a_tree.revert(backups=False)
79
79
        self.run_bzr('merge ../b -r last:1')
80
80
        self.check_file_contents('goodbye', 'quux')
81
81
        # Merging a branch pulls its revision into the tree
83
83
        b_tip = b.last_revision()
84
84
        self.failUnless(a.branch.repository.has_revision(b_tip))
85
85
        self.assertEqual([a_tip, b_tip], a.get_parent_ids())
86
 
        a_tree.revert([], backups=False)
 
86
        a_tree.revert(backups=False)
87
87
        out, err = self.run_bzr('merge -r revno:1:./hello', retcode=3)
88
88
        self.assertTrue("Not a branch" in err)
89
89
        self.run_bzr('merge -r revno:%d:./..revno:%d:../b'
91
91
        self.assertEquals(a.get_parent_ids(), 
92
92
                          [a.branch.last_revision(), b.last_revision()])
93
93
        self.check_file_contents('goodbye', 'quux')
94
 
        a_tree.revert([], backups=False)
 
94
        a_tree.revert(backups=False)
95
95
        self.run_bzr('merge -r revno:%d:../b'%b.revno())
96
96
        self.assertEquals(a.get_parent_ids(),
97
97
                          [a.branch.last_revision(), b.last_revision()])
164
164
        # test implicit --remember when no parent set, this merge conflicts
165
165
        self.build_tree(['d'])
166
166
        tree_b.add('d')
167
 
        out = self.run_bzr('merge ../branch_a', retcode=3)
168
 
        self.assertEquals(out,
169
 
                ('','bzr: ERROR: Working tree has uncommitted changes.\n'))
 
167
        self.run_bzr_error(['Working tree ".*" has uncommitted changes'],
 
168
                           'merge ../branch_a')
170
169
        self.assertEquals(abspath(branch_b.get_parent()), abspath(parent))
171
170
        # test implicit --remember after resolving conflict
172
171
        tree_b.commit('commit d')
235
234
        self.run_bzr('merge a --uncommitted -d b')
236
235
        self.failUnlessExists('b/file_1')
237
236
        self.failUnlessExists('b/file_ii')
238
 
        tree_b.revert([])
 
237
        tree_b.revert()
239
238
        self.run_bzr_error(('Cannot use --uncommitted and --revision',),
240
239
                           'merge /a --uncommitted -r1 -d b')
241
240
 
270
269
        os.chdir('tree_b')
271
270
        self.run_bzr('merge ../tree_a')
272
271
        self.assertEqual('directory', file_kind('file'))
273
 
        tree_b.revert([])
 
272
        tree_b.revert()
274
273
        self.assertEqual('file', file_kind('file'))
275
274
        self.build_tree_contents([('file', 'content_2')])
276
275
        tree_b.commit('content change')
313
312
        self.write_directive('directive', source.branch, 'target', 'rev1')
314
313
        err = self.run_bzr('merge -d target directive')[1]
315
314
        self.assertNotContainsRe(err, 'Preview patch does not match changes')
316
 
        target.revert([])
 
315
        target.revert()
317
316
        self.write_directive('directive', source.branch, 'target', 'rev1',
318
317
                             mangle_patch=True)
319
318
        err = self.run_bzr('merge -d target directive')[1]
339
338
        self.run_bzr('merge -d target -r revid:rev2a branch_a')
340
339
        self.failUnlessExists('target/file1')
341
340
        self.failIfExists('target/file2')
342
 
        target.revert([])
 
341
        target.revert()
343
342
 
344
343
        # It should work if the revid has no integer revno
345
344
        self.run_bzr('merge -d target -r revid:rev2a branch_b')
346
345
        self.failUnlessExists('target/file1')
347
346
        self.failIfExists('target/file2')
 
347
 
 
348
    def assertDirectoryContent(self, directory, entries, message=''):
 
349
        """Assert whether entries (file or directories) exist in a directory.
 
350
        
 
351
        It also checks that there are no extra entries.
 
352
        """
 
353
        ondisk = os.listdir(directory)
 
354
        if set(ondisk) == set(entries):
 
355
            return
 
356
        if message:
 
357
            message += '\n'
 
358
        raise AssertionError(
 
359
            '%s"%s" directory content is different:\na = %s\nb = %s\n'
 
360
            % (message, directory, sorted(entries), sorted(ondisk)))
 
361
 
 
362
    def test_cherrypicking_merge(self):
 
363
        # make source branch
 
364
        source = self.make_branch_and_tree('source')
 
365
        for f in ('a', 'b', 'c', 'd'):
 
366
            self.build_tree(['source/'+f])
 
367
            source.add(f)
 
368
            source.commit('added '+f, rev_id='rev_'+f)
 
369
        # target branch
 
370
        target = source.bzrdir.sprout('target', 'rev_a').open_workingtree()
 
371
        self.assertDirectoryContent('target', ['.bzr', 'a'])
 
372
        # pick 1 revision
 
373
        self.run_bzr('merge -d target -r revid:rev_b..revid:rev_c source')
 
374
        self.assertDirectoryContent('target', ['.bzr', 'a', 'c'])
 
375
        target.revert()
 
376
        # pick 2 revisions
 
377
        self.run_bzr('merge -d target -r revid:rev_b..revid:rev_d source')
 
378
        self.assertDirectoryContent('target', ['.bzr', 'a', 'c', 'd'])
 
379
        target.revert()
 
380
        # pick 1 revision with option --changes
 
381
        self.run_bzr('merge -d target -c revid:rev_d source')
 
382
        self.assertDirectoryContent('target', ['.bzr', 'a', 'd'])