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
362
373
class cmd_pull(Command):
363
"""Pull any changes from another branch into the current one.
374
"""Turn this branch into a mirror of another branch.
376
This command only works on branches that have not diverged. Branches are
377
considered diverged if the destination branch's most recent commit is one
378
that has not been merged (directly or indirectly) into the parent.
380
If branches have diverged, you can use 'bzr merge' to integrate the changes
381
from one into the other. Once one branch has merged, the other should
382
be able to pull it again.
384
If branches have diverged, you can use 'bzr merge' to pull the text changes
385
from one into the other. Once one branch has merged, the other should
386
be able to pull it again.
388
If you want to forget your local changes and just update your branch to
389
match the remote one, use pull --overwrite.
365
391
If there is no default location set, the first pull will set it. After
366
392
that, you can omit the location to use the default. To change the
367
393
default, use --remember.
369
This command only works on branches that have not diverged. Branches are
370
considered diverged if both branches have had commits without first
371
pulling from the other.
373
If branches have diverged, you can use 'bzr merge' to pull the text changes
374
from one into the other. Once one branch has merged, the other should
375
be able to pull it again.
377
If you want to forget your local changes and just update your branch to
378
match the remote one, use --overwrite.
380
395
takes_options = ['remember', 'overwrite', 'revision', 'verbose']
381
396
takes_args = ['location?']
396
411
print "Using saved location: %s" % stored_loc
397
412
location = stored_loc
399
br_from = Branch.open(location)
414
if branch_to.get_parent() is None or remember:
415
branch_to.set_parent(location)
417
branch_from = Branch.open(location)
401
419
if revision is None:
403
421
elif len(revision) == 1:
404
rev_id = revision[0].in_history(br_from).rev_id
422
rev_id = revision[0].in_history(branch_from).rev_id
406
424
raise BzrCommandError('bzr pull --revision takes one value.')
408
426
old_rh = branch_to.revision_history()
409
427
if tree_to is not None:
410
count = tree_to.pull(br_from, overwrite, rev_id)
428
count = tree_to.pull(branch_from, overwrite, rev_id)
412
count = branch_to.pull(br_from, overwrite, rev_id)
414
if branch_to.get_parent() is None or remember:
415
branch_to.set_parent(location)
430
count = branch_to.pull(branch_from, overwrite, rev_id)
416
431
note('%d revision(s) pulled.' % (count,))
426
441
class cmd_push(Command):
427
"""Push this branch into another branch.
429
The remote branch will not have its working tree populated because this
430
is both expensive, and may not be supported on the remote file system.
432
Some smart servers or protocols *may* put the working tree in place.
442
"""Update a mirror of this branch.
444
The target branch will not have its working tree populated because this
445
is both expensive, and is not supported on remote file systems.
447
Some smart servers or protocols *may* put the working tree in place in
450
This command only works on branches that have not diverged. Branches are
451
considered diverged if the destination branch's most recent commit is one
452
that has not been merged (directly or indirectly) by the source branch.
454
If branches have diverged, you can use 'bzr push --overwrite' to replace
455
the other branch completely, discarding its unmerged changes.
457
If you want to ensure you have the different changes in the other branch,
458
do a merge (see bzr help merge) from the other branch, and commit that.
459
After that you will be able to do a push without '--overwrite'.
434
461
If there is no default push location set, the first push will set it.
435
462
After that, you can omit the location to use the default. To change the
436
463
default, use --remember.
438
This command only works on branches that have not diverged. Branches are
439
considered diverged if the branch being pushed to is not an older version
442
If branches have diverged, you can use 'bzr push --overwrite' to replace
443
the other branch completely.
445
If you want to ensure you have the different changes in the other branch,
446
do a merge (see bzr help merge) from the other branch, and commit that
447
before doing a 'push --overwrite'.
449
465
takes_options = ['remember', 'overwrite',
450
466
Option('create-prefix',
468
484
print "Using saved location: %s" % stored_loc
469
485
location = stored_loc
486
if br_from.get_push_location() is None or remember:
487
br_from.set_push_location(location)
471
489
dir_to = bzrlib.bzrdir.BzrDir.open(location)
472
490
br_to = dir_to.open_branch()
514
532
except DivergedBranches:
515
533
raise BzrCommandError("These branches have diverged."
516
534
" Try a merge then push with overwrite.")
517
if br_from.get_push_location() is None or remember:
518
br_from.set_push_location(location)
519
535
note('%d revision(s) pushed.' % (count,))
750
766
class cmd_info(Command):
751
767
"""Show statistical information about a branch."""
752
768
takes_args = ['branch?']
769
takes_options = ['verbose']
755
def run(self, branch=None):
772
def run(self, branch=None, verbose=False):
756
773
import bzrlib.info
757
bzrlib.info.show_bzrdir_info(bzrdir.BzrDir.open_containing(branch)[0])
774
bzrlib.info.show_bzrdir_info(bzrdir.BzrDir.open_containing(branch)[0],
760
778
class cmd_remove(Command):
876
894
help='Create a specific format rather than the'
877
895
' current default format. Currently this '
878
' option only accepts =metadir',
896
' option only accepts "metadir"',
879
897
type=get_format_type),
881
899
def run(self, location=None, format=None):
890
908
# locations if the user supplies an extended path
891
909
if not os.path.exists(location):
892
910
os.mkdir(location)
893
bzrdir.BzrDir.create_branch_convenience(location, format=format)
912
existing = bzrdir.BzrDir.open(location)
913
except NotBranchError:
914
bzrdir.BzrDir.create_branch_convenience(location, format=format)
917
existing.open_branch()
918
except NotBranchError:
919
existing.create_branch()
920
existing.create_workingtree()
922
raise errors.AlreadyBranchError(location)
896
925
class cmd_init_repository(Command):
897
"""Create a shared repository to keep branches in."""
926
"""Create a shared repository to hold branches.
928
New branches created under the repository directory will store their revisions
929
in the repository, not in the branch directory, if the branch format supports
934
bzr init --format=metadir repo/trunk
898
938
takes_args = ["location"]
899
939
takes_options = [Option('format',
900
940
help='Use a specific format rather than the'
912
952
from bzrlib.transport import get_transport
913
953
if format is None:
914
954
format = BzrDirMetaFormat1()
915
get_transport(location).mkdir('')
916
newdir = format.initialize(location)
955
transport = get_transport(location)
956
if not transport.has('.'):
958
newdir = format.initialize_on_transport(transport)
917
959
repo = newdir.create_repository(shared=True)
918
960
repo.set_make_working_trees(trees)
1587
1629
Option('format',
1588
1630
help='Upgrade to a specific format rather than the'
1589
1631
' current default format. Currently this'
1590
' option only accepts -metadir and -knit'
1632
' option only accepts "metadir" and "knit".'
1591
1633
' WARNING: the knit format is currently'
1592
1634
' unstable and only for experimental use.',
1593
1635
type=get_format_type),
1825
1867
Use bzr resolve when you have fixed a problem. See also bzr conflicts.
1869
If there is no default branch set, the first merge will set it. After
1870
that, you can omit the branch to use the default. To change the
1871
default, use --remember.
1829
1875
To merge the latest revision from bzr.dev
1839
1885
--force is given.
1841
1887
takes_args = ['branch?']
1842
takes_options = ['revision', 'force', 'merge-type', 'reprocess',
1888
takes_options = ['revision', 'force', 'merge-type', 'reprocess', 'remember',
1843
1889
Option('show-base', help="Show base revision text in "
1846
1892
def run(self, branch=None, revision=None, force=False, merge_type=None,
1847
show_base=False, reprocess=False):
1893
show_base=False, reprocess=False, remember=False):
1848
1894
if merge_type is None:
1849
1895
merge_type = Merge3Merger
1897
tree = WorkingTree.open_containing(u'.')[0]
1898
stored_loc = tree.branch.get_parent()
1850
1899
if branch is None:
1851
branch = WorkingTree.open_containing(u'.')[0].branch.get_parent()
1853
raise BzrCommandError("No merge location known or specified.")
1900
if stored_loc is None:
1901
raise BzrCommandError("No merge branch known or specified.")
1855
print "Using saved location: %s" % branch
1903
print "Using saved branch: %s" % stored_loc
1906
if tree.branch.get_parent() is None or remember:
1907
tree.branch.set_parent(branch)
1856
1909
if revision is None or len(revision) < 1:
1857
1910
base = [None, None]
1858
1911
other = [branch, -1]
1912
other_branch, path = Branch.open_containing(branch)
1860
1914
if len(revision) == 1:
1861
1915
base = [None, None]
1862
other_branch = Branch.open_containing(branch)[0]
1916
other_branch, path = Branch.open_containing(branch)
1863
1917
revno = revision[0].in_history(other_branch).revno
1864
1918
other = [branch, revno]
1867
1921
if None in revision:
1868
1922
raise BzrCommandError(
1869
1923
"Merge doesn't permit that revision specifier.")
1870
b = Branch.open_containing(branch)[0]
1924
b, path = Branch.open_containing(branch)
1872
1926
base = [branch, revision[0].in_history(b).revno]
1873
1927
other = [branch, revision[1].in_history(b).revno]
1929
interesting_files = [path]
1931
interesting_files = None
1874
1932
pb = bzrlib.ui.ui_factory.nested_progress_bar()