1
# Copyright (C) 2005 by Canonical Ltd
2
# -*- coding: utf-8 -*-
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details.
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
"""Black-box tests for bzr merge.
24
from bzrlib.branch import Branch
25
from bzrlib.tests.blackbox import ExternalBase
26
from bzrlib.osutils import abspath
29
class TestMerge(ExternalBase):
31
def test_merge_remember(self):
32
"""Merge changes from one branch to another and test parent location."""
33
tree_a = self.make_branch_and_tree('branch_a')
34
branch_a = tree_a.branch
35
self.build_tree(['branch_a/a'])
37
tree_a.commit('commit a')
38
branch_b = branch_a.bzrdir.sprout('branch_b').open_branch()
39
tree_b = branch_b.bzrdir.open_workingtree()
40
branch_c = branch_a.bzrdir.sprout('branch_c').open_branch()
41
tree_c = branch_c.bzrdir.open_workingtree()
42
self.build_tree(['branch_a/b'])
44
tree_a.commit('commit b')
45
self.build_tree(['branch_c/c'])
47
tree_c.commit('commit c')
49
parent = branch_b.get_parent()
50
branch_b.set_parent(None)
51
self.assertEqual(None, branch_b.get_parent())
52
# test merge for failure without parent set
54
out = self.runbzr('merge', retcode=3)
55
self.assertEquals(out,
56
('','bzr: ERROR: No merge branch known or specified.\n'))
57
# test implicit --remember when no parent set, this merge conflicts
58
self.build_tree(['d'])
60
out = self.runbzr('merge ../branch_a', retcode=3)
61
self.assertEquals(out,
62
('','bzr: ERROR: Working tree has uncommitted changes.\n'))
63
self.assertEquals(abspath(branch_b.get_parent()), abspath(parent))
64
# test implicit --remember after resolving conflict
65
tree_b.commit('commit d')
66
out, err = self.runbzr('merge')
67
self.assertEquals(out, 'Using saved branch: ../branch_a\n')
68
self.assertEquals(err, 'All changes applied successfully.\n')
69
self.assertEquals(abspath(branch_b.get_parent()), abspath(parent))
70
# re-open tree as external runbzr modified it
71
tree_b = branch_b.bzrdir.open_workingtree()
72
tree_b.commit('merge branch_a')
73
# test explicit --remember
74
out, err = self.runbzr('merge ../branch_c --remember')
75
self.assertEquals(out, '')
76
self.assertEquals(err, 'All changes applied successfully.\n')
77
self.assertEquals(abspath(branch_b.get_parent()),
78
abspath(branch_c.bzrdir.root_transport.base))
79
# re-open tree as external runbzr modified it
80
tree_b = branch_b.bzrdir.open_workingtree()
81
tree_b.commit('merge branch_c')