~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Jelmer Vernooij
  • Date: 2012-01-06 22:44:57 UTC
  • mfrom: (6436 +trunk)
  • mto: (6437.3.11 2.5)
  • mto: This revision was merged to the branch mainline in revision 6444.
  • Revision ID: jelmer@samba.org-20120106224457-re0pcy0fz31xob77
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2011 Canonical Ltd
 
1
# Copyright (C) 2006-2012 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
88
88
 
89
89
        self.build_tree_contents([('a/hello', 'quuux')])
90
90
        # We can't merge when there are in-tree changes
91
 
        os.chdir('a')
92
 
        self.run_bzr('merge ../b', retcode=3)
93
 
        a = workingtree.WorkingTree.open('.')
 
91
        self.run_bzr('merge ../b', retcode=3, working_dir='a')
 
92
        a = workingtree.WorkingTree.open('a')
94
93
        a_tip = a.commit("Like an epidemic of u's")
95
 
        self.run_bzr('merge ../b -r last:1..last:1 --merge-type blooof',
96
 
                    retcode=3)
97
 
        self.run_bzr('merge ../b -r last:1..last:1 --merge-type merge3')
98
 
        a_tree.revert(backups=False)
99
 
        self.run_bzr('merge ../b -r last:1..last:1 --merge-type weave')
100
 
        a_tree.revert(backups=False)
101
 
        self.run_bzr('merge ../b -r last:1..last:1 --merge-type lca')
102
 
        a_tree.revert(backups=False)
 
94
 
 
95
        def run_merge_then_revert(args, retcode=None, working_dir='a'):
 
96
            self.run_bzr(['merge', '../b', '-r', 'last:1..last:1'] + args,
 
97
                         retcode=retcode, working_dir=working_dir)
 
98
            if retcode != 3:
 
99
                a_tree.revert(backups=False)
 
100
 
 
101
        run_merge_then_revert(['--merge-type', 'bloof'], retcode=3)
 
102
        run_merge_then_revert(['--merge-type', 'merge3'])
 
103
        run_merge_then_revert(['--merge-type', 'weave'])
 
104
        run_merge_then_revert(['--merge-type', 'lca'])
103
105
        self.run_bzr_error(['Show-base is not supported for this merge type'],
104
106
                           'merge ../b -r last:1..last:1 --merge-type weave'
105
 
                           ' --show-base')
106
 
        a_tree.revert(backups=False)
107
 
        self.run_bzr('merge ../b -r last:1..last:1 --reprocess')
108
 
        a_tree.revert(backups=False)
109
 
        self.run_bzr('merge ../b -r last:1')
110
 
        self.check_file_contents('goodbye', 'quux')
 
107
                           ' --show-base', working_dir='a')
 
108
        a_tree.revert(backups=False)
 
109
        self.run_bzr('merge ../b -r last:1..last:1 --reprocess',
 
110
                     working_dir='a')
 
111
        a_tree.revert(backups=False)
 
112
        self.run_bzr('merge ../b -r last:1', working_dir='a')
 
113
        self.check_file_contents('a/goodbye', 'quux')
111
114
        # Merging a branch pulls its revision into the tree
112
 
        b = branch.Branch.open('../b')
 
115
        b = branch.Branch.open('b')
113
116
        b_tip = b.last_revision()
114
117
        self.assertTrue(a.branch.repository.has_revision(b_tip))
115
118
        self.assertEqual([a_tip, b_tip], a.get_parent_ids())
116
119
        a_tree.revert(backups=False)
117
 
        out, err = self.run_bzr('merge -r revno:1:./hello', retcode=3)
 
120
        out, err = self.run_bzr('merge -r revno:1:./hello', retcode=3,
 
121
                                working_dir='a')
118
122
        self.assertTrue("Not a branch" in err)
119
123
        self.run_bzr('merge -r revno:%d:./..revno:%d:../b'
120
 
                    %(ancestor,b.revno()))
 
124
                    %(ancestor,b.revno()), working_dir='a')
121
125
        self.assertEquals(a.get_parent_ids(),
122
126
                          [a.branch.last_revision(), b.last_revision()])
123
 
        self.check_file_contents('goodbye', 'quux')
 
127
        self.check_file_contents('a/goodbye', 'quux')
124
128
        a_tree.revert(backups=False)
125
 
        self.run_bzr('merge -r revno:%d:../b'%b.revno())
 
129
        self.run_bzr('merge -r revno:%d:../b'%b.revno(), working_dir='a')
126
130
        self.assertEquals(a.get_parent_ids(),
127
131
                          [a.branch.last_revision(), b.last_revision()])
128
132
        a_tip = a.commit('merged')
129
 
        self.run_bzr('merge ../b -r last:1')
 
133
        self.run_bzr('merge ../b -r last:1', working_dir='a')
130
134
        self.assertEqual([a_tip], a.get_parent_ids())
