17
17
"""builtin bzr commands"""
22
from shutil import rmtree
24
from bzrlib import BZRDIR
27
from bzrlib.branch import Branch
28
import bzrlib.bzrdir as bzrdir
25
29
from bzrlib._merge_core import ApplyMerge3
26
30
from bzrlib.commands import Command, display_command
27
from bzrlib.branch import Branch
28
31
from bzrlib.revision import common_ancestor
29
32
import bzrlib.errors as errors
30
33
from bzrlib.errors import (BzrError, BzrCheckError, BzrCommandError,
392
395
If you want to forget your local changes and just update your branch to
393
396
match the remote one, use --overwrite.
395
takes_options = ['remember', 'overwrite', 'verbose']
398
takes_options = ['remember', 'overwrite', 'revision', 'verbose']
396
399
takes_args = ['location?']
398
def run(self, location=None, remember=False, overwrite=False, verbose=False):
399
from shutil import rmtree
401
def run(self, location=None, remember=False, overwrite=False, revision=None, verbose=False):
401
402
# FIXME: too much stuff is in the command class
402
403
tree_to = WorkingTree.open_containing(u'.')[0]
403
404
stored_loc = tree_to.branch.get_parent()
411
412
br_from = Branch.open(location)
412
413
br_to = tree_to.branch
417
elif len(revision) == 1:
418
rev_id = revision[0].in_history(br_from).rev_id
420
raise BzrCommandError('bzr pull --revision takes one value.')
414
422
old_rh = br_to.revision_history()
415
count = tree_to.pull(br_from, overwrite)
423
count = tree_to.pull(br_from, overwrite, rev_id)
417
425
if br_to.get_parent() is None or remember:
418
426
br_to.set_parent(location)
459
467
create_prefix=False, verbose=False):
460
468
# FIXME: Way too big! Put this into a function called from the
463
from shutil import rmtree
464
470
from bzrlib.transport import get_transport
466
472
tree_from = WorkingTree.open_containing(u'.')[0]
547
553
aliases = ['get', 'clone']
549
555
def run(self, from_location, to_location=None, revision=None, basis=None):
551
from shutil import rmtree
552
556
if revision is None:
553
557
revision = [None]
554
558
elif len(revision) > 1:
565
569
br_from.lock_read()
567
571
if basis is not None:
568
basis_branch = WorkingTree.open_containing(basis)[0].branch
572
basis_dir = bzrdir.BzrDir.open_containing(basis)[0]
571
575
if len(revision) == 1 and revision[0] is not None:
572
576
revision_id = revision[0].in_history(br_from)[1]
578
# FIXME - wt.last_revision, fallback to branch, fall back to
579
# None or perhaps NULL_REVISION to mean copy nothing
581
revision_id = br_from.last_revision()
575
582
if to_location is None:
576
583
to_location = os.path.basename(from_location.rstrip("/\\"))
592
br_from.clone(to_location, revision_id, basis_branch)
599
dir = br_from.bzrdir.sprout(to_location, revision_id, basis_dir)
600
branch = dir.open_branch()
593
601
except bzrlib.errors.NoSuchRevision:
594
602
rmtree(to_location)
595
603
msg = "The branch %s has no revision %s." % (from_location, revision[0])
598
606
rmtree(to_location)
599
607
msg = "The branch %s cannot be used as a --basis"
600
608
raise BzrCommandError(msg)
601
branch = Branch.open(to_location)
603
610
branch.control_files.put_utf8('branch-name', name)
617
class cmd_checkout(Command):
618
"""Create a new checkout of an existing branch.
620
If the TO_LOCATION is omitted, the last component of the BRANCH_LOCATION will
621
be used. In other words, "checkout ../foo/bar" will attempt to create ./bar.
623
To retrieve the branch as of a particular revision, supply the --revision
624
parameter, as in "checkout foo/bar -r 5". Note that this will be immediately
625
out of date [so you cannot commit] but it may be useful (i.e. to examine old
628
--basis is to speed up checking out from remote branches. When specified, it
629
uses the inventory and file contents from the basis branch in preference to the
630
branch being checked out. [Not implemented yet.]
632
takes_args = ['branch_location', 'to_location?']
633
takes_options = ['revision'] # , 'basis']
635
def run(self, branch_location, to_location=None, revision=None, basis=None):
638
elif len(revision) > 1:
639
raise BzrCommandError(
640
'bzr checkout --revision takes exactly 1 revision value')
641
source = Branch.open(branch_location)
642
if len(revision) == 1 and revision[0] is not None:
643
revision_id = revision[0].in_history(source)[1]
646
if to_location is None:
647
to_location = os.path.basename(branch_location.rstrip("/\\"))
649
os.mkdir(to_location)
651
if e.errno == errno.EEXIST:
652
raise BzrCommandError('Target directory "%s" already'
653
' exists.' % to_location)
654
if e.errno == errno.ENOENT:
655
raise BzrCommandError('Parent of "%s" does not exist.' %
659
checkout = bzrdir.BzrDirMetaFormat1().initialize(to_location)
660
bzrlib.branch.BranchReferenceFormat().initialize(checkout, source)
661
checkout.create_workingtree(revision_id)
610
664
class cmd_renames(Command):
611
665
"""Show list of renamed files.
619
673
def run(self, dir=u'.'):
620
674
tree = WorkingTree.open_containing(dir)[0]
621
old_inv = tree.branch.basis_tree().inventory
675
old_inv = tree.basis_tree().inventory
622
676
new_inv = tree.read_working_inventory()
624
678
renames = list(bzrlib.tree.find_renames(old_inv, new_inv))
627
681
print "%s => %s" % (old_name, new_name)
684
class cmd_update(Command):
685
"""Update a tree to have the latest code committed to its branch.
687
This will perform a merge into the working tree, and may generate
688
conflicts. If you have any uncommitted changes, you will still
689
need to commit them after the update.
691
takes_args = ['dir?']
693
def run(self, dir='.'):
694
tree = WorkingTree.open_containing(dir)[0]
697
if tree.last_revision() == tree.branch.last_revision():
698
note("Tree is up to date.")
700
conflicts = tree.update()
701
note('Updated to revision %d.' %
702
(tree.branch.revision_id_to_revno(tree.last_revision()),))
630
711
class cmd_info(Command):
631
712
"""Show statistical information about a branch."""
632
713
takes_args = ['branch?']
635
716
def run(self, branch=None):
637
b = WorkingTree.open_containing(branch)[0].branch
718
bzrlib.info.show_bzrdir_info(bzrdir.BzrDir.open_containing(branch)[0])
641
721
class cmd_remove(Command):
821
901
def run(self, show_ids=False):
822
902
tree = WorkingTree.open_containing(u'.')[0]
823
old = tree.branch.basis_tree()
903
old = tree.basis_tree()
824
904
for path, ie in old.inventory.iter_entries():
825
905
if not tree.has_id(ie.file_id):
837
917
from bzrlib.delta import compare_trees
839
919
tree = WorkingTree.open_containing(u'.')[0]
840
td = compare_trees(tree.branch.basis_tree(), tree)
920
td = compare_trees(tree.basis_tree(), tree)
842
922
for path, id, kind, text_modified, meta_modified in td.modified:
912
994
"invalid message argument %r" % message
913
995
direction = (forward and 'forward') or 'reverse'
919
tree, fp = WorkingTree.open_containing(filename)
922
inv = tree.read_working_inventory()
923
except NotBranchError:
926
b, fp = Branch.open_containing(filename)
928
inv = b.repository.get_inventory(b.last_revision())
1000
# find the file id to log:
1002
dir, fp = bzrdir.BzrDir.open_containing(filename)
1003
b = dir.open_branch()
1007
inv = dir.open_workingtree().inventory
1008
except (errors.NotBranchError, errors.NotLocalUrl):
1009
# either no tree, or is remote.
1010
inv = b.basis_tree().inventory
930
1011
file_id = inv.path2id(fp)
932
file_id = None # points to branch root
934
tree, relpath = WorkingTree.open_containing(u'.')
1014
# FIXME ? log the current subdir only RBC 20060203
1015
dir, relpath = bzrdir.BzrDir.open_containing('.')
1016
b = dir.open_branch()
938
1018
if revision is None:
941
1021
elif len(revision) == 1:
942
1022
rev1 = rev2 = revision[0].in_history(b).revno
943
1023
elif len(revision) == 2:
944
rev1 = revision[0].in_history(b).revno
945
rev2 = revision[1].in_history(b).revno
1024
if revision[0].spec is None:
1025
# missing begin-range means first revision
1028
rev1 = revision[0].in_history(b).revno
1030
if revision[1].spec is None:
1031
# missing end-range means last known revision
1034
rev2 = revision[1].in_history(b).revno
947
1036
raise BzrCommandError('bzr log --revision takes one or two values.')
958
1047
# in e.g. the default C locale.
959
1048
outf = codecs.getwriter(bzrlib.user_encoding)(sys.stdout, errors='replace')
961
log_format = get_log_format(long=long, short=short, line=line)
1050
if (log_format == None):
1051
default = bzrlib.config.BranchConfig(b).log_format()
1052
log_format = get_log_format(long=long, short=short, line=line, default=default)
962
1054
lf = log_formatter(log_format,
963
1055
show_ids=show_ids,
1171
1264
Note: export of tree with non-ascii filenames to zip is not supported.
1173
Supported formats Autodetected by extension
1174
----------------- -------------------------
1266
Supported formats Autodetected by extension
1267
----------------- -------------------------
1177
1270
tbz2 .tar.bz2, .tbz2
1358
1451
if c.needs_write:
1455
def get_format_type(typestring):
1456
"""Parse and return a format specifier."""
1457
if typestring == "metadir":
1458
return bzrdir.BzrDirMetaFormat1
1459
msg = "No known bzr-dir format %s. Supported types are: metadir\n" %\
1461
raise BzrCommandError(msg)
1363
1464
class cmd_upgrade(Command):
1368
1469
during other operations to upgrade.
1370
1471
takes_args = ['url?']
1372
def run(self, url='.'):
1474
help='Upgrade to a specific format rather than the'
1475
' current default format. Currently this '
1476
' option only accepts =metadir',
1477
type=get_format_type),
1481
def run(self, url='.', format=None):
1373
1482
from bzrlib.upgrade import upgrade
1483
upgrade(url, format)
1377
1486
class cmd_whoami(Command):
1395
1504
class cmd_nick(Command):
1397
Print or set the branch nickname.
1505
"""Print or set the branch nickname.
1398
1507
If unset, the tree root directory name is used as the nickname
1399
1508
To print the current nickname, execute with no argument.
1556
1665
last1 = branch1.last_revision()
1557
1666
last2 = branch2.last_revision()
1559
source = MultipleRevisionSources(branch1, branch2)
1668
source = MultipleRevisionSources(branch1.repository,
1561
1671
base_rev_id = common_ancestor(last1, last2, source)
1694
1804
for name, ie in tree.inventory.iter_entries(file_id):
1695
1805
interesting_ids.add(ie.file_id)
1696
transform_tree(tree, tree.branch.basis_tree(), interesting_ids)
1806
transform_tree(tree, tree.basis_tree(), interesting_ids)
1697
1807
if file_list is None:
1698
1808
restore_files = list(tree.iter_conflicts())
1818
1929
def run(self, other_branch=None, reverse=False, mine_only=False,
1819
theirs_only=False, long=True, short=False, line=False,
1930
theirs_only=False, log_format=None, long=False, short=False, line=False,
1820
1931
show_ids=False, verbose=False):
1821
1932
from bzrlib.missing import find_unmerged, iter_log_data
1822
1933
from bzrlib.log import log_formatter
1829
1940
print "Using last location: " + local_branch.get_parent()
1830
1941
remote_branch = bzrlib.branch.Branch.open(other_branch)
1831
1942
local_extra, remote_extra = find_unmerged(local_branch, remote_branch)
1832
log_format = get_log_format(long=long, short=short, line=line)
1943
if (log_format == None):
1944
default = bzrlib.config.BranchConfig(local_branch).log_format()
1945
log_format = get_log_format(long=long, short=short, line=line, default=default)
1833
1946
lf = log_formatter(log_format, sys.stdout,
1834
1947
show_ids=show_ids,
1835
1948
show_timezone='original')
1943
2056
# TODO be able to replace existing ones.
1945
2058
hidden = True # is this right ?
1946
takes_args = ['revision_id?']
2059
takes_args = ['revision_id*']
1947
2060
takes_options = ['revision']
1949
def run(self, revision_id=None, revision=None):
2062
def run(self, revision_id_list=None, revision=None):
1950
2063
import bzrlib.config as config
1951
2064
import bzrlib.gpg as gpg
1952
if revision_id is not None and revision is not None:
2065
if revision_id_list is not None and revision is not None:
1953
2066
raise BzrCommandError('You can only supply one of revision_id or --revision')
1954
if revision_id is None and revision is None:
2067
if revision_id_list is None and revision is None:
1955
2068
raise BzrCommandError('You must supply either --revision or a revision_id')
1956
2069
b = WorkingTree.open_containing(u'.')[0].branch
1957
2070
gpg_strategy = gpg.GPGStrategy(config.BranchConfig(b))
1958
if revision_id is not None:
1959
b.repository.sign_revision(revision_id, gpg_strategy)
2071
if revision_id_list is not None:
2072
for revision_id in revision_id_list:
2073
b.repository.sign_revision(revision_id, gpg_strategy)
1960
2074
elif revision is not None:
1961
2075
if len(revision) == 1:
1962
2076
revno, rev_id = revision[0].in_history(b)