~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: 2016-04-03 16:32:31 UTC
  • mto: This revision was merged to the branch mainline in revision 6617.
  • Revision ID: jelmer@jelmer.uk-20160403163231-h72bo0uyek2gikw0
Don't put French text in doc/en/user-reference when LANGUAGE=fr_CH.UTF_8.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2011 Canonical Ltd
 
1
# Copyright (C) 2006-2012, 2016 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
26
26
 
27
27
from bzrlib import (
28
28
    branch,
29
 
    bzrdir,
30
29
    conflicts,
 
30
    controldir,
31
31
    merge_directive,
32
32
    osutils,
33
33
    tests,
75
75
        return tree, other
76
76
 
77
77
    def test_merge_reprocess(self):
78
 
        d = bzrdir.BzrDir.create_standalone_workingtree('.')
 
78
        d = controldir.ControlDir.create_standalone_workingtree('.')
79
79
        d.commit('h')
80
80
        self.run_bzr('merge . --reprocess --merge-type weave')
81
81
 
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()))
121
 
        self.assertEquals(a.get_parent_ids(),
 
124
                    %(ancestor,b.revno()), working_dir='a')
 
125
        self.assertEqual(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())
126
 
        self.assertEquals(a.get_parent_ids(),
 
129
        self.run_bzr('merge -r revno:%d:../b'%b.revno(), working_dir='a')
 
130
        self.assertEqual(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)
263
 
        self.assertEquals(out,
 
265
        out = self.run_bzr('merge', retcode=3, working_dir='branch_b')
 
266
        self.assertEqual(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
 
        self.assertEquals(osutils.abspath(branch_b.get_submit_branch()),
 
281
        # re-open branch as external run_bzr modified it
 
282
        branch_b = branch_b.bzrdir.open_branch()
 
283
        self.assertEqual(osutils.abspath(branch_b.get_submit_branch()),
279
284
                          osutils.abspath(parent))
280
285
        # test implicit --remember when committing new file
281
 
        self.build_tree(['e'])
 
286
        self.build_tree(['branch_b/e'])
282
287
        tree_b.add('e')
283
288
        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,))
 
289
        out, err = self.run_bzr('merge', working_dir='branch_b')
 
290
        self.assertStartsWith(
 
291
            err, 'Merging from remembered submit location %s\n' % (base,))
287
292
        # re-open tree as external run_bzr modified it
288
293
        tree_b = branch_b.bzrdir.open_workingtree()
289
294
        tree_b.commit('merge branch_a')
290
295
        # test explicit --remember
291
 
        out, err = self.run_bzr('merge ../branch_c --remember')
292
 
        self.assertEquals(out, '')
293
 
        self.assertEquals(err, '+N  c\nAll changes applied successfully.\n')
294
 
        self.assertEquals(osutils.abspath(branch_b.get_submit_branch()),
 
296
        out, err = self.run_bzr('merge ../branch_c --remember',
 
297
                                working_dir='branch_b')
 
298
        self.assertEqual(out, '')
 
299
        self.assertEqual(err, '+N  c\nAll changes applied successfully.\n')
 
300
        # re-open branch as external run_bzr modified it
 
301
        branch_b = branch_b.bzrdir.open_branch()
 
302
        self.assertEqual(osutils.abspath(branch_b.get_submit_branch()),
295
303
                          osutils.abspath(branch_c.bzrdir.root_transport.base))
296
304
        # re-open tree as external run_bzr modified it
297
305
        tree_b = branch_b.bzrdir.open_workingtree()
310
318
 
311
319
        self.build_tree_contents([('branch_b/a', 'goodbye')])
312
320
        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)
 
321
        self.run_bzr('bundle ../branch_a -o ../bundle', working_dir='branch_b')
 
322
        self.run_bzr('merge ../bundle', retcode=1, working_dir='branch_a')
317
323
        testament_a = Testament.from_revision(tree_a.branch.repository,
318
324
                                              tree_b.get_parent_ids()[0])
319
325
        testament_b = Testament.from_revision(tree_b.branch.repository,
323
329
        tree_a.set_conflicts(conflicts.ConflictList())
324
330
        tree_a.commit('message')
325
331
        # it is legal to attempt to merge an already-merged bundle
326
 
        output = self.run_bzr('merge ../bundle')[1]
 
332
        err = self.run_bzr('merge ../bundle', working_dir='branch_a')[1]
327
333
        # but it does nothing
328
334
        self.assertFalse(tree_a.changes_from(tree_a.basis_tree()).has_changed())
329
 
        self.assertEqual('Nothing to do.\n', output)
 
335
        self.assertEqual('Nothing to do.\n', err)
330
336
 
331
337
    def test_merge_uncommitted(self):
332
338
        """Check that merge --uncommitted behaves properly"""
339
345
        tree_a.rename_one('file_1', 'file_i')
340
346
        tree_a.commit('commit 2')
341
347
        tree_a.rename_one('file_2', 'file_ii')
342
 
        ## os.chdir('b')
343
348
        self.run_bzr('merge a --uncommitted -d b')
344
349
        self.assertPathExists('b/file_1')
345
350
        self.assertPathExists('b/file_ii')
354
359
        tree_a.bzrdir.sprout('tree_b')
355
360
        self.build_tree(['tree_a/file1', 'tree_a/file2'])
356
361
        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')
 
362
        self.run_bzr(['merge', '--uncommitted', '../tree_a/file1'],
 
363
                     working_dir='tree_b')
 
364
        self.assertPathExists('tree_b/file1')
 
365
        self.assertPathDoesNotExist('tree_b/file2')
361
366
 
362
367
    def test_merge_nonexistent_file(self):
363
368
        """It should not be possible to merge changes from a file which
366
371
        self.build_tree_contents([('tree_a/file', 'bar\n')])
367
372
        tree_a.add(['file'])
368
373
        tree_a.commit('commit 1')
369
 
        os.chdir('tree_a')
370
374
        self.run_bzr_error(('Path\(s\) do not exist: non/existing',),
371
 
                           ['merge', 'non/existing'])
 
375
                           ['merge', 'non/existing'], working_dir='tree_a')
372
376
 
373
377
    def pullable_branch(self):
374
378
        tree_a = self.make_branch_and_tree('a')
383
387
 
384
388
    def test_merge_pull(self):
385
389
        self.pullable_branch()
386
 
        os.chdir('a')
387
 
        (out, err) = self.run_bzr('merge --pull ../b')
 
390
        (out, err) = self.run_bzr('merge --pull ../b', working_dir='a')
388
391
        self.assertContainsRe(out, 'Now on revision 2\\.')
389
 
        tree_a = workingtree.WorkingTree.open('.')
 
392
        tree_a = workingtree.WorkingTree.open('a')
390
393
        self.assertEqual([self.id2], tree_a.get_parent_ids())
391
394
 
392
395
    def test_merge_pull_preview(self):
413
416
        os.unlink('tree_a/file')
414
417
        self.build_tree(['tree_a/file/'])
415
418
        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'))
 
419
        self.run_bzr('merge ../tree_a', working_dir='tree_b')
 
420
        self.assertEqual('directory', osutils.file_kind('tree_b/file'))
419
421
        tree_b.revert()
420
 
        self.assertEqual('file', osutils.file_kind('file'))
421
 
        self.build_tree_contents([('file', 'content_2')])
 
422
        self.assertEqual('file', osutils.file_kind('tree_b/file'))
 
423
        self.build_tree_contents([('tree_b/file', 'content_2')])
422
424
        tree_b.commit('content change')
423
 
        self.run_bzr('merge ../tree_a', retcode=1)
 
425
        self.run_bzr('merge ../tree_a', retcode=1, working_dir='tree_b')
424
426
        self.assertEqual(tree_b.conflicts(),
425
427
                         [conflicts.ContentsConflict('file',
426
428
                                                     file_id='file-id')])
555
557
        tree_b = tree_a.bzrdir.sprout('b').open_workingtree()
556
558
        tree_c = tree_a.bzrdir.sprout('c').open_workingtree()
557
559
        out, err = self.run_bzr(['merge', '-d', 'c'])
558
 
        self.assertContainsRe(err, 'Merging from remembered parent location .*a\/')
559
 
        tree_c.branch.set_submit_branch(tree_b.bzrdir.root_transport.base)
 
560
        self.assertContainsRe(err,
 
561
                              'Merging from remembered parent location .*a\/')
 
562
        tree_c.branch.lock_write()
 
563
        try:
 
564
            tree_c.branch.set_submit_branch(tree_b.bzrdir.root_transport.base)
 
565
        finally:
 
566
            tree_c.branch.unlock()
560
567
        out, err = self.run_bzr(['merge', '-d', 'c'])
561
 
        self.assertContainsRe(err, 'Merging from remembered submit location .*b\/')
 
568
        self.assertContainsRe(err,
 
569
                              'Merging from remembered submit location .*b\/')
562
570
 
563
571
    def test_remember_sets_submit(self):
564
572
        tree_a = self.make_branch_and_tree('a')
568
576
 
569
577
        # Remember should not happen if using default from parent
570
578
        out, err = self.run_bzr(['merge', '-d', 'b'])
571
 
        self.assertIs(tree_b.branch.get_submit_branch(), None)
 
579
        refreshed = workingtree.WorkingTree.open('b')
 
580
        self.assertIs(refreshed.branch.get_submit_branch(), None)
572
581
 
573
582
        # Remember should happen if user supplies location
574
583
        out, err = self.run_bzr(['merge', '-d', 'b', 'a'])
575
 
        self.assertEqual(tree_b.branch.get_submit_branch(),
 
584
        refreshed = workingtree.WorkingTree.open('b')
 
585
        self.assertEqual(refreshed.branch.get_submit_branch(),
576
586
                         tree_a.bzrdir.root_transport.base)
577
587
 
578
588
    def test_no_remember_dont_set_submit(self):
585
595
 
586
596
        # Remember should not happen if using default from parent
587
597
        out, err = self.run_bzr(['merge', '-d', 'b', '--no-remember'])
588
 
        self.assertEquals(None, tree_b.branch.get_submit_branch())
 
598
        self.assertEqual(None, tree_b.branch.get_submit_branch())
589
599
 
590
600
        # Remember should not happen if user supplies location but ask for not
591
601
        # remembering it
681
691
        builder.build_commit(message="Rev 2a", rev_id='rev-2a')
682
692
        source.tags.set_tag('tag-a', 'rev-2a')
683
693
        source.set_last_revision_info(1, 'rev-1')
684
 
        source.get_config().set_user_option('branch.fetch_tags', 'True')
 
694
        source.get_config_stack().set('branch.fetch_tags', True)
685
695
        builder.build_commit(message="Rev 2b", rev_id='rev-2b')
686
696
        # Merge from source
687
697
        self.run_bzr('merge -d target source')