131
135
 
132
136
    def test_merge_defaults_to_reprocess(self):
211
215
            ('b/b.txt', 'hello\nsomething\n'),
212
216
            ('b/sub/c.txt', 'hello\nsomething\n')])
213
217
        b_tree.commit(message='Modified a.txt')
214
 
        os.chdir('b')
215
 
        self.run_bzr('merge ../a/', retcode=1)
216
 
        self.assertPathExists('sub/a.txt.THIS')
217
 
        self.assertPathExists('sub/a.txt.BASE')
218
 
        os.chdir('../a')
219
 
        self.run_bzr('merge ../b/', retcode=1)
220
 
        self.assertPathExists('sub/a.txt.OTHER')
221
 
        self.assertPathExists('sub/a.txt.BASE')
 
218
 
 
219
        self.run_bzr('merge ../a/', retcode=1, working_dir='b')
 
220
        self.assertPathExists('b/sub/a.txt.THIS')
 
221
        self.assertPathExists('b/sub/a.txt.BASE')
 
222
 
 
223
        self.run_bzr('merge ../b/', retcode=1, working_dir='a')
 
224
        self.assertPathExists('a/sub/a.txt.OTHER')
 
225
        self.assertPathExists('a/sub/a.txt.BASE')
222
226
 
223
227
    def test_conflict_leaves_base_this_other_files(self):
224
228
        tree, other = self.create_conflicting_branches()
258
262
        branch_b.set_parent(None)
259
263
        self.assertEqual(None, branch_b.get_parent())
260
264
        # test merge for failure without parent set
261
 
        os.chdir('branch_b')
262
 
        out = self.run_bzr('merge', retcode=3)
 
265
        out = self.run_bzr('merge', retcode=3, working_dir='branch_b')
263
266
        self.assertEquals(out,
264
267
                ('','bzr: ERROR: No location specified or remembered\n'))
265
268
 
266
269
        # test uncommitted changes
267
 
        self.build_tree(['d'])
 
270
        self.build_tree(['branch_b/d'])
268
271
        tree_b.add('d')
269
272
        self.run_bzr_error(['Working tree ".*" has uncommitted changes'],
270
 
                           'merge')
 
273
                           'merge', working_dir='branch_b')
271
274
 
272
275
        # merge should now pass and implicitly remember merge location
273
276
        tree_b.commit('commit d')
274
 
        out, err = self.run_bzr('merge ../branch_a')
 
277
        out, err = self.run_bzr('merge ../branch_a', working_dir='branch_b')
275
278
 
276
279
        base = urlutils.local_path_from_url(branch_a.base)
277
280
        self.assertEndsWith(err, '+N  b\nAll changes applied successfully.\n')
278
281
        self.assertEquals(osutils.abspath(branch_b.get_submit_branch()),
279
282
                          osutils.abspath(parent))
280
283
        # test implicit --remember when committing new file
281
 
        self.build_tree(['e'])
 
284
        self.build_tree(['branch_b/e'])
282
285
        tree_b.add('e')
283
286
        tree_b.commit('commit e')
284
 
        out, err = self.run_bzr('merge')
285
 
        self.assertStartsWith(err,
286
 
                          'Merging from remembered submit location %s\n' % (base,))
 
287
        out, err = self.run_bzr('merge', working_dir='branch_b')
 
288
        self.assertStartsWith(
 
289
            err, 'Merging from remembered submit location %s\n' % (base,))
287
290
        # re-open tree as external run_bzr modified it
288
291
        tree_b = branch_b.bzrdir.open_workingtree()
289
292
        tree_b.commit('merge branch_a')
290
293
        # test explicit --remember
291
 
        out, err = self.run_bzr('merge ../branch_c --remember')
 
294
        out, err = self.run_bzr('merge ../branch_c --remember',
 
295
                                working_dir='branch_b')
292
296
        self.assertEquals(out, '')
293
297
        self.assertEquals(err, '+N  c\nAll changes applied successfully.\n')
