22
import bzrlib.errors as errors
22
from bzrlib.errors import NoSuchFile
24
from errors import (EmptyMessageError, NoMessageNoFileError,
25
NoChangesToCommitError, ConflictsInTreeError,
26
StrictCommitError, BoundBranchOutOfDate,
27
LocalRequiresBoundBranch, NotBranchError, NonExistingParent,
24
from errors import ( LocalRequiresBoundBranch, NotBranchError, NonExistingParent,
28
25
PathPrefixNotCreated, NoLocationKnown,
29
26
DivergedBranchesError)
31
def commit(selected_list, message=None, file=None, unchanged=False,
28
def commit(selected_list, message=None, unchanged=False,
32
29
strict=False, local=False):
33
30
""" Command to commit changes into the branch.
47
44
from bzrlib.builtins import tree_files
48
45
from bzrlib.commit import NullCommitReporter
51
tree, selected_list = tree_files(selected_list)
52
except errors.NotBranchError:
47
tree, selected_list = tree_files(selected_list)
55
49
if local and not tree.branch.get_bound_location():
56
50
raise LocalRequiresBoundBranch
57
if message is None and not file:
59
raise NoMessageNoFileError
60
elif message and file:
61
raise NoMessageNoFileError
64
message = codecs.open(file, 'rt', bzrlib.user_encoding).read()
67
raise EmptyMessageError
52
assert message is not None and len(message) > 0
54
# FIXME: This should be a GtkCommitReporter!
69
55
reporter = NullCommitReporter()
72
tree.commit(message, specific_files=selected_list,
57
tree.commit(message, specific_files=selected_list,
73
58
allow_pointless=unchanged, strict=strict, local=local,
75
except errors.PointlessCommit:
76
raise NoChangesToCommitError
77
except errors.ConflictsInTree:
78
raise ConflictsInTreeError
79
except errors.StrictCommitFailed:
80
raise StrictCommitError
81
except errors.BoundBranchOutOfDate, e:
82
raise BoundBranchOutOfDate(str(e))
84
61
def push(branch, location=None, remember=False, overwrite=False,
85
62
create_prefix=False):
100
77
from bzrlib.branch import Branch
101
78
from bzrlib.transport import get_transport
104
br_from = Branch.open_containing(branch)[0]
105
except errors.NotBranchError:
106
raise NotBranchError(branch)
80
br_from = Branch.open_containing(branch)[0]
110
82
stored_loc = br_from.get_push_location()
111
83
if location is None:
126
98
dir_to = bzrlib.bzrdir.BzrDir.open(location_url)
127
99
br_to = dir_to.open_branch()
128
except errors.NotBranchError:
100
except NotBranchError:
129
101
# create a branch.
130
102
transport = transport.clone('..')
131
103
if not create_prefix:
133
105
relurl = transport.relpath(location_url)
134
106
transport.mkdir(relurl)
135
except errors.NoSuchFile:
136
108
raise NonExistingParent(location)
138
110
current = transport.base
142
114
transport, relpath = needed[-1]
143
115
transport.mkdir(relpath)
145
except errors.NoSuchFile:
146
118
new_transport = transport.clone('..')
147
119
needed.append((new_transport,
148
120
new_transport.relpath(transport.base)))
159
131
tree_to = dir_to.open_workingtree()
160
except errors.NotLocalUrl:
161
133
# FIXME - what to do here? how should we warn the user?
162
134
#warning('This transport does not update the working '
163
135
# 'tree of: %s' % (br_to.base,))
164
136
count = br_to.pull(br_from, overwrite)
165
except errors.NoWorkingTree:
137
except NoWorkingTree:
166
138
count = br_to.pull(br_from, overwrite)
168
140
count = tree_to.pull(br_from, overwrite)
169
except errors.DivergedBranches:
141
except DivergedBranches:
170
142
raise DivergedBranchesError