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.revision import common_ancestor
29
30
import bzrlib.errors as errors
30
from bzrlib.errors import BzrError, BzrCheckError, BzrCommandError, NotBranchError
31
from bzrlib.errors import DivergedBranches, NoSuchFile, NoWorkingTree
31
from bzrlib.errors import (BzrError, BzrCheckError, BzrCommandError,
32
NotBranchError, DivergedBranches, NotConflicted,
33
NoSuchFile, NoWorkingTree)
32
34
from bzrlib.option import Option
33
35
from bzrlib.revisionspec import RevisionSpec
34
36
import bzrlib.trace
39
41
def branch_files(file_list, default_branch='.'):
43
return inner_branch_files(file_list, default_branch)
44
except NotBranchError:
45
raise BzrCommandError("%s is not in the same branch as %s" %
46
(filename, file_list[0]))
48
def inner_branch_files(file_list, default_branch='.'):
41
50
Return a branch and list of branch-relative paths.
42
51
If supplied file_list is empty or None, the branch default will be used,
53
62
tree = WorkingTree(b.base, b)
55
64
for filename in file_list:
57
new_list.append(tree.relpath(filename))
58
except NotBranchError:
59
raise BzrCommandError("%s is not in the same branch as %s" %
60
(filename, file_list[0]))
65
new_list.append(tree.relpath(filename))
107
112
that revision, or between two revisions if two are provided.
110
# XXX: FIXME: bzr status should accept a -r option to show changes
111
# relative to a revision, or between revisions
113
115
# TODO: --no-recurse, --recurse options
115
117
takes_args = ['file*']
116
takes_options = ['all', 'show-ids']
118
takes_options = ['all', 'show-ids', 'revision']
117
119
aliases = ['st', 'stat']
740
742
def run(self, revision=None, file_list=None, diff_options=None):
741
743
from bzrlib.diff import show_diff
743
b, file_list = branch_files(file_list)
745
b, file_list = inner_branch_files(file_list)
747
except NotBranchError:
748
if len(file_list) != 2:
749
raise BzrCommandError("Files are in different branches")
751
b, file1 = Branch.open_containing(file_list[0])
752
b2, file2 = Branch.open_containing(file_list[1])
753
if file1 != "" or file2 != "":
754
raise BzrCommandError("Files are in different branches")
744
756
if revision is not None:
758
raise BzrCommandError("Can't specify -r with two branches")
745
759
if len(revision) == 1:
746
760
return show_diff(b, revision[0], specific_files=file_list,
747
761
external_diff_options=diff_options)
753
767
raise BzrCommandError('bzr diff --revision takes exactly one or two revision identifiers')
755
769
return show_diff(b, None, specific_files=file_list,
756
external_diff_options=diff_options)
770
external_diff_options=diff_options, b2=b2)
759
773
class cmd_deleted(Command):
1308
1322
print config.username()
1324
class cmd_nick(Command):
1326
Print or set the branch nickname.
1327
If unset, the tree root directory name is used as the nickname
1328
To print the current nickname, execute with no argument.
1330
takes_args = ['nickname?']
1331
def run(self, nickname=None):
1332
branch = Branch.open_containing('.')[0]
1333
if nickname is None:
1334
self.printme(branch)
1336
branch.nick = nickname
1339
def printme(self, branch):
1311
1342
class cmd_selftest(Command):
1312
1343
"""Run internal test suite.
1314
1345
This creates temporary test directories in the working directory,
1315
1346
but not existing data is affected. These directories are deleted
1316
1347
if the tests pass, or left behind to help in debugging if they
1348
fail and --keep-output is specified.
1319
1350
If arguments are given, they are regular expressions that say
1320
1351
which tests should run.
1324
1355
takes_args = ['testspecs*']
1325
1356
takes_options = ['verbose',
1326
1357
Option('one', help='stop when one test fails'),
1358
Option('keep-output',
1359
help='keep output directories when tests fail')
1329
def run(self, testspecs_list=None, verbose=False, one=False):
1362
def run(self, testspecs_list=None, verbose=False, one=False,
1330
1364
import bzrlib.ui
1331
1365
from bzrlib.selftest import selftest
1332
1366
# we don't want progress meters from the tests to go to the
1539
class cmd_remerge(Command):
1542
takes_args = ['file*']
1543
takes_options = ['merge-type', 'reprocess',
1544
Option('show-base', help="Show base revision text in "
1547
def run(self, file_list=None, merge_type=None, show_base=False,
1549
from bzrlib.merge import merge_inner, transform_tree
1550
from bzrlib.merge_core import ApplyMerge3
1551
if merge_type is None:
1552
merge_type = ApplyMerge3
1553
b, file_list = branch_files(file_list)
1556
pending_merges = b.working_tree().pending_merges()
1557
if len(pending_merges) != 1:
1558
raise BzrCommandError("Sorry, remerge only works after normal"
1559
+ " merges. Not cherrypicking or"
1561
this_tree = b.working_tree()
1562
base_revision = common_ancestor(b.last_revision(),
1563
pending_merges[0], b)
1564
base_tree = b.revision_tree(base_revision)
1565
other_tree = b.revision_tree(pending_merges[0])
1566
interesting_ids = None
1567
if file_list is not None:
1568
interesting_ids = set()
1569
for filename in file_list:
1570
file_id = this_tree.path2id(filename)
1571
interesting_ids.add(file_id)
1572
if this_tree.kind(file_id) != "directory":
1575
for name, ie in this_tree.inventory.iter_entries(file_id):
1576
interesting_ids.add(ie.file_id)
1577
transform_tree(this_tree, b.basis_tree(), interesting_ids)
1578
if file_list is None:
1579
restore_files = list(this_tree.iter_conflicts())
1581
restore_files = file_list
1582
for filename in restore_files:
1584
restore(this_tree.abspath(filename))
1585
except NotConflicted:
1587
conflicts = merge_inner(b, other_tree, base_tree,
1588
interesting_ids = interesting_ids,
1589
other_rev_id=pending_merges[0],
1590
merge_type=merge_type,
1591
show_base=show_base,
1592
reprocess=reprocess)
1504
1600
class cmd_revert(Command):
1505
1601
"""Reverse all changes since the last commit.
1749
1845
# TODO: Some more consistent way to split command definitions across files;
1750
1846
# we do need to load at least some information about them to know of
1752
from bzrlib.conflicts import cmd_resolve, cmd_conflicts
1848
from bzrlib.conflicts import cmd_resolve, cmd_conflicts, restore