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
22
from bzrlib.errors import NoSuchFile
24
from errors import ( LocalRequiresBoundBranch, NotBranchError, NonExistingParent,
25
PathPrefixNotCreated, NoLocationKnown,
26
DivergedBranchesError)
28
def commit(selected_list, message=None, unchanged=False,
29
strict=False, local=False):
30
""" Command to commit changes into the branch.
32
:param selected_list: list of files you want to commit (at least the top working directory has to be specified)
34
:param message: commit message
36
:param file: the file which contains the commit message
38
:param unchanged: force commit if nothing has changed since the last commit
40
:param strict: refuse to commit if there are unknown files in the working tree
42
:param local: perform a local only commit in a bound branch
44
from bzrlib.builtins import tree_files
45
from bzrlib.commit import NullCommitReporter
47
tree, selected_list = tree_files(selected_list)
49
if local and not tree.branch.get_bound_location():
50
raise LocalRequiresBoundBranch
52
assert message is not None and len(message) > 0
54
# FIXME: This should be a GtkCommitReporter!
55
reporter = NullCommitReporter()
57
tree.commit(message, specific_files=selected_list,
58
allow_pointless=unchanged, strict=strict, local=local,
61
def push(branch, location=None, remember=False, overwrite=False,
63
""" Update a mirror of a branch.
65
:param branch: the source branch
67
:param location: the location of the branch that you'd like to update
69
:param remember: if set, the location will be stored
71
:param overwrite: overwrite target location if it diverged
73
:param create_prefix: create the path leading up to the branch if it doesn't exist
75
:return: number of revisions pushed
77
from bzrlib.branch import Branch
78
from bzrlib.transport import get_transport
80
br_from = Branch.open_containing(branch)[0]
82
stored_loc = br_from.get_push_location()
84
if stored_loc is None:
89
transport = get_transport(location)
90
location_url = transport.base
92
if br_from.get_push_location() is None or remember:
93
br_from.set_push_location(location_url)
98
dir_to = bzrlib.bzrdir.BzrDir.open(location_url)
99
br_to = dir_to.open_branch()
100
except NotBranchError:
102
transport = transport.clone('..')
103
if not create_prefix:
105
relurl = transport.relpath(location_url)
106
transport.mkdir(relurl)
108
raise NonExistingParent(location)
110
current = transport.base
111
needed = [(transport, transport.relpath(location_url))]
114
transport, relpath = needed[-1]
115
transport.mkdir(relpath)
118
new_transport = transport.clone('..')
119
needed.append((new_transport,
120
new_transport.relpath(transport.base)))
121
if new_transport.base == transport.base:
122
raise PathPrefixNotCreated
123
dir_to = br_from.bzrdir.clone(location_url,
124
revision_id=br_from.last_revision())
125
br_to = dir_to.open_branch()
126
count = len(br_to.revision_history())
128
old_rh = br_to.revision_history()
131
tree_to = dir_to.open_workingtree()
133
# FIXME - what to do here? how should we warn the user?
134
#warning('This transport does not update the working '
135
# 'tree of: %s' % (br_to.base,))
136
count = br_to.pull(br_from, overwrite)
137
except NoWorkingTree:
138
count = br_to.pull(br_from, overwrite)
140
count = tree_to.pull(br_from, overwrite)
141
except DivergedBranches:
142
raise DivergedBranchesError