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 push."""
24
from bzrlib.branch import Branch
25
from bzrlib.osutils import abspath
26
from bzrlib.tests.blackbox import ExternalBase
27
from bzrlib.uncommit import uncommit
30
class TestPush(ExternalBase):
32
def test_push_remember(self):
33
"""Push changes from one branch to another and test push location."""
34
transport = self.get_transport()
35
tree_a = self.make_branch_and_tree('branch_a')
36
branch_a = tree_a.branch
37
self.build_tree(['branch_a/a'])
39
tree_a.commit('commit a')
40
tree_b = branch_a.bzrdir.sprout('branch_b').open_workingtree()
41
branch_b = tree_b.branch
42
tree_c = branch_a.bzrdir.sprout('branch_c').open_workingtree()
43
branch_c = tree_c.branch
44
self.build_tree(['branch_a/b'])
46
tree_a.commit('commit b')
47
self.build_tree(['branch_b/c'])
49
tree_b.commit('commit c')
50
# initial push location must be empty
51
self.assertEqual(None, branch_b.get_push_location())
52
# test push for failure without push location set
54
out = self.runbzr('push', retcode=3)
55
self.assertEquals(out,
56
('','bzr: ERROR: No push location known or specified.\n'))
57
# test implicit --remember when no push location set, push fails
58
out = self.runbzr('push ../branch_b', retcode=3)
59
self.assertEquals(out,
60
('','bzr: ERROR: These branches have diverged. '
61
'Try a merge then push with overwrite.\n'))
62
self.assertEquals(abspath(branch_a.get_push_location()),
63
abspath(branch_b.bzrdir.root_transport.base))
64
# test implicit --remember after resolving previous failure
65
uncommit(branch=branch_b, tree=tree_b)
66
transport.delete('branch_b/c')
68
self.assertEquals(abspath(branch_a.get_push_location()),
69
abspath(branch_b.bzrdir.root_transport.base))
70
# test explicit --remember
71
self.runbzr('push ../branch_c --remember')
72
self.assertEquals(abspath(branch_a.get_push_location()),
73
abspath(branch_c.bzrdir.root_transport.base))
75
def test_push_without_tree(self):
76
# bzr push from a branch that does not have a checkout should work.
77
b = self.make_branch('.')
78
out, err = self.run_bzr('push', 'pushed-location')
79
self.assertEqual('', out)
80
self.assertEqual('0 revision(s) pushed.\n', err)
81
b2 = bzrlib.branch.Branch.open('pushed-location')
82
self.assertEndsWith(b2.base, 'pushed-location/')