1
# Copyright (C) 2006 by Szilveszter Farkas (Phanatic) <szilveszter.farkas@gmail.com>
2
# Some parts of the code are:
3
# Copyright (C) 2005, 2006 by Canonical Ltd
5
# This program is free software; you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 2 of the License, or
8
# (at your option) any later version.
10
# This program is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
15
# You should have received a copy of the GNU General Public License
16
# along with this program; if not, write to the Free Software
17
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
from bzrlib.errors import NoSuchFile
22
from errors import ( LocalRequiresBoundBranch, NotBranchError, NonExistingParent,
23
PathPrefixNotCreated, NoLocationKnown,
24
DivergedBranchesError)
26
def push(branch, location=None, remember=False, overwrite=False,
28
""" Update a mirror of a branch.
30
:param branch: the source branch
32
:param location: the location of the branch that you'd like to update
34
:param remember: if set, the location will be stored
36
:param overwrite: overwrite target location if it diverged
38
:param create_prefix: create the path leading up to the branch if it doesn't exist
40
:return: number of revisions pushed
42
from bzrlib.branch import Branch
43
from bzrlib.transport import get_transport
45
br_from = Branch.open_containing(branch)[0]
47
stored_loc = br_from.get_push_location()
49
if stored_loc is None:
54
transport = get_transport(location)
55
location_url = transport.base
57
if br_from.get_push_location() is None or remember:
58
br_from.set_push_location(location_url)
63
dir_to = bzrlib.bzrdir.BzrDir.open(location_url)
64
br_to = dir_to.open_branch()
65
except NotBranchError:
67
transport = transport.clone('..')
70
relurl = transport.relpath(location_url)
71
transport.mkdir(relurl)
73
raise NonExistingParent(location)
75
current = transport.base
76
needed = [(transport, transport.relpath(location_url))]
79
transport, relpath = needed[-1]
80
transport.mkdir(relpath)
83
new_transport = transport.clone('..')
84
needed.append((new_transport,
85
new_transport.relpath(transport.base)))
86
if new_transport.base == transport.base:
87
raise PathPrefixNotCreated
88
dir_to = br_from.bzrdir.clone(location_url,
89
revision_id=br_from.last_revision())
90
br_to = dir_to.open_branch()
91
count = len(br_to.revision_history())
93
old_rh = br_to.revision_history()
96
tree_to = dir_to.open_workingtree()
98
# FIXME - what to do here? how should we warn the user?
99
#warning('This transport does not update the working '
100
# 'tree of: %s' % (br_to.base,))
101
count = br_to.pull(br_from, overwrite)
102
except NoWorkingTree:
103
count = br_to.pull(br_from, overwrite)
105
count = tree_to.pull(br_from, overwrite)
106
except DivergedBranches:
107
raise DivergedBranchesError