26
26
from bzrlib import BZRDIR
27
27
from bzrlib.commands import Command, display_command
28
28
from bzrlib.branch import Branch
29
from bzrlib.errors import BzrError, BzrCheckError, BzrCommandError, NotBranchError
30
from bzrlib.errors import DivergedBranches, NoSuchFile, NoWorkingTree
29
from bzrlib.revision import common_ancestor
30
from bzrlib.errors import (BzrError, BzrCheckError, BzrCommandError,
31
NotBranchError, DivergedBranches, NotConflicted,
32
NoSuchFile, NoWorkingTree, FileInWrongBranch)
31
33
from bzrlib.option import Option
32
34
from bzrlib.revisionspec import RevisionSpec
33
35
import bzrlib.trace
38
40
def tree_files(file_list, default_branch='.'):
42
return internal_tree_files(file_list, default_branch)
43
except FileInWrongBranch, e:
44
raise BzrCommandError("%s is not in the same branch as %s" %
45
(e.path, file_list[0]))
47
def internal_tree_files(file_list, default_branch='.'):
40
49
Return a branch and list of branch-relative paths.
41
50
If supplied file_list is empty or None, the branch default will be used,
50
59
new_list.append(tree.relpath(filename))
51
60
except NotBranchError:
52
raise BzrCommandError("%s is not in the same tree as %s" %
53
(filename, file_list[0]))
61
raise FileInWrongBranch(tree.branch, filename)
54
62
return tree, new_list
100
108
that revision, or between two revisions if two are provided.
103
# XXX: FIXME: bzr status should accept a -r option to show changes
104
# relative to a revision, or between revisions
106
111
# TODO: --no-recurse, --recurse options
108
113
takes_args = ['file*']
109
takes_options = ['all', 'show-ids']
114
takes_options = ['all', 'show-ids', 'revision']
110
115
aliases = ['st', 'stat']
248
253
class cmd_inventory(Command):
249
"""Show inventory of the current working copy or a revision."""
250
takes_options = ['revision', 'show-ids']
254
"""Show inventory of the current working copy or a revision.
256
It is possible to limit the output to a particular entry
257
type using the --kind option. For example; --kind file.
259
takes_options = ['revision', 'show-ids', 'kind']
253
def run(self, revision=None, show_ids=False):
262
def run(self, revision=None, show_ids=False, kind=None):
263
if kind and kind not in ['file', 'directory', 'symlink']:
264
raise BzrCommandError('invalid kind specified')
254
265
tree = WorkingTree.open_containing('.')[0]
255
266
if revision is None:
256
267
inv = tree.read_working_inventory()
262
273
revision[0].in_history(tree.branch).rev_id)
264
275
for path, entry in inv.entries():
276
if kind and kind != entry.kind:
266
279
print '%-50s %s' % (path, entry.file_id)
659
672
print revision_id
662
class cmd_directories(Command):
663
"""Display list of versioned directories in this tree."""
666
for name, ie in (WorkingTree.open_containing('.')[0].
667
read_working_inventory().directories()):
674
675
class cmd_init(Command):
675
676
"""Make a directory into a versioned branch.
733
734
def run(self, revision=None, file_list=None, diff_options=None):
734
735
from bzrlib.diff import show_diff
736
tree, file_list = tree_files(file_list)
737
tree, file_list = internal_tree_files(file_list)
740
except FileInWrongBranch:
741
if len(file_list) != 2:
742
raise BzrCommandError("Files are in different branches")
744
b, file1 = Branch.open_containing(file_list[0])
745
b2, file2 = Branch.open_containing(file_list[1])
746
if file1 != "" or file2 != "":
747
# FIXME diff those two files. rbc 20051123
748
raise BzrCommandError("Files are in different branches")
737
750
if revision is not None:
752
raise BzrCommandError("Can't specify -r with two branches")
738
753
if len(revision) == 1:
739
754
return show_diff(tree.branch, revision[0], specific_files=file_list,
740
755
external_diff_options=diff_options)
746
761
raise BzrCommandError('bzr diff --revision takes exactly one or two revision identifiers')
748
return show_diff(tree.branch, None, specific_files=file_list,
749
external_diff_options=diff_options)
764
return show_diff(b, None, specific_files=file_list,
765
external_diff_options=diff_options, b2=b2)
767
return show_diff(tree.branch, None, specific_files=file_list,
768
external_diff_options=diff_options)
752
771
class cmd_deleted(Command):
889
908
raise BzrCommandError('bzr log --revision takes one or two values.')
910
# By this point, the revision numbers are converted to the +ve
911
# form if they were supplied in the -ve form, so we can do
912
# this comparison in relative safety
914
(rev2, rev1) = (rev1, rev2)
896
916
mutter('encoding log as %r', bzrlib.user_encoding)
1317
1337
print config.username()
1339
class cmd_nick(Command):
1341
Print or set the branch nickname.
1342
If unset, the tree root directory name is used as the nickname
1343
To print the current nickname, execute with no argument.
1345
takes_args = ['nickname?']
1346
def run(self, nickname=None):
1347
branch = Branch.open_containing('.')[0]
1348
if nickname is None:
1349
self.printme(branch)
1351
branch.nick = nickname
1354
def printme(self, branch):
1320
1357
class cmd_selftest(Command):
1321
1358
"""Run internal test suite.
1323
1360
This creates temporary test directories in the working directory,
1324
1361
but not existing data is affected. These directories are deleted
1325
1362
if the tests pass, or left behind to help in debugging if they
1363
fail and --keep-output is specified.
1328
1365
If arguments are given, they are regular expressions that say
1329
1366
which tests should run.
1333
1370
takes_args = ['testspecs*']
1334
1371
takes_options = ['verbose',
1335
1372
Option('one', help='stop when one test fails'),
1373
Option('keep-output',
1374
help='keep output directories when tests fail')
1338
def run(self, testspecs_list=None, verbose=False, one=False):
1377
def run(self, testspecs_list=None, verbose=False, one=False,
1339
1379
import bzrlib.ui
1340
1380
from bzrlib.selftest import selftest
1341
1381
# we don't want progress meters from the tests to go to the
1554
class cmd_remerge(Command):
1557
takes_args = ['file*']
1558
takes_options = ['merge-type', 'reprocess',
1559
Option('show-base', help="Show base revision text in "
1562
def run(self, file_list=None, merge_type=None, show_base=False,
1564
from bzrlib.merge import merge_inner, transform_tree
1565
from bzrlib.merge_core import ApplyMerge3
1566
if merge_type is None:
1567
merge_type = ApplyMerge3
1568
tree, file_list = tree_files(file_list)
1571
pending_merges = tree.pending_merges()
1572
if len(pending_merges) != 1:
1573
raise BzrCommandError("Sorry, remerge only works after normal"
1574
+ " merges. Not cherrypicking or"
1576
base_revision = common_ancestor(tree.branch.last_revision(),
1577
pending_merges[0], tree.branch)
1578
base_tree = tree.branch.revision_tree(base_revision)
1579
other_tree = tree.branch.revision_tree(pending_merges[0])
1580
interesting_ids = None
1581
if file_list is not None:
1582
interesting_ids = set()
1583
for filename in file_list:
1584
file_id = tree.path2id(filename)
1585
interesting_ids.add(file_id)
1586
if tree.kind(file_id) != "directory":
1589
for name, ie in tree.inventory.iter_entries(file_id):
1590
interesting_ids.add(ie.file_id)
1591
transform_tree(tree, tree.branch.basis_tree(), interesting_ids)
1592
if file_list is None:
1593
restore_files = list(tree.iter_conflicts())
1595
restore_files = file_list
1596
for filename in restore_files:
1598
restore(tree.abspath(filename))
1599
except NotConflicted:
1601
conflicts = merge_inner(tree.branch, other_tree, base_tree,
1602
interesting_ids = interesting_ids,
1603
other_rev_id=pending_merges[0],
1604
merge_type=merge_type,
1605
show_base=show_base,
1606
reprocess=reprocess)
1513
1614
class cmd_revert(Command):
1514
1615
"""Reverse all changes since the last commit.
1759
1860
# TODO: Some more consistent way to split command definitions across files;
1760
1861
# we do need to load at least some information about them to know of
1762
from bzrlib.conflicts import cmd_resolve, cmd_conflicts
1863
from bzrlib.conflicts import cmd_resolve, cmd_conflicts, restore