52
52
raise BzrCommandError("%s is not in the same branch as %s" %
53
53
(e.path, file_list[0]))
56
# XXX: Bad function name; should possibly also be a class method of
57
# WorkingTree rather than a function.
55
58
def internal_tree_files(file_list, default_branch=u'.'):
57
Return a branch and list of branch-relative paths.
58
If supplied file_list is empty or None, the branch default will be used,
59
and returned file_list will match the original.
59
"""Convert command-line paths to a WorkingTree and relative paths.
61
This is typically used for command-line processors that take one or
62
more filenames, and infer the workingtree that contains them.
64
The filenames given are not required to exist.
66
:param file_list: Filenames to convert.
68
:param default_branch: Fallback tree path to use if file_list is empty or None.
70
:return: workingtree, [relative_paths]
61
72
if file_list is None or len(file_list) == 0:
62
73
return WorkingTree.open_containing(default_branch)[0], file_list
73
84
def get_format_type(typestring):
74
85
"""Parse and return a format specifier."""
86
if typestring == "weave":
87
return bzrdir.BzrDirFormat6()
75
88
if typestring == "metadir":
76
89
return bzrdir.BzrDirMetaFormat1()
77
90
if typestring == "knit":
78
91
format = bzrdir.BzrDirMetaFormat1()
79
92
format.repository_format = bzrlib.repository.RepositoryFormatKnit1()
81
msg = "No known bzr-dir format %s. Supported types are: metadir\n" %\
94
msg = "No known bzr-dir format %s. Supported types are: weave, metadir\n" %\
83
96
raise BzrCommandError(msg)
329
class cmd_move(Command):
330
"""Move files to a different directory.
335
The destination must be a versioned directory in the same branch.
337
takes_args = ['source$', 'dest']
338
def run(self, source_list, dest):
339
tree, source_list = tree_files(source_list)
340
# TODO: glob expansion on windows?
341
tree.move(source_list, tree.relpath(dest))
344
class cmd_rename(Command):
345
"""Change the name of an entry.
348
bzr rename frob.c frobber.c
349
bzr rename src/frob.c lib/frob.c
351
It is an error if the destination name exists.
353
See also the 'move' command, which moves files into a different
354
directory without changing their name.
356
# TODO: Some way to rename multiple files without invoking
357
# bzr for each one?"""
358
takes_args = ['from_name', 'to_name']
360
def run(self, from_name, to_name):
361
tree, (from_name, to_name) = tree_files((from_name, to_name))
362
tree.rename_one(from_name, to_name)
365
342
class cmd_mv(Command):
366
343
"""Move or rename a file.
396
375
class cmd_pull(Command):
397
"""Pull any changes from another branch into the current one.
376
"""Turn this branch into a mirror of another branch.
378
This command only works on branches that have not diverged. Branches are
379
considered diverged if the destination branch's most recent commit is one
380
that has not been merged (directly or indirectly) into the parent.
382
If branches have diverged, you can use 'bzr merge' to integrate the changes
383
from one into the other. Once one branch has merged, the other should
384
be able to pull it again.
386
If branches have diverged, you can use 'bzr merge' to pull the text changes
387
from one into the other. Once one branch has merged, the other should
388
be able to pull it again.
390
If you want to forget your local changes and just update your branch to
391
match the remote one, use pull --overwrite.
399
393
If there is no default location set, the first pull will set it. After
400
394
that, you can omit the location to use the default. To change the
401
395
default, use --remember.
403
This command only works on branches that have not diverged. Branches are
404
considered diverged if both branches have had commits without first
405
pulling from the other.
407
If branches have diverged, you can use 'bzr merge' to pull the text changes
408
from one into the other. Once one branch has merged, the other should
409
be able to pull it again.
411
If you want to forget your local changes and just update your branch to
412
match the remote one, use --overwrite.
414
397
takes_options = ['remember', 'overwrite', 'revision', 'verbose']
415
398
takes_args = ['location?']
417
400
def run(self, location=None, remember=False, overwrite=False, revision=None, verbose=False):
418
# FIXME: too much stuff is in the command class
419
tree_to = WorkingTree.open_containing(u'.')[0]
420
stored_loc = tree_to.branch.get_parent()
401
# FIXME: too much stuff is in the command class
403
tree_to = WorkingTree.open_containing(u'.')[0]
404
branch_to = tree_to.branch
405
except NoWorkingTree:
407
branch_to = Branch.open_containing(u'.')[0]
408
stored_loc = branch_to.get_parent()
421
409
if location is None:
422
410
if stored_loc is None:
423
411
raise BzrCommandError("No pull location known or specified.")
425
413
print "Using saved location: %s" % stored_loc
426
414
location = stored_loc
428
br_from = Branch.open(location)
429
br_to = tree_to.branch
416
if branch_to.get_parent() is None or remember:
417
branch_to.set_parent(location)
419
branch_from = Branch.open(location)
431
421
if revision is None:
433
423
elif len(revision) == 1:
434
rev_id = revision[0].in_history(br_from).rev_id
424
rev_id = revision[0].in_history(branch_from).rev_id
436
426
raise BzrCommandError('bzr pull --revision takes one value.')
438
old_rh = br_to.revision_history()
439
count = tree_to.pull(br_from, overwrite, rev_id)
441
if br_to.get_parent() is None or remember:
442
br_to.set_parent(location)
428
old_rh = branch_to.revision_history()
429
if tree_to is not None:
430
count = tree_to.pull(branch_from, overwrite, rev_id)
432
count = branch_to.pull(branch_from, overwrite, rev_id)
443
433
note('%d revision(s) pulled.' % (count,))
446
new_rh = tree_to.branch.revision_history()
436
new_rh = branch_to.revision_history()
447
437
if old_rh != new_rh:
448
438
# Something changed
449
439
from bzrlib.log import show_changed_revisions
450
show_changed_revisions(tree_to.branch, old_rh, new_rh)
440
show_changed_revisions(branch_to, old_rh, new_rh)
453
443
class cmd_push(Command):
454
"""Push this branch into another branch.
456
The remote branch will not have its working tree populated because this
457
is both expensive, and may not be supported on the remote file system.
459
Some smart servers or protocols *may* put the working tree in place.
444
"""Update a mirror of this branch.
446
The target branch will not have its working tree populated because this
447
is both expensive, and is not supported on remote file systems.
449
Some smart servers or protocols *may* put the working tree in place in
452
This command only works on branches that have not diverged. Branches are
453
considered diverged if the destination branch's most recent commit is one
454
that has not been merged (directly or indirectly) by the source branch.
456
If branches have diverged, you can use 'bzr push --overwrite' to replace
457
the other branch completely, discarding its unmerged changes.
459
If you want to ensure you have the different changes in the other branch,
460
do a merge (see bzr help merge) from the other branch, and commit that.
461
After that you will be able to do a push without '--overwrite'.
461
463
If there is no default push location set, the first push will set it.
462
464
After that, you can omit the location to use the default. To change the
463
465
default, use --remember.
465
This command only works on branches that have not diverged. Branches are
466
considered diverged if the branch being pushed to is not an older version
469
If branches have diverged, you can use 'bzr push --overwrite' to replace
470
the other branch completely.
472
If you want to ensure you have the different changes in the other branch,
473
do a merge (see bzr help merge) from the other branch, and commit that
474
before doing a 'push --overwrite'.
476
467
takes_options = ['remember', 'overwrite',
477
468
Option('create-prefix',
531
524
# TODO: This should be updated for branches which don't have a
532
525
# working tree, as opposed to ones where we just couldn't
533
526
# update the tree.
534
warning('Unable to update the working tree of: %s' % (br_to.base,))
527
warning('This transport does not update the working '
528
'tree of: %s' % (br_to.base,))
535
529
count = br_to.pull(br_from, overwrite)
536
530
except NoWorkingTree:
537
531
count = br_to.pull(br_from, overwrite)
635
627
class cmd_checkout(Command):
636
628
"""Create a new checkout of an existing branch.
630
If BRANCH_LOCATION is omitted, checkout will reconstitute a working tree for
631
the branch found in '.'. This is useful if you have removed the working tree
632
or if it was never created - i.e. if you pushed the branch to its current
638
635
If the TO_LOCATION is omitted, the last component of the BRANCH_LOCATION will
639
636
be used. In other words, "checkout ../foo/bar" will attempt to create ./bar.
661
def run(self, branch_location, to_location=None, revision=None, basis=None,
658
def run(self, branch_location=None, to_location=None, revision=None, basis=None,
662
659
lightweight=False):
663
660
if revision is None:
664
661
revision = [None]
665
662
elif len(revision) > 1:
666
663
raise BzrCommandError(
667
664
'bzr checkout --revision takes exactly 1 revision value')
665
if branch_location is None:
666
branch_location = bzrlib.osutils.getcwd()
667
to_location = branch_location
668
668
source = Branch.open(branch_location)
669
669
if len(revision) == 1 and revision[0] is not None:
670
670
revision_id = revision[0].in_history(source)[1]
672
672
revision_id = None
673
673
if to_location is None:
674
674
to_location = os.path.basename(branch_location.rstrip("/\\"))
675
# if the source and to_location are the same,
676
# and there is no working tree,
677
# then reconstitute a branch
678
if (bzrlib.osutils.abspath(to_location) ==
679
bzrlib.osutils.abspath(branch_location)):
681
source.bzrdir.open_workingtree()
682
except errors.NoWorkingTree:
683
source.bzrdir.create_workingtree()
676
686
os.mkdir(to_location)
677
687
except OSError, e:
758
768
class cmd_info(Command):
759
769
"""Show statistical information about a branch."""
760
770
takes_args = ['branch?']
771
takes_options = ['verbose']
763
def run(self, branch=None):
774
def run(self, branch=None, verbose=False):
764
775
import bzrlib.info
765
bzrlib.info.show_bzrdir_info(bzrdir.BzrDir.open_containing(branch)[0])
776
bzrlib.info.show_bzrdir_info(bzrdir.BzrDir.open_containing(branch)[0],
768
780
class cmd_remove(Command):
871
883
Use this to create an empty branch, or before importing an
872
884
existing project.
886
If there is a repository in a parent directory of the location, then
887
the history of the branch will be stored in the repository. Otherwise
888
init creates a standalone branch which carries its own history in
891
If there is already a branch at the location but it has no working tree,
892
the tree can be populated with 'bzr checkout'.
874
894
Recipe for importing a tree of files:
898
918
# locations if the user supplies an extended path
899
919
if not os.path.exists(location):
900
920
os.mkdir(location)
922
existing_bzrdir = bzrdir.BzrDir.open(location)
923
except NotBranchError:
924
# really a NotBzrDir error...
925
bzrdir.BzrDir.create_branch_convenience(location, format=format)
927
if existing_bzrdir.has_branch():
928
if existing_bzrdir.has_workingtree():
929
raise errors.AlreadyBranchError(location)
931
raise errors.BranchExistsWithoutWorkingTree(location)
933
existing_bzrdir.create_branch()
934
existing_bzrdir.create_workingtree()
937
class cmd_init_repository(Command):
938
"""Create a shared repository to hold branches.
940
New branches created under the repository directory will store their revisions
941
in the repository, not in the branch directory, if the branch format supports
947
bzr checkout --lightweight repo/trunk trunk-checkout
951
takes_args = ["location"]
952
takes_options = [Option('format',
953
help='Use a specific format rather than the'
954
' current default format. Currently this'
955
' option accepts "weave", "metadir" and "knit"',
956
type=get_format_type),
958
help='Allows branches in repository to have'
960
aliases = ["init-repo"]
961
def run(self, location, format=None, trees=False):
962
from bzrlib.bzrdir import BzrDirMetaFormat1
963
from bzrlib.transport import get_transport
901
964
if format is None:
903
bzrdir.BzrDir.create_standalone_workingtree(location)
905
new_dir = format.initialize(location)
906
new_dir.create_repository()
907
new_dir.create_branch()
908
# TODO: ask the bzrdir format for the right classs
909
import bzrlib.workingtree
910
bzrlib.workingtree.WorkingTreeFormat3().initialize(new_dir)
965
format = BzrDirMetaFormat1()
966
transport = get_transport(location)
967
if not transport.has('.'):
969
newdir = format.initialize_on_transport(transport)
970
repo = newdir.create_repository(shared=True)
971
repo.set_make_working_trees(trees)
913
974
class cmd_diff(Command):
1047
1108
class cmd_log(Command):
1048
"""Show log of this branch.
1109
"""Show log of a branch, file, or directory.
1111
By default show the log of the branch containing the working directory.
1050
1113
To request a range of logs, you can use the command -r begin..end
1051
1114
-r revision requests a specific revision, -r ..end or -r begin.. are
1120
bzr log -r -10.. http://server/branch
1055
1123
# TODO: Make --revision support uuid: and hash: [future tag:] notation.
1057
takes_args = ['filename?']
1125
takes_args = ['location?']
1058
1126
takes_options = [Option('forward',
1059
1127
help='show from oldest to newest'),
1060
'timezone', 'verbose',
1130
help='show files changed in each revision'),
1061
1131
'show-ids', 'revision',
1063
1133
'line', 'long',
1460
1530
def run(self, message=None, file=None, verbose=True, selected_list=None,
1461
1531
unchanged=False, strict=False, local=False):
1532
from bzrlib.commit import (NullCommitReporter, ReportCommitToLog)
1462
1533
from bzrlib.errors import (PointlessCommit, ConflictsInTree,
1463
1534
StrictCommitFailed)
1464
1535
from bzrlib.msgeditor import edit_commit_message, \
1493
1564
if message == "":
1494
1565
raise BzrCommandError("empty commit message specified")
1568
reporter = ReportCommitToLog()
1570
reporter = NullCommitReporter()
1497
1573
tree.commit(message, specific_files=selected_list,
1498
allow_pointless=unchanged, strict=strict, local=local)
1574
allow_pointless=unchanged, strict=strict, local=local,
1499
1576
except PointlessCommit:
1500
1577
# FIXME: This should really happen before the file is read in;
1501
1578
# perhaps prepare the commit; get the message; then actually commit
1812
1895
--force is given.
1814
1897
takes_args = ['branch?']
1815
takes_options = ['revision', 'force', 'merge-type', 'reprocess',
1898
takes_options = ['revision', 'force', 'merge-type', 'reprocess', 'remember',
1816
1899
Option('show-base', help="Show base revision text in "
1819
1902
def run(self, branch=None, revision=None, force=False, merge_type=None,
1820
show_base=False, reprocess=False):
1903
show_base=False, reprocess=False, remember=False):
1821
1904
if merge_type is None:
1822
1905
merge_type = Merge3Merger
1907
tree = WorkingTree.open_containing(u'.')[0]
1908
stored_loc = tree.branch.get_parent()
1823
1909
if branch is None:
1824
branch = WorkingTree.open_containing(u'.')[0].branch.get_parent()
1826
raise BzrCommandError("No merge location known or specified.")
1910
if stored_loc is None:
1911
raise BzrCommandError("No merge branch known or specified.")
1828
print "Using saved location: %s" % branch
1913
print "Using saved branch: %s" % stored_loc
1916
if tree.branch.get_parent() is None or remember:
1917
tree.branch.set_parent(branch)
1829
1919
if revision is None or len(revision) < 1:
1830
1920
base = [None, None]
1831
1921
other = [branch, -1]
1922
other_branch, path = Branch.open_containing(branch)
1833
1924
if len(revision) == 1:
1834
1925
base = [None, None]
1835
other_branch = Branch.open_containing(branch)[0]
1926
other_branch, path = Branch.open_containing(branch)
1836
1927
revno = revision[0].in_history(other_branch).revno
1837
1928
other = [branch, revno]
2379
2479
if show_base and not merge_type is Merge3Merger:
2380
2480
raise BzrCommandError("Show-base is not supported for this merge"
2381
2481
" type. %s" % merge_type)
2382
if reprocess and not merge_type is Merge3Merger:
2383
raise BzrCommandError("Reprocess is not supported for this merge"
2384
" type. %s" % merge_type)
2482
if reprocess and not merge_type.supports_reprocess:
2483
raise BzrCommandError("Conflict reduction is not supported for merge"
2484
" type %s." % merge_type)
2385
2485
if reprocess and show_base:
2386
raise BzrCommandError("Cannot reprocess and show base.")
2486
raise BzrCommandError("Cannot do conflict reduction and show base.")
2388
2488
merger = Merger(this_tree.branch, this_tree=this_tree, pb=pb)
2389
2489
merger.pp = ProgressPhase("Merge phase", 5, pb)
2410
2511
# these get imported and then picked up by the scan for cmd_*
2411
2512
# TODO: Some more consistent way to split command definitions across files;
2412
2513
# we do need to load at least some information about them to know of
2514
# aliases. ideally we would avoid loading the implementation until the
2515
# details were needed.
2414
2516
from bzrlib.conflicts import cmd_resolve, cmd_conflicts, restore
2415
2517
from bzrlib.sign_my_commits import cmd_sign_my_commits
2518
from bzrlib.weave_commands import cmd_weave_list, cmd_weave_join, \
2519
cmd_weave_plan_merge, cmd_weave_merge_text