745
559
location = stored_loc
747
561
to_transport = transport.get_transport(location)
562
location_url = to_transport.base
749
br_to = repository_to = dir_to = None
751
dir_to = bzrdir.BzrDir.open_from_transport(to_transport)
752
except errors.NotBranchError:
753
pass # Didn't find anything
755
# If we can open a branch, use its direct repository, otherwise see
756
# if there is a repository without a branch.
758
br_to = dir_to.open_branch()
759
except errors.NotBranchError:
760
# Didn't find a branch, can we find a repository?
566
dir_to = bzrdir.BzrDir.open(location_url)
567
br_to = dir_to.open_branch()
568
except NotBranchError:
570
to_transport = to_transport.clone('..')
571
if not create_prefix:
762
repository_to = dir_to.find_repository()
763
except errors.NoRepositoryPresent:
766
# Found a branch, so we must have found a repository
767
repository_to = br_to.repository
769
if revision is not None:
770
if len(revision) == 1:
771
revision_id = revision[0].in_history(br_from).rev_id
773
raise errors.BzrCommandError(
774
'bzr push --revision takes one value.')
776
revision_id = br_from.last_revision()
782
# The destination doesn't exist; create it.
783
# XXX: Refactor the create_prefix/no_create_prefix code into a
784
# common helper function
786
def make_directory(transport):
790
def redirected(redirected_transport, e, redirection_notice):
791
return transport.get_transport(e.get_target_url())
794
to_transport = transport.do_catching_redirections(
795
make_directory, to_transport, redirected)
796
except errors.FileExists:
797
if not use_existing_dir:
798
raise errors.BzrCommandError("Target directory %s"
799
" already exists, but does not have a valid .bzr"
800
" directory. Supply --use-existing-dir to push"
801
" there anyway." % location)
802
except errors.NoSuchFile:
803
if not create_prefix:
804
raise errors.BzrCommandError("Parent directory of %s"
806
"\nYou may supply --create-prefix to create all"
807
" leading parent directories."
809
_create_prefix(to_transport)
810
except errors.TooManyRedirections:
811
raise errors.BzrCommandError("Too many redirections trying "
812
"to make %s." % location)
814
# Now the target directory exists, but doesn't have a .bzr
815
# directory. So we need to create it, along with any work to create
816
# all of the dependent branches, etc.
817
dir_to = br_from.bzrdir.clone_on_transport(to_transport,
818
revision_id=revision_id)
573
relurl = to_transport.relpath(location_url)
574
mutter('creating directory %s => %s', location_url, relurl)
575
to_transport.mkdir(relurl)
577
raise BzrCommandError("Parent directory of %s "
578
"does not exist." % location)
580
current = to_transport.base
581
needed = [(to_transport, to_transport.relpath(location_url))]
584
to_transport, relpath = needed[-1]
585
to_transport.mkdir(relpath)
588
new_transport = to_transport.clone('..')
589
needed.append((new_transport,
590
new_transport.relpath(to_transport.base)))
591
if new_transport.base == to_transport.base:
592
raise BzrCommandError("Could not create "
594
dir_to = br_from.bzrdir.clone(location_url,
595
revision_id=br_from.last_revision())
819
596
br_to = dir_to.open_branch()
820
# TODO: Some more useful message about what was copied
821
note('Created new branch.')
597
count = len(br_to.revision_history())
822
598
# We successfully created the target, remember it
823
599
if br_from.get_push_location() is None or remember:
824
600
br_from.set_push_location(br_to.base)
825
elif repository_to is None:
826
# we have a bzrdir but no branch or repository
827
# XXX: Figure out what to do other than complain.
828
raise errors.BzrCommandError("At %s you have a valid .bzr control"
829
" directory, but not a branch or repository. This is an"
830
" unsupported configuration. Please move the target directory"
831
" out of the way and try again."
834
# We have a repository but no branch, copy the revisions, and then
836
repository_to.fetch(br_from.repository, revision_id=revision_id)
837
br_to = br_from.clone(dir_to, revision_id=revision_id)
838
note('Created new branch.')
839
if br_from.get_push_location() is None or remember:
840
br_from.set_push_location(br_to.base)
841
else: # We have a valid to branch
842
602
# We were able to connect to the remote location, so remember it
843
603
# we don't need to successfully push because of possible divergence.
844
604
if br_from.get_push_location() is None or remember:
845
605
br_from.set_push_location(br_to.base)
847
old_rh = br_to.revision_history()
606
old_rh = br_to.revision_history()
850
609
tree_to = dir_to.open_workingtree()
851
610
except errors.NotLocalUrl:
852
warning("This transport does not update the working "
853
"tree of: %s. See 'bzr help working-trees' for "
854
"more information." % br_to.base)
855
push_result = br_from.push(br_to, overwrite,
856
stop_revision=revision_id)
857
except errors.NoWorkingTree:
858
push_result = br_from.push(br_to, overwrite,
859
stop_revision=revision_id)
611
warning('This transport does not update the working '
612
'tree of: %s' % (br_to.base,))
613
count = br_to.pull(br_from, overwrite)
614
except NoWorkingTree:
615
count = br_to.pull(br_from, overwrite)
863
push_result = br_from.push(tree_to.branch, overwrite,
864
stop_revision=revision_id)
868
except errors.DivergedBranches:
869
raise errors.BzrCommandError('These branches have diverged.'
870
' Try using "merge" and then "push".')
871
if push_result is not None:
872
push_result.report(self.outf)
617
count = tree_to.pull(br_from, overwrite)
618
except DivergedBranches:
619
raise BzrCommandError("These branches have diverged."
620
" Try a merge then push with overwrite.")
621
note('%d revision(s) pushed.' % (count,))
874
624
new_rh = br_to.revision_history()
875
625
if old_rh != new_rh:
876
626
# Something changed
877
627
from bzrlib.log import show_changed_revisions
878
628
show_changed_revisions(br_to, old_rh, new_rh,
879
629
to_file=self.outf)
881
# we probably did a clone rather than a push, so a message was
886
632
class cmd_branch(Command):
1344
1045
# Just using os.mkdir, since I don't
1345
1046
# believe that we want to create a bunch of
1346
1047
# locations if the user supplies an extended path
1348
to_transport.ensure_base()
1349
except errors.NoSuchFile:
1350
if not create_prefix:
1351
raise errors.BzrCommandError("Parent directory of %s"
1353
"\nYou may supply --create-prefix to create all"
1354
" leading parent directories."
1356
_create_prefix(to_transport)
1359
existing_bzrdir = bzrdir.BzrDir.open_from_transport(to_transport)
1360
except errors.NotBranchError:
1048
# TODO: create-prefix
1050
to_transport.mkdir('.')
1051
except errors.FileExists:
1055
existing_bzrdir = bzrdir.BzrDir.open(location)
1056
except NotBranchError:
1361
1057
# really a NotBzrDir error...
1362
create_branch = bzrdir.BzrDir.create_branch_convenience
1363
branch = create_branch(to_transport.base, format=format,
1364
possible_transports=[to_transport])
1058
bzrdir.BzrDir.create_branch_convenience(location, format=format)
1366
from bzrlib.transport.local import LocalTransport
1367
1060
if existing_bzrdir.has_branch():
1368
1061
if (isinstance(to_transport, LocalTransport)
1369
1062
and not existing_bzrdir.has_workingtree()):
1370
1063
raise errors.BranchExistsWithoutWorkingTree(location)
1371
1064
raise errors.AlreadyBranchError(location)
1373
branch = existing_bzrdir.create_branch()
1066
existing_bzrdir.create_branch()
1374
1067
existing_bzrdir.create_workingtree()
1375
if append_revisions_only:
1377
branch.set_append_revisions_only(True)
1378
except errors.UpgradeRequired:
1379
raise errors.BzrCommandError('This branch format cannot be set'
1380
' to append-revisions-only. Try --experimental-branch6')
1383
1070
class cmd_init_repository(Command):
1384
1071
"""Create a shared repository to hold branches.
1386
New branches created under the repository directory will store their
1387
revisions in the repository, not in the branch directory.
1389
If the --no-trees option is used then the branches in the repository
1390
will not have working trees by default.
1393
Create a shared repositories holding just branches::
1395
bzr init-repo --no-trees repo
1398
Make a lightweight checkout elsewhere::
1400
bzr checkout --lightweight repo/trunk trunk-checkout
1073
New branches created under the repository directory will store their revisions
1074
in the repository, not in the branch directory, if the branch format supports
1080
bzr checkout --lightweight repo/trunk trunk-checkout
1405
_see_also = ['init', 'branch', 'checkout', 'repositories']
1406
takes_args = ["location"]
1407
takes_options = [RegistryOption('format',
1408
help='Specify a format for this repository. See'
1409
' "bzr help formats" for details.',
1410
registry=bzrdir.format_registry,
1411
converter=bzrdir.format_registry.make_bzrdir,
1412
value_switches=True, title='Repository format'),
1414
help='Branches in the repository will default to'
1415
' not having a working tree.'),
1084
takes_args = ["location"]
1085
takes_options = [Option('format',
1086
help='Specify a format for this repository.'
1087
' Current formats are: default, knit,'
1088
' metaweave and weave. Default is knit;'
1089
' metaweave and weave are deprecated',
1090
type=get_format_type),
1092
help='Allows branches in repository to have'
1417
1094
aliases = ["init-repo"]
1419
def run(self, location, format=None, no_trees=False):
1095
def run(self, location, format=None, trees=False):
1420
1096
if format is None:
1421
format = bzrdir.format_registry.make_bzrdir('default')
1097
format = get_format_type('default')
1423
1099
if location is None:
1426
1102
to_transport = transport.get_transport(location)
1427
to_transport.ensure_base()
1104
to_transport.mkdir('.')
1105
except errors.FileExists:
1429
1108
newdir = format.initialize_on_transport(to_transport)
1430
1109
repo = newdir.create_repository(shared=True)
1431
repo.set_make_working_trees(not no_trees)
1110
repo.set_make_working_trees(trees)
1434
1113
class cmd_diff(Command):
1435
"""Show differences in the working tree, between revisions or branches.
1114
"""Show differences in the working tree or between revisions.
1437
If no arguments are given, all changes for the current tree are listed.
1438
If files are given, only the changes in those files are listed.
1439
Remote and multiple branches can be compared by using the --old and
1440
--new options. If not provided, the default for both is derived from
1441
the first argument, if any, or the current tree if no arguments are
1116
If files are listed, only the changes in those files are listed.
1117
Otherwise, all changes for the tree are listed.
1444
1119
"bzr diff -p1" is equivalent to "bzr diff --prefix old/:new/", and
1445
1120
produces patches suitable for "patch -p1".
1449
2 - unrepresentable changes
1454
Shows the difference in the working tree versus the last commit::
1458
Difference between the working tree and revision 1::
1462
Difference between revision 2 and revision 1::
1466
Difference between revision 2 and revision 1 for branch xxx::
1470
Show just the differences for file NEWS::
1474
Show the differences in working tree xxx for file NEWS::
1478
Show the differences from branch xxx to this working tree:
1482
Show the differences between two branches for file NEWS::
1484
bzr diff --old xxx --new yyy NEWS
1486
Same as 'bzr diff' but prefix paths with old/ and new/::
1488
bzr diff --prefix old/:new/
1124
Shows the difference in the working tree versus the last commit
1126
Difference between the working tree and revision 1
1128
Difference between revision 2 and revision 1
1129
bzr diff --diff-prefix old/:new/
1130
Same as 'bzr diff' but prefix paths with old/ and new/
1131
bzr diff bzr.mine bzr.dev
1132
Show the differences between the two working trees
1134
Show just the differences for 'foo.c'
1490
_see_also = ['status']
1136
# TODO: Option to use external diff command; could be GNU diff, wdiff,
1137
# or a graphical diff.
1139
# TODO: Python difflib is not exactly the same as unidiff; should
1140
# either fix it up or prefer to use an external diff.
1142
# TODO: Selected-file diff is inefficient and doesn't show you
1145
# TODO: This probably handles non-Unix newlines poorly.
1491
1147
takes_args = ['file*']
1493
Option('diff-options', type=str,
1494
help='Pass these options to the external diff program.'),
1495
Option('prefix', type=str,
1497
help='Set prefixes added to old and new filenames, as '
1498
'two values separated by a colon. (eg "old/:new/").'),
1500
help='Branch/tree to compare from.',
1504
help='Branch/tree to compare to.',
1510
help='Use this command to compare files.',
1148
takes_options = ['revision', 'diff-options', 'prefix']
1514
1149
aliases = ['di', 'dif']
1515
1150
encoding_type = 'exact'
1517
1152
@display_command
1518
1153
def run(self, revision=None, file_list=None, diff_options=None,
1519
prefix=None, old=None, new=None, using=None):
1520
from bzrlib.diff import _get_trees_to_diff, show_diff_trees
1155
from bzrlib.diff import diff_cmd_helper, show_diff_trees
1522
1157
if (prefix is None) or (prefix == '0'):
1523
1158
# diff -p0 format
2599
1936
return FakeNFSServer
2600
1937
msg = "No known transport type %s. Supported types are: sftp\n" %\
2602
raise errors.BzrCommandError(msg)
1939
raise BzrCommandError(msg)
2605
1942
takes_args = ['testspecs*']
2606
1943
takes_options = ['verbose',
2608
help='Stop when one test fails.',
1944
Option('one', help='stop when one test fails'),
1945
Option('keep-output',
1946
help='keep output directories when tests fail'),
2612
1948
help='Use a different transport by default '
2613
1949
'throughout the test suite.',
2614
1950
type=get_transport_type),
2616
help='Run the benchmarks rather than selftests.'),
1951
Option('benchmark', help='run the bzr bencharks.'),
2617
1952
Option('lsprof-timed',
2618
help='Generate lsprof output for benchmarked'
1953
help='generate lsprof output for benchmarked'
2619
1954
' sections of code.'),
2620
1955
Option('cache-dir', type=str,
2621
help='Cache intermediate benchmark output in this '
2624
help='Run all tests, but run specified tests first.',
2628
help='List the tests instead of running them.'),
2629
Option('randomize', type=str, argname="SEED",
2630
help='Randomize the order of tests using the given'
2631
' seed or "now" for the current time.'),
2632
Option('exclude', type=str, argname="PATTERN",
2634
help='Exclude tests that match this regular'
2636
Option('strict', help='Fail on missing dependencies or '
2638
Option('load-list', type=str, argname='TESTLISTFILE',
2639
help='Load a test id list from a text file.'),
2640
ListOption('debugflag', type=str, short_name='E',
2641
help='Turn on a selftest debug flag.'),
2642
Option('starting-with', type=str, argname='TESTID',
2644
help='Load only the tests starting with TESTID.'),
1956
help='a directory to cache intermediate'
1957
' benchmark steps'),
2646
encoding_type = 'replace'
2648
def run(self, testspecs_list=None, verbose=False, one=False,
2649
transport=None, benchmark=None,
2650
lsprof_timed=None, cache_dir=None,
2651
first=False, list_only=False,
2652
randomize=None, exclude=None, strict=False,
2653
load_list=None, debugflag=None, starting_with=None):
1960
def run(self, testspecs_list=None, verbose=None, one=False,
1961
keep_output=False, transport=None, benchmark=None,
1962
lsprof_timed=None, cache_dir=None):
2654
1963
import bzrlib.ui
2655
1964
from bzrlib.tests import selftest
2656
1965
import bzrlib.benchmarks as benchmarks
2657
1966
from bzrlib.benchmarks import tree_creator
2659
# Make deprecation warnings visible, unless -Werror is set
2660
symbol_versioning.activate_deprecation_warnings(override=False)
2662
1968
if cache_dir is not None:
2663
1969
tree_creator.TreeCreator.CACHE_ROOT = osutils.abspath(cache_dir)
2665
print 'testing: %s' % (osutils.realpath(sys.argv[0]),)
2666
print ' %s (%s python%s)' % (
2668
bzrlib.version_string,
2669
bzrlib._format_version_tuple(sys.version_info),
1970
# we don't want progress meters from the tests to go to the
1971
# real output; and we don't want log messages cluttering up
1973
save_ui = ui.ui_factory
1974
print '%10s: %s' % ('bzr', osutils.realpath(sys.argv[0]))
1975
print '%10s: %s' % ('bzrlib', bzrlib.__path__[0])
2672
if testspecs_list is not None:
2673
pattern = '|'.join(testspecs_list)
2677
test_suite_factory = benchmarks.test_suite
2678
# Unless user explicitly asks for quiet, be verbose in benchmarks
2679
verbose = not is_quiet()
2680
# TODO: should possibly lock the history file...
2681
benchfile = open(".perf_history", "at", buffering=1)
2683
test_suite_factory = None
1977
info('running tests...')
2686
result = selftest(verbose=verbose,
2688
stop_on_failure=one,
2689
transport=transport,
2690
test_suite_factory=test_suite_factory,
2691
lsprof_timed=lsprof_timed,
2692
bench_history=benchfile,
2693
matching_tests_first=first,
2694
list_only=list_only,
2695
random_seed=randomize,
2696
exclude_pattern=exclude,
2698
load_list=load_list,
2699
debug_flags=debugflag,
2700
starting_with=starting_with,
1979
ui.ui_factory = ui.SilentUIFactory()
1980
if testspecs_list is not None:
1981
pattern = '|'.join(testspecs_list)
1985
test_suite_factory = benchmarks.test_suite
1988
benchfile = open(".perf_history", "at")
1990
test_suite_factory = None
1995
result = selftest(verbose=verbose,
1997
stop_on_failure=one,
1998
keep_output=keep_output,
1999
transport=transport,
2000
test_suite_factory=test_suite_factory,
2001
lsprof_timed=lsprof_timed,
2002
bench_history=benchfile)
2004
if benchfile is not None:
2007
info('tests passed')
2009
info('tests failed')
2010
return int(not result)
2703
if benchfile is not None:
2706
note('tests passed')
2708
note('tests failed')
2709
return int(not result)
2012
ui.ui_factory = save_ui
2712
2015
class cmd_version(Command):
2713
2016
"""Show version of bzr."""
2715
encoding_type = 'replace'
2717
Option("short", help="Print just the version number."),
2720
2018
@display_command
2721
def run(self, short=False):
2722
2020
from bzrlib.version import show_version
2724
self.outf.write(bzrlib.version_string + '\n')
2726
show_version(to_file=self.outf)
2729
2024
class cmd_rocks(Command):
2797
2084
default, use --remember. The value will only be saved if the remote
2798
2085
location can be accessed.
2800
The results of the merge are placed into the destination working
2801
directory, where they can be reviewed (with bzr diff), tested, and then
2802
committed to record the result of the merge.
2089
To merge the latest revision from bzr.dev
2090
bzr merge ../bzr.dev
2092
To merge changes up to and including revision 82 from bzr.dev
2093
bzr merge -r 82 ../bzr.dev
2095
To merge the changes introduced by 82, without previous changes:
2096
bzr merge -r 81..82 ../bzr.dev
2804
2098
merge refuses to run if there are any uncommitted changes, unless
2805
2099
--force is given.
2808
To merge the latest revision from bzr.dev::
2810
bzr merge ../bzr.dev
2812
To merge changes up to and including revision 82 from bzr.dev::
2814
bzr merge -r 82 ../bzr.dev
2816
To merge the changes introduced by 82, without previous changes::
2818
bzr merge -r 81..82 ../bzr.dev
2820
To apply a merge directive contained in in /tmp/merge:
2822
bzr merge /tmp/merge
2101
The following merge types are available:
2825
encoding_type = 'exact'
2826
_see_also = ['update', 'remerge', 'status-flags']
2827
takes_args = ['location?']
2832
help='Merge even if the destination tree has uncommitted changes.'),
2836
Option('show-base', help="Show base revision text in "
2838
Option('uncommitted', help='Apply uncommitted changes'
2839
' from a working copy, instead of branch changes.'),
2840
Option('pull', help='If the destination is already'
2841
' completely merged into the source, pull from the'
2842
' source rather than merging. When this happens,'
2843
' you do not need to commit the result.'),
2845
help='Branch to merge into, '
2846
'rather than the one containing the working directory.',
2850
Option('preview', help='Instead of merging, show a diff of the merge.')
2853
def run(self, location=None, revision=None, force=False,
2854
merge_type=None, show_base=False, reprocess=False, remember=False,
2855
uncommitted=False, pull=False,
2103
takes_args = ['branch?']
2104
takes_options = ['revision', 'force', 'merge-type', 'reprocess', 'remember',
2105
Option('show-base', help="Show base revision text in "
2107
Option('uncommitted', help='Apply uncommitted changes'
2108
' from a working copy, instead of branch changes')]
2111
from merge import merge_type_help
2112
from inspect import getdoc
2113
return getdoc(self) + '\n' + merge_type_help()
2115
def run(self, branch=None, revision=None, force=False, merge_type=None,
2116
show_base=False, reprocess=False, remember=False,
2859
2118
if merge_type is None:
2860
merge_type = _mod_merge.Merge3Merger
2862
if directory is None: directory = u'.'
2863
possible_transports = []
2865
allow_pending = True
2866
verified = 'inapplicable'
2867
tree = WorkingTree.open_containing(directory)[0]
2868
change_reporter = delta._ChangeReporter(
2869
unversioned_filter=tree.is_ignored)
2872
pb = ui.ui_factory.nested_progress_bar()
2873
cleanups.append(pb.finished)
2875
cleanups.append(tree.unlock)
2876
if location is not None:
2878
mergeable = bundle.read_mergeable_from_url(location,
2879
possible_transports=possible_transports)
2880
except errors.NotABundle:
2119
merge_type = Merge3Merger
2121
tree = WorkingTree.open_containing(u'.')[0]
2123
if branch is not None:
2125
reader = bundle.read_bundle_from_url(branch)
2127
pass # Continue on considering this url a Branch
2129
conflicts = merge_bundle(reader, tree, not force, merge_type,
2130
reprocess, show_base)
2884
raise errors.BzrCommandError('Cannot use --uncommitted'
2885
' with bundles or merge directives.')
2887
if revision is not None:
2888
raise errors.BzrCommandError(
2889
'Cannot use -r with merge directives or bundles')
2890
merger, verified = _mod_merge.Merger.from_mergeable(tree,
2893
if merger is None and uncommitted:
2894
if revision is not None and len(revision) > 0:
2895
raise errors.BzrCommandError('Cannot use --uncommitted and'
2896
' --revision at the same time.')
2897
location = self._select_branch_location(tree, location)[0]
2898
other_tree, other_path = WorkingTree.open_containing(location)
2899
merger = _mod_merge.Merger.from_uncommitted(tree, other_tree,
2901
allow_pending = False
2902
if other_path != '':
2903
merger.interesting_files = [other_path]
2906
merger, allow_pending = self._get_merger_from_branch(tree,
2907
location, revision, remember, possible_transports, pb)
2909
merger.merge_type = merge_type
2910
merger.reprocess = reprocess
2911
merger.show_base = show_base
2912
self.sanity_check_merger(merger)
2913
if (merger.base_rev_id == merger.other_rev_id and
2914
merger.other_rev_id is not None):
2915
note('Nothing to do.')
2136
branch = self._get_remembered_parent(tree, branch, 'Merging from')
2138
if revision is None or len(revision) < 1:
2141
other = [branch, None]
2144
other = [branch, -1]
2145
other_branch, path = Branch.open_containing(branch)
2148
raise BzrCommandError('Cannot use --uncommitted and --revision'
2149
' at the same time.')
2150
if len(revision) == 1:
2152
other_branch, path = Branch.open_containing(branch)
2153
revno = revision[0].in_history(other_branch).revno
2154
other = [branch, revno]
2156
assert len(revision) == 2
2157
if None in revision:
2158
raise BzrCommandError(
2159
"Merge doesn't permit that revision specifier.")
2160
other_branch, path = Branch.open_containing(branch)
2162
base = [branch, revision[0].in_history(other_branch).revno]
2163
other = [branch, revision[1].in_history(other_branch).revno]
2165
if tree.branch.get_parent() is None or remember:
2166
tree.branch.set_parent(other_branch.base)
2169
interesting_files = [path]
2171
interesting_files = None
2172
pb = ui.ui_factory.nested_progress_bar()
2175
conflict_count = merge(other, base, check_clean=(not force),
2176
merge_type=merge_type,
2177
reprocess=reprocess,
2178
show_base=show_base,
2179
pb=pb, file_list=interesting_files)
2182
if conflict_count != 0:
2918
if merger.interesting_files is not None:
2919
raise errors.BzrCommandError('Cannot pull individual files')
2920
if (merger.base_rev_id == tree.last_revision()):
2921
result = tree.pull(merger.other_branch, False,
2922
merger.other_rev_id)
2923
result.report(self.outf)
2925
merger.check_basis(not force)
2927
return self._do_preview(merger)
2929
return self._do_merge(merger, change_reporter, allow_pending,
2932
for cleanup in reversed(cleanups):
2935
def _do_preview(self, merger):
2936
from bzrlib.diff import show_diff_trees
2937
tree_merger = merger.make_merger()
2938
tt = tree_merger.make_preview_transform()
2940
result_tree = tt.get_preview_tree()
2941
show_diff_trees(merger.this_tree, result_tree, self.outf,
2942
old_label='', new_label='')
2946
def _do_merge(self, merger, change_reporter, allow_pending, verified):
2947
merger.change_reporter = change_reporter
2948
conflict_count = merger.do_merge()
2950
merger.set_pending()
2951
if verified == 'failed':
2952
warning('Preview patch does not match changes')
2953
if conflict_count != 0:
2958
def sanity_check_merger(self, merger):
2959
if (merger.show_base and
2960
not merger.merge_type is _mod_merge.Merge3Merger):
2961
raise errors.BzrCommandError("Show-base is not supported for this"
2962
" merge type. %s" % merger.merge_type)
2963
if merger.reprocess and not merger.merge_type.supports_reprocess:
2964
raise errors.BzrCommandError("Conflict reduction is not supported"
2965
" for merge type %s." %
2967
if merger.reprocess and merger.show_base:
2968
raise errors.BzrCommandError("Cannot do conflict reduction and"
2971
def _get_merger_from_branch(self, tree, location, revision, remember,
2972
possible_transports, pb):
2973
"""Produce a merger from a location, assuming it refers to a branch."""
2974
from bzrlib.tag import _merge_tags_if_possible
2975
# find the branch locations
2976
other_loc, user_location = self._select_branch_location(tree, location,
2978
if revision is not None and len(revision) == 2:
2979
base_loc, _unused = self._select_branch_location(tree,
2980
location, revision, 0)
2982
base_loc = other_loc
2984
other_branch, other_path = Branch.open_containing(other_loc,
2985
possible_transports)
2986
if base_loc == other_loc:
2987
base_branch = other_branch
2989
base_branch, base_path = Branch.open_containing(base_loc,
2990
possible_transports)
2991
# Find the revision ids
2992
if revision is None or len(revision) < 1 or revision[-1] is None:
2993
other_revision_id = _mod_revision.ensure_null(
2994
other_branch.last_revision())
2996
other_revision_id = revision[-1].as_revision_id(other_branch)
2997
if (revision is not None and len(revision) == 2
2998
and revision[0] is not None):
2999
base_revision_id = revision[0].as_revision_id(base_branch)
3001
base_revision_id = None
3002
# Remember where we merge from
3003
if ((remember or tree.branch.get_submit_branch() is None) and
3004
user_location is not None):
3005
tree.branch.set_submit_branch(other_branch.base)
3006
_merge_tags_if_possible(other_branch, tree.branch)
3007
merger = _mod_merge.Merger.from_revision_ids(pb, tree,
3008
other_revision_id, base_revision_id, other_branch, base_branch)
3009
if other_path != '':
3010
allow_pending = False
3011
merger.interesting_files = [other_path]
3013
allow_pending = True
3014
return merger, allow_pending
3016
def _select_branch_location(self, tree, user_location, revision=None,
3018
"""Select a branch location, according to possible inputs.
3020
If provided, branches from ``revision`` are preferred. (Both
3021
``revision`` and ``index`` must be supplied.)
3023
Otherwise, the ``location`` parameter is used. If it is None, then the
3024
``submit`` or ``parent`` location is used, and a note is printed.
3026
:param tree: The working tree to select a branch for merging into
3027
:param location: The location entered by the user
3028
:param revision: The revision parameter to the command
3029
:param index: The index to use for the revision parameter. Negative
3030
indices are permitted.
3031
:return: (selected_location, user_location). The default location
3032
will be the user-entered location.
3034
if (revision is not None and index is not None
3035
and revision[index] is not None):
3036
branch = revision[index].get_branch()
3037
if branch is not None:
3038
return branch, branch
3039
if user_location is None:
3040
location = self._get_remembered(tree, 'Merging from')
3042
location = user_location
3043
return location, user_location
3045
def _get_remembered(self, tree, verb_string):
2186
except errors.AmbiguousBase, e:
2187
m = ("sorry, bzr can't determine the right merge base yet\n"
2188
"candidates are:\n "
2189
+ "\n ".join(e.bases)
2191
"please specify an explicit base with -r,\n"
2192
"and (if you want) report this to the bzr developers\n")
2195
# TODO: move up to common parent; this isn't merge-specific anymore.
2196
def _get_remembered_parent(self, tree, supplied_location, verb_string):
3046
2197
"""Use tree.branch's parent if none was supplied.
3048
2199
Report if the remembered location was used.
3050
stored_location = tree.branch.get_submit_branch()
3051
if stored_location is None:
3052
stored_location = tree.branch.get_parent()
2201
if supplied_location is not None:
2202
return supplied_location
2203
stored_location = tree.branch.get_parent()
3053
2204
mutter("%s", stored_location)
3054
2205
if stored_location is None:
3055
raise errors.BzrCommandError("No location specified or remembered")
3056
display_url = urlutils.unescape_for_display(stored_location, 'utf-8')
3057
note(u"%s remembered location %s", verb_string, display_url)
2206
raise BzrCommandError("No location specified or remembered")
2207
display_url = urlutils.unescape_for_display(stored_location, self.outf.encoding)
2208
self.outf.write("%s remembered location %s\n" % (verb_string, display_url))
3058
2209
return stored_location
3806
class cmd_wait_until_signalled(Command):
3807
"""Test helper for test_start_and_stop_bzr_subprocess_send_signal.
3809
This just prints a line to signal when it is ready, then blocks on stdin.
3815
sys.stdout.write("running\n")
3817
sys.stdin.readline()
3820
class cmd_serve(Command):
3821
"""Run the bzr server."""
3823
aliases = ['server']
3827
help='Serve on stdin/out for use from inetd or sshd.'),
3829
help='Listen for connections on nominated port of the form '
3830
'[hostname:]portnumber. Passing 0 as the port number will '
3831
'result in a dynamically allocated port. The default port is '
3835
help='Serve contents of this directory.',
3837
Option('allow-writes',
3838
help='By default the server is a readonly server. Supplying '
3839
'--allow-writes enables write access to the contents of '
3840
'the served directory and below.'
3844
def run(self, port=None, inet=False, directory=None, allow_writes=False):
3845
from bzrlib import lockdir
3846
from bzrlib.smart import medium, server
3847
from bzrlib.transport import get_transport
3848
from bzrlib.transport.chroot import ChrootServer
3849
if directory is None:
3850
directory = os.getcwd()
3851
url = urlutils.local_path_to_url(directory)
3852
if not allow_writes:
3853
url = 'readonly+' + url
3854
chroot_server = ChrootServer(get_transport(url))
3855
chroot_server.setUp()
3856
t = get_transport(chroot_server.get_url())
3858
smart_server = medium.SmartServerPipeStreamMedium(
3859
sys.stdin, sys.stdout, t)
3861
host = medium.BZR_DEFAULT_INTERFACE
3863
port = medium.BZR_DEFAULT_PORT
3866
host, port = port.split(':')
3868
smart_server = server.SmartTCPServer(t, host=host, port=port)
3869
print 'listening on port: ', smart_server.port
3871
# for the duration of this server, no UI output is permitted.
3872
# note that this may cause problems with blackbox tests. This should
3873
# be changed with care though, as we dont want to use bandwidth sending
3874
# progress over stderr to smart server clients!
3875
old_factory = ui.ui_factory
3876
old_lockdir_timeout = lockdir._DEFAULT_TIMEOUT_SECONDS
3878
ui.ui_factory = ui.SilentUIFactory()
3879
lockdir._DEFAULT_TIMEOUT_SECONDS = 0
3880
smart_server.serve()
3882
ui.ui_factory = old_factory
3883
lockdir._DEFAULT_TIMEOUT_SECONDS = old_lockdir_timeout
3886
class cmd_join(Command):
3887
"""Combine a subtree into its containing tree.
3889
This command is for experimental use only. It requires the target tree
3890
to be in dirstate-with-subtree format, which cannot be converted into
3893
The TREE argument should be an independent tree, inside another tree, but
3894
not part of it. (Such trees can be produced by "bzr split", but also by
3895
running "bzr branch" with the target inside a tree.)
3897
The result is a combined tree, with the subtree no longer an independant
3898
part. This is marked as a merge of the subtree into the containing tree,
3899
and all history is preserved.
3901
If --reference is specified, the subtree retains its independence. It can
3902
be branched by itself, and can be part of multiple projects at the same
3903
time. But operations performed in the containing tree, such as commit
3904
and merge, will recurse into the subtree.
3907
_see_also = ['split']
3908
takes_args = ['tree']
3910
Option('reference', help='Join by reference.'),
3914
def run(self, tree, reference=False):
3915
sub_tree = WorkingTree.open(tree)
3916
parent_dir = osutils.dirname(sub_tree.basedir)
3917
containing_tree = WorkingTree.open_containing(parent_dir)[0]
3918
repo = containing_tree.branch.repository
3919
if not repo.supports_rich_root():
3920
raise errors.BzrCommandError(
3921
"Can't join trees because %s doesn't support rich root data.\n"
3922
"You can use bzr upgrade on the repository."
3926
containing_tree.add_reference(sub_tree)
3927
except errors.BadReferenceTarget, e:
3928
# XXX: Would be better to just raise a nicely printable
3929
# exception from the real origin. Also below. mbp 20070306
3930
raise errors.BzrCommandError("Cannot join %s. %s" %
3934
containing_tree.subsume(sub_tree)
3935
except errors.BadSubsumeSource, e:
3936
raise errors.BzrCommandError("Cannot join %s. %s" %
3940
class cmd_split(Command):
3941
"""Split a subdirectory of a tree into a separate tree.
3943
This command will produce a target tree in a format that supports
3944
rich roots, like 'rich-root' or 'rich-root-pack'. These formats cannot be
3945
converted into earlier formats like 'dirstate-tags'.
3947
The TREE argument should be a subdirectory of a working tree. That
3948
subdirectory will be converted into an independent tree, with its own
3949
branch. Commits in the top-level tree will not apply to the new subtree.
3952
# join is not un-hidden yet
3953
#_see_also = ['join']
3954
takes_args = ['tree']
3956
def run(self, tree):
3957
containing_tree, subdir = WorkingTree.open_containing(tree)
3958
sub_id = containing_tree.path2id(subdir)
3960
raise errors.NotVersionedError(subdir)
3962
containing_tree.extract(sub_id)
3963
except errors.RootNotRich:
3964
raise errors.UpgradeRequired(containing_tree.branch.base)
3967
class cmd_merge_directive(Command):
3968
"""Generate a merge directive for auto-merge tools.
3970
A directive requests a merge to be performed, and also provides all the
3971
information necessary to do so. This means it must either include a
3972
revision bundle, or the location of a branch containing the desired
3975
A submit branch (the location to merge into) must be supplied the first
3976
time the command is issued. After it has been supplied once, it will
3977
be remembered as the default.
3979
A public branch is optional if a revision bundle is supplied, but required
3980
if --diff or --plain is specified. It will be remembered as the default
3981
after the first use.
3984
takes_args = ['submit_branch?', 'public_branch?']
3988
_see_also = ['send']
3991
RegistryOption.from_kwargs('patch-type',
3992
'The type of patch to include in the directive.',
3994
value_switches=True,
3996
bundle='Bazaar revision bundle (default).',
3997
diff='Normal unified diff.',
3998
plain='No patch, just directive.'),
3999
Option('sign', help='GPG-sign the directive.'), 'revision',
4000
Option('mail-to', type=str,
4001
help='Instead of printing the directive, email to this address.'),
4002
Option('message', type=str, short_name='m',
4003
help='Message to use when committing this merge.')
4006
encoding_type = 'exact'
4008
def run(self, submit_branch=None, public_branch=None, patch_type='bundle',
4009
sign=False, revision=None, mail_to=None, message=None):
4010
from bzrlib.revision import ensure_null, NULL_REVISION
4011
include_patch, include_bundle = {
4012
'plain': (False, False),
4013
'diff': (True, False),
4014
'bundle': (True, True),
4016
branch = Branch.open('.')
4017
stored_submit_branch = branch.get_submit_branch()
4018
if submit_branch is None:
4019
submit_branch = stored_submit_branch
4021
if stored_submit_branch is None:
4022
branch.set_submit_branch(submit_branch)
4023
if submit_branch is None:
4024
submit_branch = branch.get_parent()
4025
if submit_branch is None:
4026
raise errors.BzrCommandError('No submit branch specified or known')
4028
stored_public_branch = branch.get_public_branch()
4029
if public_branch is None:
4030
public_branch = stored_public_branch
4031
elif stored_public_branch is None:
4032
branch.set_public_branch(public_branch)
4033
if not include_bundle and public_branch is None:
4034
raise errors.BzrCommandError('No public branch specified or'
4036
base_revision_id = None
4037
if revision is not None:
4038
if len(revision) > 2:
4039
raise errors.BzrCommandError('bzr merge-directive takes '
4040
'at most two one revision identifiers')
4041
revision_id = revision[-1].as_revision_id(branch)
4042
if len(revision) == 2:
4043
base_revision_id = revision[0].as_revision_id(branch)
4045
revision_id = branch.last_revision()
4046
revision_id = ensure_null(revision_id)
4047
if revision_id == NULL_REVISION:
4048
raise errors.BzrCommandError('No revisions to bundle.')
4049
directive = merge_directive.MergeDirective2.from_objects(
4050
branch.repository, revision_id, time.time(),
4051
osutils.local_time_offset(), submit_branch,
4052
public_branch=public_branch, include_patch=include_patch,
4053
include_bundle=include_bundle, message=message,
4054
base_revision_id=base_revision_id)
4057
self.outf.write(directive.to_signed(branch))
4059
self.outf.writelines(directive.to_lines())
4061
message = directive.to_email(mail_to, branch, sign)
4062
s = SMTPConnection(branch.get_config())
4063
s.send_email(message)
4066
class cmd_send(Command):
4067
"""Mail or create a merge-directive for submiting changes.
4069
A merge directive provides many things needed for requesting merges:
4071
* A machine-readable description of the merge to perform
4073
* An optional patch that is a preview of the changes requested
4075
* An optional bundle of revision data, so that the changes can be applied
4076
directly from the merge directive, without retrieving data from a
4079
If --no-bundle is specified, then public_branch is needed (and must be
4080
up-to-date), so that the receiver can perform the merge using the
4081
public_branch. The public_branch is always included if known, so that
4082
people can check it later.
4084
The submit branch defaults to the parent, but can be overridden. Both
4085
submit branch and public branch will be remembered if supplied.
4087
If a public_branch is known for the submit_branch, that public submit
4088
branch is used in the merge instructions. This means that a local mirror
4089
can be used as your actual submit branch, once you have set public_branch
4092
Mail is sent using your preferred mail program. This should be transparent
4093
on Windows (it uses MAPI). On Linux, it requires the xdg-email utility.
4094
If the preferred client can't be found (or used), your editor will be used.
4096
To use a specific mail program, set the mail_client configuration option.
4097
(For Thunderbird 1.5, this works around some bugs.) Supported values for
4098
specific clients are "evolution", "kmail", "mutt", and "thunderbird";
4099
generic options are "default", "editor", "mapi", and "xdg-email".
4101
If mail is being sent, a to address is required. This can be supplied
4102
either on the commandline, by setting the submit_to configuration
4103
option in the branch itself or the child_submit_to configuration option
4104
in the submit branch.
4106
Two formats are currently supported: "4" uses revision bundle format 4 and
4107
merge directive format 2. It is significantly faster and smaller than
4108
older formats. It is compatible with Bazaar 0.19 and later. It is the
4109
default. "0.9" uses revision bundle format 0.9 and merge directive
4110
format 1. It is compatible with Bazaar 0.12 - 0.18.
4112
Merge directives are applied using the merge command or the pull command.
4115
encoding_type = 'exact'
4117
_see_also = ['merge', 'pull']
4119
takes_args = ['submit_branch?', 'public_branch?']
4123
help='Do not include a bundle in the merge directive.'),
4124
Option('no-patch', help='Do not include a preview patch in the merge'
4127
help='Remember submit and public branch.'),
4129
help='Branch to generate the submission from, '
4130
'rather than the one containing the working directory.',
4133
Option('output', short_name='o',
4134
help='Write merge directive to this file; '
4135
'use - for stdout.',
4137
Option('mail-to', help='Mail the request to this address.',
4141
RegistryOption.from_kwargs('format',
4142
'Use the specified output format.',
4143
**{'4': 'Bundle format 4, Merge Directive 2 (default)',
4144
'0.9': 'Bundle format 0.9, Merge Directive 1',})
4147
def run(self, submit_branch=None, public_branch=None, no_bundle=False,
4148
no_patch=False, revision=None, remember=False, output=None,
4149
format='4', mail_to=None, message=None, **kwargs):
4150
return self._run(submit_branch, revision, public_branch, remember,
4151
format, no_bundle, no_patch, output,
4152
kwargs.get('from', '.'), mail_to, message)
4154
def _run(self, submit_branch, revision, public_branch, remember, format,
4155
no_bundle, no_patch, output, from_, mail_to, message):
4156
from bzrlib.revision import NULL_REVISION
4157
branch = Branch.open_containing(from_)[0]
4159
outfile = StringIO()
4163
outfile = open(output, 'wb')
4164
# we may need to write data into branch's repository to calculate
4169
config = branch.get_config()
4171
mail_to = config.get_user_option('submit_to')
4172
mail_client = config.get_mail_client()
4173
if remember and submit_branch is None:
4174
raise errors.BzrCommandError(
4175
'--remember requires a branch to be specified.')
4176
stored_submit_branch = branch.get_submit_branch()
4177
remembered_submit_branch = False
4178
if submit_branch is None:
4179
submit_branch = stored_submit_branch
4180
remembered_submit_branch = True
4182
if stored_submit_branch is None or remember:
4183
branch.set_submit_branch(submit_branch)
4184
if submit_branch is None:
4185
submit_branch = branch.get_parent()
4186
remembered_submit_branch = True
4187
if submit_branch is None:
4188
raise errors.BzrCommandError('No submit branch known or'
4190
if remembered_submit_branch:
4191
note('Using saved location: %s', submit_branch)
4194
submit_config = Branch.open(submit_branch).get_config()
4195
mail_to = submit_config.get_user_option("child_submit_to")
4197
stored_public_branch = branch.get_public_branch()
4198
if public_branch is None:
4199
public_branch = stored_public_branch
4200
elif stored_public_branch is None or remember:
4201
branch.set_public_branch(public_branch)
4202
if no_bundle and public_branch is None:
4203
raise errors.BzrCommandError('No public branch specified or'
4205
base_revision_id = None
4207
if revision is not None:
4208
if len(revision) > 2:
4209
raise errors.BzrCommandError('bzr send takes '
4210
'at most two one revision identifiers')
4211
revision_id = revision[-1].as_revision_id(branch)
4212
if len(revision) == 2:
4213
base_revision_id = revision[0].as_revision_id(branch)
4214
if revision_id is None:
4215
revision_id = branch.last_revision()
4216
if revision_id == NULL_REVISION:
4217
raise errors.BzrCommandError('No revisions to submit.')
4219
directive = merge_directive.MergeDirective2.from_objects(
4220
branch.repository, revision_id, time.time(),
4221
osutils.local_time_offset(), submit_branch,
4222
public_branch=public_branch, include_patch=not no_patch,
4223
include_bundle=not no_bundle, message=message,
4224
base_revision_id=base_revision_id)
4225
elif format == '0.9':
4228
patch_type = 'bundle'
4230
raise errors.BzrCommandError('Format 0.9 does not'
4231
' permit bundle with no patch')
4237
directive = merge_directive.MergeDirective.from_objects(
4238
branch.repository, revision_id, time.time(),
4239
osutils.local_time_offset(), submit_branch,
4240
public_branch=public_branch, patch_type=patch_type,
4243
outfile.writelines(directive.to_lines())
4245
subject = '[MERGE] '
4246
if message is not None:
4249
revision = branch.repository.get_revision(revision_id)
4250
subject += revision.get_summary()
4251
basename = directive.get_disk_name(branch)
4252
mail_client.compose_merge_request(mail_to, subject,
4253
outfile.getvalue(), basename)
4260
class cmd_bundle_revisions(cmd_send):
4262
"""Create a merge-directive for submiting changes.
4264
A merge directive provides many things needed for requesting merges:
4266
* A machine-readable description of the merge to perform
4268
* An optional patch that is a preview of the changes requested
4270
* An optional bundle of revision data, so that the changes can be applied
4271
directly from the merge directive, without retrieving data from a
4274
If --no-bundle is specified, then public_branch is needed (and must be
4275
up-to-date), so that the receiver can perform the merge using the
4276
public_branch. The public_branch is always included if known, so that
4277
people can check it later.
4279
The submit branch defaults to the parent, but can be overridden. Both
4280
submit branch and public branch will be remembered if supplied.
4282
If a public_branch is known for the submit_branch, that public submit
4283
branch is used in the merge instructions. This means that a local mirror
4284
can be used as your actual submit branch, once you have set public_branch
4287
Two formats are currently supported: "4" uses revision bundle format 4 and
4288
merge directive format 2. It is significantly faster and smaller than
4289
older formats. It is compatible with Bazaar 0.19 and later. It is the
4290
default. "0.9" uses revision bundle format 0.9 and merge directive
4291
format 1. It is compatible with Bazaar 0.12 - 0.18.
4296
help='Do not include a bundle in the merge directive.'),
4297
Option('no-patch', help='Do not include a preview patch in the merge'
4300
help='Remember submit and public branch.'),
4302
help='Branch to generate the submission from, '
4303
'rather than the one containing the working directory.',
4306
Option('output', short_name='o', help='Write directive to this file.',
4309
RegistryOption.from_kwargs('format',
4310
'Use the specified output format.',
4311
**{'4': 'Bundle format 4, Merge Directive 2 (default)',
4312
'0.9': 'Bundle format 0.9, Merge Directive 1',})
4314
aliases = ['bundle']
4316
_see_also = ['send', 'merge']
4320
def run(self, submit_branch=None, public_branch=None, no_bundle=False,
4321
no_patch=False, revision=None, remember=False, output=None,
4322
format='4', **kwargs):
4325
return self._run(submit_branch, revision, public_branch, remember,
4326
format, no_bundle, no_patch, output,
4327
kwargs.get('from', '.'), None, None)
4330
class cmd_tag(Command):
4331
"""Create, remove or modify a tag naming a revision.
4333
Tags give human-meaningful names to revisions. Commands that take a -r
4334
(--revision) option can be given -rtag:X, where X is any previously
4337
Tags are stored in the branch. Tags are copied from one branch to another
4338
along when you branch, push, pull or merge.
4340
It is an error to give a tag name that already exists unless you pass
4341
--force, in which case the tag is moved to point to the new revision.
4344
_see_also = ['commit', 'tags']
4345
takes_args = ['tag_name']
4348
help='Delete this tag rather than placing it.',
4351
help='Branch in which to place the tag.',
4356
help='Replace existing tags.',
4361
def run(self, tag_name,
4367
branch, relpath = Branch.open_containing(directory)
4371
branch.tags.delete_tag(tag_name)
4372
self.outf.write('Deleted tag %s.\n' % tag_name)
4375
if len(revision) != 1:
4376
raise errors.BzrCommandError(
4377
"Tags can only be placed on a single revision, "
4379
revision_id = revision[0].as_revision_id(branch)
4381
revision_id = branch.last_revision()
4382
if (not force) and branch.tags.has_tag(tag_name):
4383
raise errors.TagAlreadyExists(tag_name)
4384
branch.tags.set_tag(tag_name, revision_id)
4385
self.outf.write('Created tag %s.\n' % tag_name)
4390
class cmd_tags(Command):
4393
This command shows a table of tag names and the revisions they reference.
4399
help='Branch whose tags should be displayed.',
4403
RegistryOption.from_kwargs('sort',
4404
'Sort tags by different criteria.', title='Sorting',
4405
alpha='Sort tags lexicographically (default).',
4406
time='Sort tags chronologically.',
4417
branch, relpath = Branch.open_containing(directory)
4418
tags = branch.tags.get_tag_dict().items()
4421
elif sort == 'time':
4423
for tag, revid in tags:
4425
revobj = branch.repository.get_revision(revid)
4426
except errors.NoSuchRevision:
4427
timestamp = sys.maxint # place them at the end
4429
timestamp = revobj.timestamp
4430
timestamps[revid] = timestamp
4431
tags.sort(key=lambda x: timestamps[x[1]])
4433
# [ (tag, revid), ... ] -> [ (tag, dotted_revno), ... ]
4434
revno_map = branch.get_revision_id_to_revno_map()
4435
tags = [ (tag, '.'.join(map(str, revno_map.get(revid, ('?',)))))
4436
for tag, revid in tags ]
4437
for tag, revspec in tags:
4438
self.outf.write('%-20s %s\n' % (tag, revspec))
4441
class cmd_reconfigure(Command):
4442
"""Reconfigure the type of a bzr directory.
4444
A target configuration must be specified.
4446
For checkouts, the bind-to location will be auto-detected if not specified.
4447
The order of preference is
4448
1. For a lightweight checkout, the current bound location.
4449
2. For branches that used to be checkouts, the previously-bound location.
4450
3. The push location.
4451
4. The parent location.
4452
If none of these is available, --bind-to must be specified.
4455
takes_args = ['location?']
4456
takes_options = [RegistryOption.from_kwargs('target_type',
4457
title='Target type',
4458
help='The type to reconfigure the directory to.',
4459
value_switches=True, enum_switch=False,
4460
branch='Reconfigure to a branch.',
4461
tree='Reconfigure to a tree.',
4462
checkout='Reconfigure to a checkout.',
4463
lightweight_checkout='Reconfigure to a lightweight'
4465
standalone='Reconfigure to be standalone.',
4466
use_shared='Reconfigure to use a shared repository.'),
4467
Option('bind-to', help='Branch to bind checkout to.',
4470
help='Perform reconfiguration even if local changes'
4474
def run(self, location=None, target_type=None, bind_to=None, force=False):
4475
directory = bzrdir.BzrDir.open(location)
4476
if target_type is None:
4477
raise errors.BzrCommandError('No target configuration specified')
4478
elif target_type == 'branch':
4479
reconfiguration = reconfigure.Reconfigure.to_branch(directory)
4480
elif target_type == 'tree':
4481
reconfiguration = reconfigure.Reconfigure.to_tree(directory)
4482
elif target_type == 'checkout':
4483
reconfiguration = reconfigure.Reconfigure.to_checkout(directory,
4485
elif target_type == 'lightweight-checkout':
4486
reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
4488
elif target_type == 'use-shared':
4489
reconfiguration = reconfigure.Reconfigure.to_use_shared(directory)
4490
elif target_type == 'standalone':
4491
reconfiguration = reconfigure.Reconfigure.to_standalone(directory)
4492
reconfiguration.apply(force)
4495
class cmd_switch(Command):
4496
"""Set the branch of a checkout and update.
4498
For lightweight checkouts, this changes the branch being referenced.
4499
For heavyweight checkouts, this checks that there are no local commits
4500
versus the current bound branch, then it makes the local branch a mirror
4501
of the new location and binds to it.
4503
In both cases, the working tree is updated and uncommitted changes
4504
are merged. The user can commit or revert these as they desire.
4506
Pending merges need to be committed or reverted before using switch.
4508
The path to the branch to switch to can be specified relative to the parent
4509
directory of the current branch. For example, if you are currently in a
4510
checkout of /path/to/branch, specifying 'newbranch' will find a branch at
4514
takes_args = ['to_location']
4515
takes_options = [Option('force',
4516
help='Switch even if local commits will be lost.')
4519
def run(self, to_location, force=False):
4520
from bzrlib import switch
4522
control_dir = bzrdir.BzrDir.open_containing(tree_location)[0]
4524
to_branch = Branch.open(to_location)
4525
except errors.NotBranchError:
4526
to_branch = Branch.open(
4527
control_dir.open_branch().base + '../' + to_location)
4528
switch.switch(control_dir, to_branch, force)
4529
note('Switched to branch: %s',
4530
urlutils.unescape_for_display(to_branch.base, 'utf-8'))
4533
class cmd_hooks(Command):
4534
"""Show a branch's currently registered hooks.
4538
takes_args = ['path?']
4540
def run(self, path=None):
4543
branch_hooks = Branch.open(path).hooks
4544
for hook_type in branch_hooks:
4545
hooks = branch_hooks[hook_type]
4546
self.outf.write("%s:\n" % (hook_type,))
4549
self.outf.write(" %s\n" %
4550
(branch_hooks.get_hook_name(hook),))
4552
self.outf.write(" <no hooks installed>\n")
4555
def _create_prefix(cur_transport):
4556
needed = [cur_transport]
4557
# Recurse upwards until we can create a directory successfully
4559
new_transport = cur_transport.clone('..')
4560
if new_transport.base == cur_transport.base:
4561
raise errors.BzrCommandError(
4562
"Failed to create path prefix for %s."
4563
% cur_transport.base)
4565
new_transport.mkdir('.')
4566
except errors.NoSuchFile:
4567
needed.append(new_transport)
4568
cur_transport = new_transport
4571
# Now we only need to create child directories
4573
cur_transport = needed.pop()
4574
cur_transport.ensure_base()
2746
# command-line interpretation helper for merge-related commands
2747
def merge(other_revision, base_revision,
2748
check_clean=True, ignore_zero=False,
2749
this_dir=None, backup_files=False, merge_type=Merge3Merger,
2750
file_list=None, show_base=False, reprocess=False,
2751
pb=DummyProgress()):
2752
"""Merge changes into a tree.
2755
list(path, revno) Base for three-way merge.
2756
If [None, None] then a base will be automatically determined.
2758
list(path, revno) Other revision for three-way merge.
2760
Directory to merge changes into; '.' by default.
2762
If true, this_dir must have no uncommitted changes before the
2764
ignore_zero - If true, suppress the "zero conflicts" message when
2765
there are no conflicts; should be set when doing something we expect
2766
to complete perfectly.
2767
file_list - If supplied, merge only changes to selected files.
2769
All available ancestors of other_revision and base_revision are
2770
automatically pulled into the branch.
2772
The revno may be -1 to indicate the last revision on the branch, which is
2775
This function is intended for use from the command line; programmatic
2776
clients might prefer to call merge.merge_inner(), which has less magic
2779
from bzrlib.merge import Merger
2780
if this_dir is None:
2782
this_tree = WorkingTree.open_containing(this_dir)[0]
2783
if show_base and not merge_type is Merge3Merger:
2784
raise BzrCommandError("Show-base is not supported for this merge"
2785
" type. %s" % merge_type)
2786
if reprocess and not merge_type.supports_reprocess:
2787
raise BzrCommandError("Conflict reduction is not supported for merge"
2788
" type %s." % merge_type)
2789
if reprocess and show_base:
2790
raise BzrCommandError("Cannot do conflict reduction and show base.")
2792
merger = Merger(this_tree.branch, this_tree=this_tree, pb=pb)
2793
merger.pp = ProgressPhase("Merge phase", 5, pb)
2794
merger.pp.next_phase()
2795
merger.check_basis(check_clean)
2796
merger.set_other(other_revision)
2797
merger.pp.next_phase()
2798
merger.set_base(base_revision)
2799
if merger.base_rev_id == merger.other_rev_id:
2800
note('Nothing to do.')
2802
merger.backup_files = backup_files
2803
merger.merge_type = merge_type
2804
merger.set_interesting_files(file_list)
2805
merger.show_base = show_base
2806
merger.reprocess = reprocess
2807
conflicts = merger.do_merge()
2808
if file_list is None:
2809
merger.set_pending()
4577
2815
# these get imported and then picked up by the scan for cmd_*