38
38
from bzrlib.workingtree import WorkingTree
41
def tree_files(file_list, default_branch='.'):
41
def tree_files(file_list, default_branch=u'.'):
43
43
return internal_tree_files(file_list, default_branch)
44
44
except FileInWrongBranch, e:
45
45
raise BzrCommandError("%s is not in the same branch as %s" %
46
46
(e.path, file_list[0]))
48
def internal_tree_files(file_list, default_branch='.'):
48
def internal_tree_files(file_list, default_branch=u'.'):
50
50
Return a branch and list of branch-relative paths.
51
51
If supplied file_list is empty or None, the branch default will be used,
58
58
for filename in file_list:
60
60
new_list.append(tree.relpath(filename))
61
except NotBranchError:
61
except errors.PathNotChild:
62
62
raise FileInWrongBranch(tree.branch, filename)
63
63
return tree, new_list
142
142
raise BzrCommandError('You can only supply one of revision_id or --revision')
143
143
if revision_id is None and revision is None:
144
144
raise BzrCommandError('You must supply either --revision or a revision_id')
145
b = WorkingTree.open_containing('.')[0].branch
145
b = WorkingTree.open_containing(u'.')[0].branch
146
146
if revision_id is not None:
147
147
sys.stdout.write(b.storage.get_revision_xml(revision_id))
148
148
elif revision is not None:
157
157
"""Show current revision number.
159
159
This is equal to the number of revisions on this branch."""
160
takes_args = ['location?']
162
print Branch.open_containing('.')[0].revno()
162
def run(self, location=u'.'):
163
print Branch.open_containing(location)[0].revno()
165
166
class cmd_revision_info(Command):
263
264
def run(self, revision=None, show_ids=False, kind=None):
264
265
if kind and kind not in ['file', 'directory', 'symlink']:
265
266
raise BzrCommandError('invalid kind specified')
266
tree = WorkingTree.open_containing('.')[0]
267
tree = WorkingTree.open_containing(u'.')[0]
267
268
if revision is None:
268
269
inv = tree.read_working_inventory()
375
376
from shutil import rmtree
377
378
# FIXME: too much stuff is in the command class
378
tree_to = WorkingTree.open_containing('.')[0]
379
tree_to = WorkingTree.open_containing(u'.')[0]
379
380
stored_loc = tree_to.branch.get_parent()
380
381
if location is None:
381
382
if stored_loc is None:
396
397
if br_to.get_parent() is None or remember:
397
398
br_to.set_parent(location)
398
note('%d revision(s) pulled.', count)
399
note('%d revision(s) pulled.' % (count,))
400
402
new_rh = tree_to.branch.revision_history()
401
403
if old_rh != new_rh:
441
443
from shutil import rmtree
442
444
from bzrlib.transport import get_transport
444
tree_from = WorkingTree.open_containing('.')[0]
446
tree_from = WorkingTree.open_containing(u'.')[0]
445
447
br_from = tree_from.branch
446
448
stored_loc = tree_from.branch.get_push_location()
447
449
if location is None:
477
479
raise BzrCommandError("Could not creeate "
479
481
br_to = Branch.initialize(location)
482
old_rh = br_to.revision_history()
481
old_rh = br_to.revision_history()
482
count = br_to.pull(br_from, overwrite)
485
tree_to = br_to.working_tree()
486
except NoWorkingTree:
487
# TODO: This should be updated for branches which don't have a
488
# working tree, as opposed to ones where we just couldn't
490
warning('Unable to update the working tree of: %s' % (br_to.base,))
491
count = br_to.pull(br_from, overwrite)
493
count = tree_to.pull(br_from, overwrite)
483
494
except DivergedBranches:
484
495
raise BzrCommandError("These branches have diverged."
485
496
" Try a merge then push with overwrite.")
486
497
if br_from.get_push_location() is None or remember:
487
498
br_from.set_push_location(location)
488
499
note('%d revision(s) pushed.' % (count,))
490
502
new_rh = br_to.revision_history()
491
503
if old_rh != new_rh:
784
796
# if the directories are very large...)
786
798
def run(self, show_ids=False):
787
tree = WorkingTree.open_containing('.')[0]
799
tree = WorkingTree.open_containing(u'.')[0]
788
800
old = tree.branch.basis_tree()
789
801
for path, ie in old.inventory.iter_entries():
790
802
if not tree.has_id(ie.file_id):
802
814
from bzrlib.delta import compare_trees
804
tree = WorkingTree.open_containing('.')[0]
816
tree = WorkingTree.open_containing(u'.')[0]
805
817
td = compare_trees(tree.branch.basis_tree(), tree)
807
819
for path, id, kind, text_modified, meta_modified in td.modified:
990
1002
selection = {'I':ignored, '?':unknown, 'V':versioned}
992
tree, relpath = WorkingTree.open_containing('.')
1004
tree, relpath = WorkingTree.open_containing(u'.')
997
1009
if revision is not None:
1049
1061
from bzrlib.atomicfile import AtomicFile
1052
tree, relpath = WorkingTree.open_containing('.')
1064
tree, relpath = WorkingTree.open_containing(u'.')
1053
1065
ifn = tree.abspath('.bzrignore')
1055
1067
if os.path.exists(ifn):
1089
1101
See also: bzr ignore"""
1090
1102
@display_command
1092
tree = WorkingTree.open_containing('.')[0]
1104
tree = WorkingTree.open_containing(u'.')[0]
1093
1105
for path, file_class, kind, file_id, entry in tree.list_files():
1094
1106
if file_class != 'I':
1114
1126
except ValueError:
1115
1127
raise BzrCommandError("not a valid revision-number: %r" % revno)
1117
print WorkingTree.open_containing('.')[0].branch.get_rev_id(revno)
1129
print WorkingTree.open_containing(u'.')[0].branch.get_rev_id(revno)
1120
1132
class cmd_export(Command):
1144
1156
def run(self, dest, revision=None, format=None, root=None):
1146
1158
from bzrlib.export import export
1147
tree = WorkingTree.open_containing('.')[0]
1159
tree = WorkingTree.open_containing(u'.')[0]
1148
1160
b = tree.branch
1149
1161
if revision is None:
1150
1162
# should be tree.last_revision FIXME
1169
1181
@display_command
1170
1182
def run(self, filename, revision=None):
1171
if revision is None:
1172
raise BzrCommandError("bzr cat requires a revision number")
1173
elif len(revision) != 1:
1183
if revision is not None and len(revision) != 1:
1174
1184
raise BzrCommandError("bzr cat --revision takes exactly one number")
1178
1188
b = tree.branch
1179
1189
except NotBranchError:
1181
1192
if tree is None:
1182
1193
b, relpath = Branch.open_containing(filename)
1183
b.print_file(relpath, revision[0].in_history(b).revno)
1194
if revision is None:
1195
revision_id = b.last_revision()
1197
revision_id = revision[0].in_history(b).rev_id
1198
b.print_file(relpath, revision_id)
1186
1201
class cmd_local_time_offset(Command):
1231
1246
unchanged=False, strict=False):
1232
1247
from bzrlib.errors import (PointlessCommit, ConflictsInTree,
1233
1248
StrictCommitFailed)
1234
from bzrlib.msgeditor import edit_commit_message
1249
from bzrlib.msgeditor import edit_commit_message, \
1250
make_commit_message_template
1235
1251
from bzrlib.status import show_status
1236
from cStringIO import StringIO
1252
from tempfile import TemporaryFile
1255
# TODO: Need a blackbox test for invoking the external editor; may be
1256
# slightly problematic to run this cross-platform.
1258
# TODO: do more checks that the commit will succeed before
1259
# spending the user's valuable time typing a commit message.
1261
# TODO: if the commit *does* happen to fail, then save the commit
1262
# message to a temporary file where it can be recovered
1238
1263
tree, selected_list = tree_files(selected_list)
1239
1264
if message is None and not file:
1240
catcher = StringIO()
1241
show_status(tree.branch, specific_files=selected_list,
1243
message = edit_commit_message(catcher.getvalue())
1265
template = make_commit_message_template(tree, selected_list)
1266
message = edit_commit_message(template)
1245
1267
if message is None:
1246
1268
raise BzrCommandError("please specify a commit message"
1247
1269
" with either --message or --file")
1270
1292
raise BzrCommandError("Commit refused because there are unknown "
1271
1293
"files in the working tree.")
1272
1294
note('Committed revision %d.' % (tree.branch.revno(),))
1275
1297
class cmd_check(Command):
1276
1298
"""Validate consistency of branch history.
1334
1356
@display_command
1335
1357
def run(self, email=False):
1337
b = WorkingTree.open_containing('.')[0].branch
1359
b = WorkingTree.open_containing(u'.')[0].branch
1338
1360
config = bzrlib.config.BranchConfig(b)
1339
1361
except NotBranchError:
1340
1362
config = bzrlib.config.GlobalConfig()
1353
1375
takes_args = ['nickname?']
1354
1376
def run(self, nickname=None):
1355
branch = Branch.open_containing('.')[0]
1377
branch = Branch.open_containing(u'.')[0]
1356
1378
if nickname is None:
1357
1379
self.printme(branch)
1730
1752
if verbose and is_quiet():
1731
1753
raise BzrCommandError('Cannot pass both quiet and verbose')
1733
tree = WorkingTree.open_containing('.')[0]
1755
tree = WorkingTree.open_containing(u'.')[0]
1734
1756
parent = tree.branch.get_parent()
1735
1757
if remote is None:
1736
1758
if parent is None:
1756
1778
import bzrlib.plugin
1757
1779
from inspect import getdoc
1758
for plugin in bzrlib.plugin.all_plugins:
1780
for name, plugin in bzrlib.plugin.all_plugins().items():
1759
1781
if hasattr(plugin, '__path__'):
1760
1782
print plugin.__path__[0]
1761
1783
elif hasattr(plugin, '__file__'):
1773
1795
takes_options = ['revision', 'long']
1774
1796
takes_args = ['branch?']
1775
1797
@display_command
1776
def run(self, branch='.', revision=None, long=False):
1798
def run(self, branch=u'.', revision=None, long=False):
1777
1799
from bzrlib.testament import Testament
1778
1800
b = WorkingTree.open_containing(branch)[0].branch
1840
1862
raise BzrCommandError('You can only supply one of revision_id or --revision')
1841
1863
if revision_id is None and revision is None:
1842
1864
raise BzrCommandError('You must supply either --revision or a revision_id')
1843
b = WorkingTree.open_containing('.')[0].branch
1865
b = WorkingTree.open_containing(u'.')[0].branch
1844
1866
gpg_strategy = gpg.GPGStrategy(config.BranchConfig(b))
1845
1867
if revision_id is not None:
1846
1868
b.storage.sign_revision(revision_id, gpg_strategy)