294
298
        self.assertEquals(osutils.abspath(branch_b.get_submit_branch()),
310
314
 
311
315
        self.build_tree_contents([('branch_b/a', 'goodbye')])
312
316
        tree_b.commit('message')
313
 
        os.chdir('branch_b')
314
 
        self.run_bzr('bundle ../branch_a -o ../bundle')
315
 
        os.chdir('../branch_a')
316
 
        self.run_bzr('merge ../bundle', retcode=1)
 
317
        self.run_bzr('bundle ../branch_a -o ../bundle', working_dir='branch_b')
 
318
        self.run_bzr('merge ../bundle', retcode=1, working_dir='branch_a')
317
319
        testament_a = Testament.from_revision(tree_a.branch.repository,
318
320
                                              tree_b.get_parent_ids()[0])
319
321
        testament_b = Testament.from_revision(tree_b.branch.repository,
323
325
        tree_a.set_conflicts(conflicts.ConflictList())
324
326
        tree_a.commit('message')
325
327
        # it is legal to attempt to merge an already-merged bundle
326
 
        output = self.run_bzr('merge ../bundle')[1]
 
328
        err = self.run_bzr('merge ../bundle', working_dir='branch_a')[1]
327
329
        # but it does nothing
328
330
        self.assertFalse(tree_a.changes_from(tree_a.basis_tree()).has_changed())
329
 
        self.assertEqual('Nothing to do.\n', output)
 
331
        self.assertEqual('Nothing to do.\n', err)
330
332
 
331
333
    def test_merge_uncommitted(self):
332
334
        """Check that merge --uncommitted behaves properly"""
339
341
        tree_a.rename_one('file_1', 'file_i')
340
342
        tree_a.commit('commit 2')
341
343
        tree_a.rename_one('file_2', 'file_ii')
342
 
        ## os.chdir('b')
343
344
        self.run_bzr('merge a --uncommitted -d b')
344
345
        self.assertPathExists('b/file_1')
345
346
        self.assertPathExists('b/file_ii')
354
355
        tree_a.bzrdir.sprout('tree_b')
355
356
        self.build_tree(['tree_a/file1', 'tree_a/file2'])
356
357
        tree_a.add(['file1', 'file2'])
357
 
        os.chdir('tree_b')
358
 
        self.run_bzr(['merge', '--uncommitted', '../tree_a/file1'])
359
 
        self.assertPathExists('file1')
360
 
        self.assertPathDoesNotExist('file2')
 
358
        self.run_bzr(['merge', '--uncommitted', '../tree_a/file1'],
 
359
                     working_dir='tree_b')
 
360
        self.assertPathExists('tree_b/file1')
 
361
        self.assertPathDoesNotExist('tree_b/file2')
361
362
 
362
363
    def test_merge_nonexistent_file(self):
363
364
        """It should not be possible to merge changes from a file which
366
367
        self.build_tree_contents([('tree_a/file', 'bar\n')])
367
368
        tree_a.add(['file'])
368
369
        tree_a.commit('commit 1')
369
 
        os.chdir('tree_a')
370
370
        self.run_bzr_error(('Path\(s\) do not exist: non/existing',),
371
 
                           ['merge', 'non/existing'])
 
371
                           ['merge', 'non/existing'], working_dir='tree_a')
372
372
 
373
373
    def pullable_branch(self):
374
374
        tree_a = self.make_branch_and_tree('a')
383
383
 
384
384
    def test_merge_pull(self):
385
385
        self.pullable_branch()
386
 
        os.chdir('a')
387
 
        (out, err) = self.run_bzr('merge --pull ../b')
 
386
        (out, err) = self.run_bzr('merge --pull ../b', working_dir='a')
388
387
        self.assertContainsRe(out, 'Now on revision 2\\.')
389
 
        tree_a = workingtree.WorkingTree.open('.')
 
388
        tree_a = workingtree.WorkingTree.open('a')
390
389
        self.assertEqual([self.id2], tree_a.get_parent_ids())
391
390
 
392
391
    def test_merge_pull_preview(self):
413
412
        os.unlink('tree_a/file')
414
413
        self.build_tree(['tree_a/file/'])
415
414
        tree_a.commit('changed file to directory')
416
 
        os.chdir('tree_b')
417
 
        self.run_bzr('merge ../tree_a')
418
 
        self.assertEqual('directory', osutils.file_kind('file'))
 
415
        self.run_bzr('merge ../tree_a', working_dir='tree_b')
 
416
        self.assertEqual('directory', osutils.file_kind('tree_b/file'))
419
417
        tree_b.revert()
420
 
        self.assertEqual('file', osutils.file_kind('file'))
421
 
        self.build_tree_contents([('file', 'content_2')])
 
418
        self.assertEqual('file', osutils.file_kind('tree_b/file'))
 
419
        self.build_tree_contents([('tree_b/file', 'content_2')])
422
420
        tree_b.commit('content change')
423
 
        self.run_bzr('merge ../tree_a', retcode=1)
 
421
        self.run_bzr('merge ../tree_a', retcode=1, working_dir='tree_b')
424
422
        self.assertEqual(tree_b.conflicts(),
425
423
                         [conflicts.ContentsConflict('file',
426
424
                                                     file_id='file-id')])
681
679
        builder.build_commit(message="Rev 2a", rev_id='rev-2a')
682
680
        source.tags.set_tag('tag-a', 'rev-2a')
683
681
        source.set_last_revision_info(1, 'rev-1')
684
 
        source.get_config().set_user_option('branch.fetch_tags', 'True')
 
682
        source.get_config_stack().set('branch.fetch_tags', True)
685
683
        builder.build_commit(message="Rev 2b", rev_id='rev-2b')
686
684
        # Merge from source
687
685
        self.run_bzr('merge -d target source')