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