~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Vincent Ladeuil
  • Date: 2012-01-05 17:56:30 UTC
  • mfrom: (6434 +trunk)
  • mto: This revision was merged to the branch mainline in revision 6468.
  • Revision ID: v.ladeuil+lp@free.fr-20120105175630-kp0kt0el27s40q0x
Merge trunk resolving conflicts

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')
280
283
        self.assertEquals(osutils.abspath(branch_b.get_submit_branch()),
281
284
                          osutils.abspath(parent))
282
285
        # test implicit --remember when committing new file
283
 
        self.build_tree(['e'])
 
286
        self.build_tree(['branch_b/e'])
284
287
        tree_b.add('e')
285
288
        tree_b.commit('commit e')
286
 
        out, err = self.run_bzr('merge')
 
289
        out, err = self.run_bzr('merge', working_dir='branch_b')
287
290
        self.assertStartsWith(
288
291
            err, 'Merging from remembered submit location %s\n' % (base,))
289
292
        # re-open tree as external run_bzr modified it
290
293
        tree_b = branch_b.bzrdir.open_workingtree()
291
294
        tree_b.commit('merge branch_a')
292
295
        # test explicit --remember
293
 
        out, err = self.run_bzr('merge ../branch_c --remember')
 
296
        out, err = self.run_bzr('merge ../branch_c --remember',
 
297
                                working_dir='branch_b')
294
298
        self.assertEquals(out, '')
295
299
        self.assertEquals(err, '+N  c\nAll changes applied successfully.\n')
296
300
        # re-open branch as external run_bzr modified it
314
318
 
315
319
        self.build_tree_contents([('branch_b/a', 'goodbye')])
316
320
        tree_b.commit('message')
317
 
        os.chdir('branch_b')
318
 
        self.run_bzr('bundle ../branch_a -o ../bundle')
319
 
        os.chdir('../branch_a')
320
 
        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')
321
323
        testament_a = Testament.from_revision(tree_a.branch.repository,
322
324
                                              tree_b.get_parent_ids()[0])
323
325
        testament_b = Testament.from_revision(tree_b.branch.repository,
327
329
        tree_a.set_conflicts(conflicts.ConflictList())
328
330
        tree_a.commit('message')
329
331
        # it is legal to attempt to merge an already-merged bundle
330
 
        output = self.run_bzr('merge ../bundle')[1]
 
332
        err = self.run_bzr('merge ../bundle', working_dir='branch_a')[1]
331
333
        # but it does nothing
332
334
        self.assertFalse(tree_a.changes_from(tree_a.basis_tree()).has_changed())
333
 
        self.assertEqual('Nothing to do.\n', output)
 
335
        self.assertEqual('Nothing to do.\n', err)
334
336
 
335
337
    def test_merge_uncommitted(self):
336
338
        """Check that merge --uncommitted behaves properly"""
343
345
        tree_a.rename_one('file_1', 'file_i')
344
346
        tree_a.commit('commit 2')
345
347
        tree_a.rename_one('file_2', 'file_ii')
346
 
        ## os.chdir('b')
347
348
        self.run_bzr('merge a --uncommitted -d b')
348
349
        self.assertPathExists('b/file_1')
349
350
        self.assertPathExists('b/file_ii')
358
359
        tree_a.bzrdir.sprout('tree_b')
359
360
        self.build_tree(['tree_a/file1', 'tree_a/file2'])
360
361
        tree_a.add(['file1', 'file2'])
361
 
        os.chdir('tree_b')
362
 
        self.run_bzr(['merge', '--uncommitted', '../tree_a/file1'])
363
 
        self.assertPathExists('file1')
364
 
        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')
365
366
 
366
367
    def test_merge_nonexistent_file(self):
367
368
        """It should not be possible to merge changes from a file which
370
371
        self.build_tree_contents([('tree_a/file', 'bar\n')])
371
372
        tree_a.add(['file'])
372
373
        tree_a.commit('commit 1')
373
 
        os.chdir('tree_a')
374
374
        self.run_bzr_error(('Path\(s\) do not exist: non/existing',),
375
 
                           ['merge', 'non/existing'])
 
375
                           ['merge', 'non/existing'], working_dir='tree_a')
376
376
 
377
377
    def pullable_branch(self):
378
378
        tree_a = self.make_branch_and_tree('a')
387
387
 
388
388
    def test_merge_pull(self):
389
389
        self.pullable_branch()
390
 
        os.chdir('a')
391
 
        (out, err) = self.run_bzr('merge --pull ../b')
 
390
        (out, err) = self.run_bzr('merge --pull ../b', working_dir='a')
392
391
        self.assertContainsRe(out, 'Now on revision 2\\.')
393
 
        tree_a = workingtree.WorkingTree.open('.')
 
392
        tree_a = workingtree.WorkingTree.open('a')
394
393
        self.assertEqual([self.id2], tree_a.get_parent_ids())
395
394
 
396
395
    def test_merge_pull_preview(self):
417
416
        os.unlink('tree_a/file')
418
417
        self.build_tree(['tree_a/file/'])
419
418
        tree_a.commit('changed file to directory')
420
 
        os.chdir('tree_b')
421
 
        self.run_bzr('merge ../tree_a')
422
 
        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'))
423
421
        tree_b.revert()
424
 
        self.assertEqual('file', osutils.file_kind('file'))
425
 
        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')])
426
424
        tree_b.commit('content change')
427
 
        self.run_bzr('merge ../tree_a', retcode=1)
 
425
        self.run_bzr('merge ../tree_a', retcode=1, working_dir='tree_b')
428
426
        self.assertEqual(tree_b.conflicts(),
429
427
                         [conflicts.ContentsConflict('file',
430
428
                                                     file_id='file-id')])