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 branch_files(file_list, default_branch='.'):
42
return inner_branch_files(file_list, default_branch)
43
except FileInWrongBranch, e:
45
raise BzrCommandError("%s is not in the same branch as %s" %
46
(e.path, file_list[0]))
48
def inner_branch_files(file_list, default_branch='.'):
40
50
Return a branch and list of branch-relative paths.
41
51
If supplied file_list is empty or None, the branch default will be used,
56
66
new_list.append(tree.relpath(filename))
57
67
except NotBranchError:
58
raise BzrCommandError("%s is not in the same branch as %s" %
59
(filename, file_list[0]))
68
raise FileInWrongBranch(b, filename)
106
115
that revision, or between two revisions if two are provided.
109
# XXX: FIXME: bzr status should accept a -r option to show changes
110
# relative to a revision, or between revisions
112
118
# TODO: --no-recurse, --recurse options
114
120
takes_args = ['file*']
115
takes_options = ['all', 'show-ids']
121
takes_options = ['all', 'show-ids', 'revision']
116
122
aliases = ['st', 'stat']
739
745
def run(self, revision=None, file_list=None, diff_options=None):
740
746
from bzrlib.diff import show_diff
742
b, file_list = branch_files(file_list)
748
b, file_list = inner_branch_files(file_list)
750
except FileInWrongBranch:
751
if len(file_list) != 2:
752
raise BzrCommandError("Files are in different branches")
754
b, file1 = Branch.open_containing(file_list[0])
755
b2, file2 = Branch.open_containing(file_list[1])
756
if file1 != "" or file2 != "":
757
raise BzrCommandError("Files are in different branches")
743
759
if revision is not None:
761
raise BzrCommandError("Can't specify -r with two branches")
744
762
if len(revision) == 1:
745
763
return show_diff(b, revision[0], specific_files=file_list,
746
764
external_diff_options=diff_options)
752
770
raise BzrCommandError('bzr diff --revision takes exactly one or two revision identifiers')
754
772
return show_diff(b, None, specific_files=file_list,
755
external_diff_options=diff_options)
773
external_diff_options=diff_options, b2=b2)
758
776
class cmd_deleted(Command):
888
906
raise BzrCommandError('bzr log --revision takes one or two values.')
908
# By this point, the revision numbers are converted to the +ve
909
# form if they were supplied in the -ve form, so we can do
910
# this comparison in relative safety
912
(rev2, rev1) = (rev1, rev2)
895
914
mutter('encoding log as %r', bzrlib.user_encoding)
1310
1329
print config.username()
1331
class cmd_nick(Command):
1333
Print or set the branch nickname.
1334
If unset, the tree root directory name is used as the nickname
1335
To print the current nickname, execute with no argument.
1337
takes_args = ['nickname?']
1338
def run(self, nickname=None):
1339
branch = Branch.open_containing('.')[0]
1340
if nickname is None:
1341
self.printme(branch)
1343
branch.nick = nickname
1346
def printme(self, branch):
1313
1349
class cmd_selftest(Command):
1314
1350
"""Run internal test suite.
1316
1352
This creates temporary test directories in the working directory,
1317
1353
but not existing data is affected. These directories are deleted
1318
1354
if the tests pass, or left behind to help in debugging if they
1355
fail and --keep-output is specified.
1321
1357
If arguments are given, they are regular expressions that say
1322
1358
which tests should run.
1326
1362
takes_args = ['testspecs*']
1327
1363
takes_options = ['verbose',
1328
1364
Option('one', help='stop when one test fails'),
1365
Option('keep-output',
1366
help='keep output directories when tests fail')
1331
def run(self, testspecs_list=None, verbose=False, one=False):
1369
def run(self, testspecs_list=None, verbose=False, one=False,
1332
1371
import bzrlib.ui
1333
1372
from bzrlib.selftest import selftest
1334
1373
# we don't want progress meters from the tests to go to the
1546
class cmd_remerge(Command):
1549
takes_args = ['file*']
1550
takes_options = ['merge-type', 'reprocess',
1551
Option('show-base', help="Show base revision text in "
1554
def run(self, file_list=None, merge_type=None, show_base=False,
1556
from bzrlib.merge import merge_inner, transform_tree
1557
from bzrlib.merge_core import ApplyMerge3
1558
if merge_type is None:
1559
merge_type = ApplyMerge3
1560
b, file_list = branch_files(file_list)
1563
pending_merges = b.working_tree().pending_merges()
1564
if len(pending_merges) != 1:
1565
raise BzrCommandError("Sorry, remerge only works after normal"
1566
+ " merges. Not cherrypicking or"
1568
this_tree = b.working_tree()
1569
base_revision = common_ancestor(b.last_revision(),
1570
pending_merges[0], b)
1571
base_tree = b.revision_tree(base_revision)
1572
other_tree = b.revision_tree(pending_merges[0])
1573
interesting_ids = None
1574
if file_list is not None:
1575
interesting_ids = set()
1576
for filename in file_list:
1577
file_id = this_tree.path2id(filename)
1578
interesting_ids.add(file_id)
1579
if this_tree.kind(file_id) != "directory":
1582
for name, ie in this_tree.inventory.iter_entries(file_id):
1583
interesting_ids.add(ie.file_id)
1584
transform_tree(this_tree, b.basis_tree(), interesting_ids)
1585
if file_list is None:
1586
restore_files = list(this_tree.iter_conflicts())
1588
restore_files = file_list
1589
for filename in restore_files:
1591
restore(this_tree.abspath(filename))
1592
except NotConflicted:
1594
conflicts = merge_inner(b, other_tree, base_tree,
1595
interesting_ids = interesting_ids,
1596
other_rev_id=pending_merges[0],
1597
merge_type=merge_type,
1598
show_base=show_base,
1599
reprocess=reprocess)
1506
1607
class cmd_revert(Command):
1507
1608
"""Reverse all changes since the last commit.
1751
1852
# TODO: Some more consistent way to split command definitions across files;
1752
1853
# we do need to load at least some information about them to know of
1754
from bzrlib.conflicts import cmd_resolve, cmd_conflicts
1855
from bzrlib.conflicts import cmd_resolve, cmd_conflicts, restore