60
60
from bzrlib.workingtree import WorkingTree
63
from bzrlib.commands import Command, display_command
63
from bzrlib.commands import (
65
builtin_command_registry,
64
68
from bzrlib.option import (
985
989
tree_to = WorkingTree.open_containing(directory)[0]
986
990
branch_to = tree_to.branch
992
self.add_cleanup(tree_to.unlock)
987
993
except errors.NoWorkingTree:
989
995
branch_to = Branch.open_containing(directory)[0]
996
branch_to.lock_write()
997
self.add_cleanup(branch_to.unlock)
991
999
if local and not branch_to.get_bound_location():
992
1000
raise errors.LocalRequiresBoundBranch()
1024
1032
branch_from = Branch.open(location,
1025
1033
possible_transports=possible_transports)
1034
branch_from.lock_read()
1035
self.add_cleanup(branch_from.unlock)
1027
1037
if branch_to.get_parent() is None or remember:
1028
1038
branch_to.set_parent(branch_from.base)
1030
if branch_from is not branch_to:
1031
branch_from.lock_read()
1032
self.add_cleanup(branch_from.unlock)
1033
1040
if revision is not None:
1034
1041
revision_id = revision.as_revision_id(branch_from)
1036
branch_to.lock_write()
1037
self.add_cleanup(branch_to.unlock)
1038
1043
if tree_to is not None:
1039
1044
view_info = _get_view_info_for_change_reporter(tree_to)
1040
1045
change_reporter = delta._ChangeReporter(
1122
1127
# Get the source branch
1123
1128
(tree, br_from,
1124
1129
_unused) = bzrdir.BzrDir.open_containing_tree_or_branch(directory)
1126
strict = br_from.get_config().get_user_option_as_bool('push_strict')
1127
if strict is None: strict = True # default value
1128
1130
# Get the tip's revision_id
1129
1131
revision = _get_one_revision('push', revision)
1130
1132
if revision is not None:
1131
1133
revision_id = revision.in_history(br_from).rev_id
1133
1135
revision_id = None
1134
if strict and tree is not None and revision_id is None:
1135
if (tree.has_changes()):
1136
raise errors.UncommittedChanges(
1137
tree, more='Use --no-strict to force the push.')
1138
if tree.last_revision() != tree.branch.last_revision():
1139
# The tree has lost sync with its branch, there is little
1140
# chance that the user is aware of it but he can still force
1141
# the push with --no-strict
1142
raise errors.OutOfDateTree(
1143
tree, more='Use --no-strict to force the push.')
1136
if tree is not None and revision_id is None:
1137
tree.warn_if_changed_or_out_of_date(
1138
strict, 'push_strict', 'Use --no-strict to force the push.')
1145
1139
# Get the stacked_on branch, if any
1146
1140
if stacked_on is not None:
1147
1141
stacked_on = urlutils.normalize_url(stacked_on)
1428
1422
branch_location = tree.branch.base
1429
1423
self.add_cleanup(tree.unlock)
1430
1424
# get rid of the final '/' and be ready for display
1431
branch_location = urlutils.unescape_for_display(branch_location[:-1],
1425
branch_location = urlutils.unescape_for_display(
1426
branch_location.rstrip('/'),
1433
1428
existing_pending_merges = tree.get_parent_ids()[1:]
1434
1429
if master is None:
1444
1439
revision_id = branch.last_revision()
1445
1440
if revision_id == _mod_revision.ensure_null(tree.last_revision()):
1446
revno = branch.revision_id_to_revno(revision_id)
1447
note("Tree is up to date at revision %d of branch %s" %
1448
(revno, branch_location))
1441
revno = branch.revision_id_to_dotted_revno(revision_id)
1442
note("Tree is up to date at revision %s of branch %s" %
1443
('.'.join(map(str, revno)), branch_location))
1450
1445
view_info = _get_view_info_for_change_reporter(tree)
1451
1446
change_reporter = delta._ChangeReporter(
1463
1458
"bzr update --revision only works"
1464
1459
" for a revision in the branch history"
1465
1460
% (e.revision))
1466
revno = tree.branch.revision_id_to_revno(
1461
revno = tree.branch.revision_id_to_dotted_revno(
1467
1462
_mod_revision.ensure_null(tree.last_revision()))
1468
note('Updated to revision %d of branch %s' %
1469
(revno, branch_location))
1470
if tree.get_parent_ids()[1:] != existing_pending_merges:
1463
note('Updated to revision %s of branch %s' %
1464
('.'.join(map(str, revno)), branch_location))
1465
parent_ids = tree.get_parent_ids()
1466
if parent_ids[1:] and parent_ids[1:] != existing_pending_merges:
1471
1467
note('Your local commits will now show as pending merges with '
1472
1468
"'bzr status', and can be committed with 'bzr commit'.")
1473
1469
if conflicts != 0:
1949
1945
help='Use this command to compare files.',
1948
RegistryOption('format',
1949
help='Diff format to use.',
1950
lazy_registry=('bzrlib.diff', 'format_registry'),
1951
value_switches=False, title='Diff format'),
1953
1953
aliases = ['di', 'dif']
1954
1954
encoding_type = 'exact'
1956
1956
@display_command
1957
1957
def run(self, revision=None, file_list=None, diff_options=None,
1958
prefix=None, old=None, new=None, using=None):
1959
from bzrlib.diff import get_trees_and_branches_to_diff, show_diff_trees
1958
prefix=None, old=None, new=None, using=None, format=None):
1959
from bzrlib.diff import (get_trees_and_branches_to_diff_locked,
1961
1962
if (prefix is None) or (prefix == '0'):
1962
1963
# diff -p0 format
1976
1977
raise errors.BzrCommandError('bzr diff --revision takes exactly'
1977
1978
' one or two revision specifiers')
1980
if using is not None and format is not None:
1981
raise errors.BzrCommandError('--using and --format are mutually '
1979
1984
(old_tree, new_tree,
1980
1985
old_branch, new_branch,
1981
specific_files, extra_trees) = get_trees_and_branches_to_diff(
1982
file_list, revision, old, new, apply_view=True)
1986
specific_files, extra_trees) = get_trees_and_branches_to_diff_locked(
1987
file_list, revision, old, new, self.add_cleanup, apply_view=True)
1983
1988
return show_diff_trees(old_tree, new_tree, sys.stdout,
1984
1989
specific_files=specific_files,
1985
1990
external_diff_options=diff_options,
1986
1991
old_label=old_label, new_label=new_label,
1987
extra_trees=extra_trees, using=using)
1992
extra_trees=extra_trees, using=using,
1990
1996
class cmd_deleted(Command):
3135
3141
'(use --file "%(f)s" to take commit message from that file)'
3136
3142
% { 'f': message })
3137
3143
ui.ui_factory.show_warning(warning_msg)
3145
message = message.replace('\r\n', '\n')
3146
message = message.replace('\r', '\n')
3148
raise errors.BzrCommandError(
3149
"please specify either --message or --file")
3139
3151
def get_message(commit_obj):
3140
3152
"""Callback to get commit message"""
3141
my_message = message
3142
if my_message is not None and '\r' in my_message:
3143
my_message = my_message.replace('\r\n', '\n')
3144
my_message = my_message.replace('\r', '\n')
3145
if my_message is None and not file:
3146
t = make_commit_message_template_encoded(tree,
3154
my_message = codecs.open(
3155
file, 'rt', osutils.get_user_encoding()).read()
3156
elif message is not None:
3157
my_message = message
3159
# No message supplied: make one up.
3160
# text is the status of the tree
3161
text = make_commit_message_template_encoded(tree,
3147
3162
selected_list, diff=show_diff,
3148
3163
output_encoding=osutils.get_user_encoding())
3164
# start_message is the template generated from hooks
3165
# XXX: Warning - looks like hooks return unicode,
3166
# make_commit_message_template_encoded returns user encoding.
3167
# We probably want to be using edit_commit_message instead to
3149
3169
start_message = generate_commit_message_template(commit_obj)
3150
my_message = edit_commit_message_encoded(t,
3170
my_message = edit_commit_message_encoded(text,
3151
3171
start_message=start_message)
3152
3172
if my_message is None:
3153
3173
raise errors.BzrCommandError("please specify a commit"
3154
3174
" message with either --message or --file")
3155
elif my_message and file:
3156
raise errors.BzrCommandError(
3157
"please specify either --message or --file")
3159
my_message = codecs.open(file, 'rt',
3160
osutils.get_user_encoding()).read()
3161
3175
if my_message == "":
3162
3176
raise errors.BzrCommandError("empty commit message specified")
3163
3177
return my_message
3175
3189
timezone=offset,
3176
3190
exclude=safe_relpath_files(tree, exclude))
3177
3191
except PointlessCommit:
3178
# FIXME: This should really happen before the file is read in;
3179
# perhaps prepare the commit; get the message; then actually commit
3180
3192
raise errors.BzrCommandError("No changes to commit."
3181
3193
" Use --unchanged to commit anyhow.")
3182
3194
except ConflictsInTree:
4062
4074
def run(self, file_list=None, merge_type=None, show_base=False,
4063
4075
reprocess=False):
4076
from bzrlib.conflicts import restore
4064
4077
if merge_type is None:
4065
4078
merge_type = _mod_merge.Merge3Merger
4066
4079
tree, file_list = tree_files(file_list)
4181
4194
def run(self, revision=None, no_backup=False, file_list=None,
4182
4195
forget_merges=None):
4183
4196
tree, file_list = tree_files(file_list)
4197
tree.lock_tree_write()
4185
4198
self.add_cleanup(tree.unlock)
4186
4199
if forget_merges:
4187
4200
tree.set_parent_ids(tree.get_parent_ids()[:1])
4338
4354
remote_branch = Branch.open(other_branch)
4339
4355
if remote_branch.base == local_branch.base:
4340
4356
remote_branch = local_branch
4358
remote_branch.lock_read()
4359
self.add_cleanup(remote_branch.unlock)
4342
local_branch.lock_read()
4343
self.add_cleanup(local_branch.unlock)
4344
4361
local_revid_range = _revision_range_to_revid_range(
4345
4362
_get_revision_range(my_revision, local_branch,
4348
remote_branch.lock_read()
4349
self.add_cleanup(remote_branch.unlock)
4350
4365
remote_revid_range = _revision_range_to_revid_range(
4351
4366
_get_revision_range(revision,
4352
4367
remote_branch, self.name()))
5993
6008
self.outf.write('%s %s\n' % (path, location))
5996
# these get imported and then picked up by the scan for cmd_*
5997
# TODO: Some more consistent way to split command definitions across files;
5998
# we do need to load at least some information about them to know of
5999
# aliases. ideally we would avoid loading the implementation until the
6000
# details were needed.
6001
from bzrlib.cmd_version_info import cmd_version_info
6002
from bzrlib.conflicts import cmd_resolve, cmd_conflicts, restore
6003
from bzrlib.bundle.commands import (
6006
from bzrlib.foreign import cmd_dpush
6007
from bzrlib.sign_my_commits import cmd_sign_my_commits
6011
def _register_lazy_builtins():
6012
# register lazy builtins from other modules; called at startup and should
6013
# be only called once.
6014
for (name, aliases, module_name) in [
6015
('cmd_bundle_info', [], 'bzrlib.bundle.commands'),
6016
('cmd_dpush', [], 'bzrlib.foreign'),
6017
('cmd_version_info', [], 'bzrlib.cmd_version_info'),
6018
('cmd_resolve', ['resolved'], 'bzrlib.conflicts'),
6019
('cmd_conflicts', [], 'bzrlib.conflicts'),
6020
('cmd_sign_my_commits', [], 'bzrlib.sign_my_commits'),
6022
builtin_command_registry.register_lazy(name, aliases, module_name)