53
55
from bzrlib.commands import Command, display_command
54
from bzrlib.option import Option
56
from bzrlib.option import Option, RegistryOption
55
57
from bzrlib.progress import DummyProgress, ProgressPhase
56
58
from bzrlib.trace import mutter, note, log_error, warning, is_quiet, info
93
95
return tree, new_list
98
@symbol_versioning.deprecated_function(symbol_versioning.zero_fifteen)
96
99
def get_format_type(typestring):
97
100
"""Parse and return a format specifier."""
98
101
# Have to use BzrDirMetaFormat1 directly, so that
451
454
If the last argument is a versioned directory, all the other names
452
455
are moved into it. Otherwise, there must be exactly two arguments
453
and the file is changed to a new name, which must not already exist.
456
and the file is changed to a new name.
458
If OLDNAME does not exist on the filesystem but is versioned and
459
NEWNAME does exist on the filesystem but is not versioned, mv
460
assumes that the file has been manually moved and only updates
461
its internal inventory to reflect that change.
462
The same is valid when moving many SOURCE files to a DESTINATION.
455
464
Files cannot be moved between branches.
458
467
takes_args = ['names*']
468
takes_options = [Option("after", help="move only the bzr identifier"
469
" of the file (file has already been moved). Use this flag if"
470
" bzr is not able to detect this itself.")]
459
471
aliases = ['move', 'rename']
460
472
encoding_type = 'replace'
462
def run(self, names_list):
474
def run(self, names_list, after=False):
463
475
if names_list is None:
470
482
if os.path.isdir(names_list[-1]):
471
483
# move into existing directory
472
for pair in tree.move(rel_names[:-1], rel_names[-1]):
484
for pair in tree.move(rel_names[:-1], rel_names[-1], after=after):
473
485
self.outf.write("%s => %s\n" % pair)
475
487
if len(names_list) != 2:
476
raise errors.BzrCommandError('to mv multiple files the destination '
477
'must be a versioned directory')
478
tree.rename_one(rel_names[0], rel_names[1])
488
raise errors.BzrCommandError('to mv multiple files the'
489
' destination must be a versioned'
491
tree.rename_one(rel_names[0], rel_names[1], after=after)
479
492
self.outf.write("%s => %s\n" % (rel_names[0], rel_names[1]))
650
663
dir_to = br_from.bzrdir.clone(location_url,
651
664
revision_id=br_from.last_revision())
652
665
br_to = dir_to.open_branch()
653
count = len(br_to.revision_history())
666
count = br_to.last_revision_info()[0]
654
667
# We successfully created the target, remember it
655
668
if br_from.get_push_location() is None or remember:
656
669
br_from.set_push_location(br_to.base)
666
679
except errors.NotLocalUrl:
667
680
warning('This transport does not update the working '
668
681
'tree of: %s' % (br_to.base,))
669
count = br_to.pull(br_from, overwrite)
682
count = br_from.push(br_to, overwrite)
670
683
except errors.NoWorkingTree:
671
count = br_to.pull(br_from, overwrite)
684
count = br_from.push(br_to, overwrite)
673
count = tree_to.pull(br_from, overwrite)
688
count = br_from.push(tree_to.branch, overwrite)
674
692
except errors.DivergedBranches:
675
693
raise errors.BzrCommandError('These branches have diverged.'
676
694
' Try using "merge" and then "push".')
837
old_format = bzrdir.BzrDirFormat.get_default_format()
838
bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirMetaFormat1())
840
source.create_checkout(to_location, revision_id, lightweight)
842
bzrdir.BzrDirFormat.set_default_format(old_format)
855
source.create_checkout(to_location, revision_id, lightweight)
845
858
class cmd_renames(Command):
1085
1098
takes_args = ['location?']
1086
1099
takes_options = [
1100
RegistryOption('format',
1088
1101
help='Specify a format for this branch. Current'
1089
1102
' formats are: default, knit, metaweave and'
1090
1103
' weave. Default is knit; metaweave and'
1091
1104
' weave are deprecated',
1092
type=get_format_type),
1105
converter=bzrdir.format_registry.make_bzrdir,
1106
registry=bzrdir.format_registry,
1107
value_switches=True),
1094
1109
def run(self, location=None, format=None):
1095
1110
if format is None:
1096
format = get_format_type('default')
1111
format = bzrdir.format_registry.make_bzrdir('default')
1097
1112
if location is None:
1098
1113
location = u'.'
1142
1157
(add files here)
1144
1159
takes_args = ["location"]
1145
takes_options = [Option('format',
1160
takes_options = [RegistryOption('format',
1146
1161
help='Specify a format for this repository.'
1147
1162
' Current formats are: default, knit,'
1148
1163
' metaweave and weave. Default is knit;'
1149
1164
' metaweave and weave are deprecated',
1150
type=get_format_type),
1165
registry=bzrdir.format_registry,
1166
converter=bzrdir.format_registry.make_bzrdir,
1167
value_switches=True),
1151
1168
Option('trees',
1152
1169
help='Allows branches in repository to have'
1153
1170
' a working tree')]
1154
1171
aliases = ["init-repo"]
1155
1172
def run(self, location, format=None, trees=False):
1156
1173
if format is None:
1157
format = get_format_type('default')
1174
format = bzrdir.format_registry.make_bzrdir('default')
1159
1176
if location is None:
1553
tree, relpath = WorkingTree.open_containing(fs_path)
1570
tree, branch, relpath = bzrdir.BzrDir.open_containing_tree_or_branch(
1558
1576
if revision is not None:
1559
tree = tree.branch.repository.revision_tree(
1560
revision[0].in_history(tree.branch).rev_id)
1577
tree = branch.repository.revision_tree(
1578
revision[0].in_history(branch).rev_id)
1580
tree = branch.basis_tree()
1562
1582
for fp, fc, fkind, fid, entry in tree.list_files(include_root=False):
1563
1583
if fp.startswith(relpath):
1970
1990
takes_args = ['url?']
1971
1991
takes_options = [
1973
help='Upgrade to a specific format. Current formats'
1974
' are: default, knit, metaweave and weave.'
1975
' Default is knit; metaweave and weave are'
1977
type=get_format_type),
1992
RegistryOption('format',
1993
help='Upgrade to a specific format. Current formats'
1994
' are: default, knit, metaweave and weave.'
1995
' Default is knit; metaweave and weave are'
1997
registry=bzrdir.format_registry,
1998
converter=bzrdir.format_registry.make_bzrdir,
1999
value_switches=True),
1981
2003
def run(self, url='.', format=None):
1982
2004
from bzrlib.upgrade import upgrade
1983
2005
if format is None:
1984
format = get_format_type('default')
2006
format = bzrdir.format_registry.make_bzrdir('default')
1985
2007
upgrade(url, format)
2052
2074
class cmd_selftest(Command):
2053
2075
"""Run internal test suite.
2055
This creates temporary test directories in the working directory,
2056
but not existing data is affected. These directories are deleted
2057
if the tests pass, or left behind to help in debugging if they
2058
fail and --keep-output is specified.
2077
This creates temporary test directories in the working directory, but not
2078
existing data is affected. These directories are deleted if the tests
2079
pass, or left behind to help in debugging if they fail and --keep-output
2060
If arguments are given, they are regular expressions that say
2061
which tests should run.
2082
If arguments are given, they are regular expressions that say which tests
2083
should run. Tests matching any expression are run, and other tests are
2086
Alternatively if --first is given, matching tests are run first and then
2087
all other tests are run. This is useful if you have been working in a
2088
particular area, but want to make sure nothing else was broken.
2063
2090
If the global option '--no-plugins' is given, plugins are not loaded
2064
2091
before running the selftests. This has two effects: features provided or
2065
2092
modified by plugins will not be tested, and tests provided by plugins will
2069
2096
bzr selftest ignore
2097
run only tests relating to 'ignore'
2070
2098
bzr --no-plugins selftest -v
2099
disable plugins and list tests as they're run
2072
2101
# TODO: --list should give a list of all available tests
2108
2137
Option('clean-output',
2109
2138
help='clean temporary tests directories'
2110
2139
' without running tests'),
2141
help='run all tests, but run specified tests first',
2112
2144
encoding_type = 'replace'
2114
2146
def run(self, testspecs_list=None, verbose=None, one=False,
2115
2147
keep_output=False, transport=None, benchmark=None,
2116
lsprof_timed=None, cache_dir=None, clean_output=False):
2148
lsprof_timed=None, cache_dir=None, clean_output=False,
2117
2150
import bzrlib.ui
2118
2151
from bzrlib.tests import selftest
2119
2152
import bzrlib.benchmarks as benchmarks
2152
2185
transport=transport,
2153
2186
test_suite_factory=test_suite_factory,
2154
2187
lsprof_timed=lsprof_timed,
2155
bench_history=benchfile)
2188
bench_history=benchfile,
2189
matching_tests_first=first,
2157
2192
if benchfile is not None:
2158
2193
benchfile.close()
2196
2231
branch1 = Branch.open_containing(branch)[0]
2197
2232
branch2 = Branch.open_containing(other)[0]
2199
history_1 = branch1.revision_history()
2200
history_2 = branch2.revision_history()
2202
2234
last1 = branch1.last_revision()
2203
2235
last2 = branch2.last_revision()
2604
2636
other_branch = parent
2605
2637
if other_branch is None:
2606
2638
raise errors.BzrCommandError("No peer location known or specified.")
2607
print "Using last location: " + local_branch.get_parent()
2639
display_url = urlutils.unescape_for_display(parent,
2641
print "Using last location: " + display_url
2608
2643
remote_branch = Branch.open(other_branch)
2609
2644
if remote_branch.base == local_branch.base:
2610
2645
remote_branch = local_branch