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)
362
375
class cmd_pull(Command):
363
"""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.
365
393
If there is no default location set, the first pull will set it. After
366
394
that, you can omit the location to use the default. To change the
367
395
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
397
takes_options = ['remember', 'overwrite', 'revision', 'verbose']
381
398
takes_args = ['location?']
396
413
print "Using saved location: %s" % stored_loc
397
414
location = stored_loc
399
br_from = Branch.open(location)
416
if branch_to.get_parent() is None or remember:
417
branch_to.set_parent(location)
419
branch_from = Branch.open(location)
401
421
if revision is None:
403
423
elif len(revision) == 1:
404
rev_id = revision[0].in_history(br_from).rev_id
424
rev_id = revision[0].in_history(branch_from).rev_id
406
426
raise BzrCommandError('bzr pull --revision takes one value.')
408
428
old_rh = branch_to.revision_history()
409
429
if tree_to is not None:
410
count = tree_to.pull(br_from, overwrite, rev_id)
430
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)
432
count = branch_to.pull(branch_from, overwrite, rev_id)
416
433
note('%d revision(s) pulled.' % (count,))
426
443
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.
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'.
434
463
If there is no default push location set, the first push will set it.
435
464
After that, you can omit the location to use the default. To change the
436
465
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
467
takes_options = ['remember', 'overwrite',
450
468
Option('create-prefix',
468
486
print "Using saved location: %s" % stored_loc
469
487
location = stored_loc
488
if br_from.get_push_location() is None or remember:
489
br_from.set_push_location(location)
471
491
dir_to = bzrlib.bzrdir.BzrDir.open(location)
472
492
br_to = dir_to.open_branch()
514
534
except DivergedBranches:
515
535
raise BzrCommandError("These branches have diverged."
516
536
" 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
537
note('%d revision(s) pushed.' % (count,))
892
910
# locations if the user supplies an extended path
893
911
if not os.path.exists(location):
894
912
os.mkdir(location)
895
bzrdir.BzrDir.create_branch_convenience(location, format=format)
914
existing = bzrdir.BzrDir.open(location)
915
except NotBranchError:
916
bzrdir.BzrDir.create_branch_convenience(location, format=format)
919
existing.open_branch()
920
except NotBranchError:
921
existing.create_branch()
922
existing.create_workingtree()
924
raise errors.AlreadyBranchError(location)
898
927
class cmd_init_repository(Command):
899
"""Create a shared repository to keep branches in."""
928
"""Create a shared repository to hold branches.
930
New branches created under the repository directory will store their revisions
931
in the repository, not in the branch directory, if the branch format supports
936
bzr init --format=metadir repo/trunk
900
940
takes_args = ["location"]
901
941
takes_options = [Option('format',
902
942
help='Use a specific format rather than the'
914
954
from bzrlib.transport import get_transport
915
955
if format is None:
916
956
format = BzrDirMetaFormat1()
917
get_transport(location).mkdir('')
918
newdir = format.initialize(location)
957
transport = get_transport(location)
958
if not transport.has('.'):
960
newdir = format.initialize_on_transport(transport)
919
961
repo = newdir.create_repository(shared=True)
920
962
repo.set_make_working_trees(trees)
1827
1869
Use bzr resolve when you have fixed a problem. See also bzr conflicts.
1871
If there is no default branch set, the first merge will set it. After
1872
that, you can omit the branch to use the default. To change the
1873
default, use --remember.
1831
1877
To merge the latest revision from bzr.dev
1841
1887
--force is given.
1843
1889
takes_args = ['branch?']
1844
takes_options = ['revision', 'force', 'merge-type', 'reprocess',
1890
takes_options = ['revision', 'force', 'merge-type', 'reprocess', 'remember',
1845
1891
Option('show-base', help="Show base revision text in "
1848
1894
def run(self, branch=None, revision=None, force=False, merge_type=None,
1849
show_base=False, reprocess=False):
1895
show_base=False, reprocess=False, remember=False):
1850
1896
if merge_type is None:
1851
1897
merge_type = Merge3Merger
1899
tree = WorkingTree.open_containing(u'.')[0]
1900
stored_loc = tree.branch.get_parent()
1852
1901
if branch is None:
1853
branch = WorkingTree.open_containing(u'.')[0].branch.get_parent()
1855
raise BzrCommandError("No merge location known or specified.")
1902
if stored_loc is None:
1903
raise BzrCommandError("No merge branch known or specified.")
1857
print "Using saved location: %s" % branch
1905
print "Using saved branch: %s" % stored_loc
1908
if tree.branch.get_parent() is None or remember:
1909
tree.branch.set_parent(branch)
1858
1911
if revision is None or len(revision) < 1:
1859
1912
base = [None, None]
1860
1913
other = [branch, -1]
2412
2465
if show_base and not merge_type is Merge3Merger:
2413
2466
raise BzrCommandError("Show-base is not supported for this merge"
2414
2467
" type. %s" % merge_type)
2415
if reprocess and not merge_type is Merge3Merger:
2416
raise BzrCommandError("Reprocess is not supported for this merge"
2417
" type. %s" % merge_type)
2468
if reprocess and not merge_type.supports_reprocess:
2469
raise BzrCommandError("Conflict reduction is not supported for merge"
2470
" type %s." % merge_type)
2418
2471
if reprocess and show_base:
2419
raise BzrCommandError("Cannot reprocess and show base.")
2472
raise BzrCommandError("Cannot do conflict reduction and show base.")
2421
2474
merger = Merger(this_tree.branch, this_tree=this_tree, pb=pb)
2422
2475
merger.pp = ProgressPhase("Merge phase", 5, pb)