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
31
30
import bzrlib.errors as errors
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']
364
365
If you want to forget your local changes and just update your branch to
365
366
match the remote one, use --overwrite.
367
takes_options = ['remember', 'overwrite']
368
takes_options = ['remember', 'overwrite', 'verbose']
368
369
takes_args = ['location?']
370
def run(self, location=None, remember=False, overwrite=False):
371
def run(self, location=None, remember=False, overwrite=False, verbose=False):
371
372
from bzrlib.merge import merge
372
373
from shutil import rmtree
395
397
if br_to.get_parent() is None or remember:
396
398
br_to.set_parent(location)
401
new_rh = br_to.revision_history()
404
from bzrlib.log import show_changed_revisions
405
show_changed_revisions(br_to, old_rh, new_rh)
399
408
class cmd_push(Command):
400
409
"""Push this branch into another branch.
426
435
takes_args = ['location?']
428
437
def run(self, location=None, remember=False, overwrite=False,
429
create_prefix=False):
438
create_prefix=False, verbose=False):
431
440
from shutil import rmtree
432
441
from bzrlib.transport import get_transport
476
486
if br_from.get_push_location() is None or remember:
477
487
br_from.set_push_location(location)
490
new_rh = br_to.revision_history()
493
from bzrlib.log import show_changed_revisions
494
show_changed_revisions(br_to, old_rh, new_rh)
480
496
class cmd_branch(Command):
481
497
"""Create a new copy of a branch.
737
753
def run(self, revision=None, file_list=None, diff_options=None):
738
754
from bzrlib.diff import show_diff
740
b, file_list = branch_files(file_list)
756
b, file_list = inner_branch_files(file_list)
758
except NotBranchError:
759
if len(file_list) != 2:
760
raise BzrCommandError("Files are in different branches")
762
b, file1 = Branch.open_containing(file_list[0])
763
b2, file2 = Branch.open_containing(file_list[1])
764
if file1 != "" or file2 != "":
765
raise BzrCommandError("Files are in different branches")
741
767
if revision is not None:
769
raise BzrCommandError("Can't specify -r with two branches")
742
770
if len(revision) == 1:
743
771
return show_diff(b, revision[0], specific_files=file_list,
744
772
external_diff_options=diff_options)
750
778
raise BzrCommandError('bzr diff --revision takes exactly one or two revision identifiers')
752
780
return show_diff(b, None, specific_files=file_list,
753
external_diff_options=diff_options)
781
external_diff_options=diff_options, b2=b2)
756
784
class cmd_deleted(Command):
1102
1130
is found exports to a directory (equivalent to --format=dir).
1104
1132
Root may be the top directory for tar, tgz and tbz2 formats. If none
1105
is given, the top directory will be the root name of the file."""
1106
# TODO: list known exporters
1133
is given, the top directory will be the root name of the file.
1135
Note: export of tree with non-ascii filenames to zip is not supported.
1137
Supported formats Autodetected by extension
1138
----------------- -------------------------
1141
tbz2 .tar.bz2, .tbz2
1107
1145
takes_args = ['dest']
1108
1146
takes_options = ['revision', 'format', 'root']
1109
1147
def run(self, dest, revision=None, format=None, root=None):
1149
from bzrlib.export import export
1111
1150
b = Branch.open_containing('.')[0]
1112
1151
if revision is None:
1113
1152
rev_id = b.last_revision()
1116
1155
raise BzrError('bzr export --revision takes exactly 1 argument')
1117
1156
rev_id = revision[0].in_history(b).rev_id
1118
1157
t = b.revision_tree(rev_id)
1119
arg_root, ext = os.path.splitext(os.path.basename(dest))
1120
if ext in ('.gz', '.bz2'):
1121
new_root, new_ext = os.path.splitext(arg_root)
1122
if new_ext == '.tar':
1128
if ext in (".tar",):
1130
elif ext in (".tar.gz", ".tgz"):
1132
elif ext in (".tar.bz2", ".tbz2"):
1136
t.export(dest, format, root)
1159
export(t, dest, format, root)
1160
except errors.NoSuchExportFormat, e:
1161
raise BzrCommandError('Unsupported export format: %s' % e.format)
1139
1164
class cmd_cat(Command):
1310
1335
print config.username()
1337
class cmd_nick(Command):
1339
Print or set the branch nickname.
1340
If unset, the tree root directory name is used as the nickname
1341
To print the current nickname, execute with no argument.
1343
takes_args = ['nickname?']
1344
def run(self, nickname=None):
1345
branch = Branch.open_containing('.')[0]
1346
if nickname is None:
1347
self.printme(branch)
1349
branch.nick = nickname
1352
def printme(self, branch):
1313
1355
class cmd_selftest(Command):
1314
1356
"""Run internal test suite.
1316
1358
This creates temporary test directories in the working directory,
1317
1359
but not existing data is affected. These directories are deleted
1318
1360
if the tests pass, or left behind to help in debugging if they
1361
fail and --keep-output is specified.
1321
1363
If arguments are given, they are regular expressions that say
1322
1364
which tests should run.
1326
1368
takes_args = ['testspecs*']
1327
1369
takes_options = ['verbose',
1328
1370
Option('one', help='stop when one test fails'),
1371
Option('keep-output',
1372
help='keep output directories when tests fail')
1331
def run(self, testspecs_list=None, verbose=False, one=False):
1375
def run(self, testspecs_list=None, verbose=False, one=False,
1332
1377
import bzrlib.ui
1333
1378
from bzrlib.selftest import selftest
1334
1379
# we don't want progress meters from the tests to go to the
1552
class cmd_remerge(Command):
1555
takes_args = ['file*']
1556
takes_options = ['merge-type', 'reprocess',
1557
Option('show-base', help="Show base revision text in "
1560
def run(self, file_list=None, merge_type=None, show_base=False,
1562
from bzrlib.merge import merge_inner, transform_tree
1563
from bzrlib.merge_core import ApplyMerge3
1564
if merge_type is None:
1565
merge_type = ApplyMerge3
1566
b, file_list = branch_files(file_list)
1569
pending_merges = b.working_tree().pending_merges()
1570
if len(pending_merges) != 1:
1571
raise BzrCommandError("Sorry, remerge only works after normal"
1572
+ " merges. Not cherrypicking or"
1574
this_tree = b.working_tree()
1575
base_revision = common_ancestor(b.last_revision(),
1576
pending_merges[0], b)
1577
base_tree = b.revision_tree(base_revision)
1578
other_tree = b.revision_tree(pending_merges[0])
1579
interesting_ids = None
1580
if file_list is not None:
1581
interesting_ids = set()
1582
for filename in file_list:
1583
file_id = this_tree.path2id(filename)
1584
interesting_ids.add(file_id)
1585
if this_tree.kind(file_id) != "directory":
1588
for name, ie in this_tree.inventory.iter_entries(file_id):
1589
interesting_ids.add(ie.file_id)
1590
transform_tree(this_tree, b.basis_tree(), interesting_ids)
1591
if file_list is None:
1592
restore_files = list(this_tree.iter_conflicts())
1594
restore_files = file_list
1595
for filename in restore_files:
1597
restore(this_tree.abspath(filename))
1598
except NotConflicted:
1600
conflicts = merge_inner(b, other_tree, base_tree,
1601
interesting_ids = interesting_ids,
1602
other_rev_id=pending_merges[0],
1603
merge_type=merge_type,
1604
show_base=show_base,
1605
reprocess=reprocess)
1506
1613
class cmd_revert(Command):
1507
1614
"""Reverse all changes since the last commit.
1808
1915
# TODO: Some more consistent way to split command definitions across files;
1809
1916
# we do need to load at least some information about them to know of
1811
from bzrlib.conflicts import cmd_resolve, cmd_conflicts
1918
from bzrlib.conflicts import cmd_resolve, cmd_conflicts, restore