53
53
from bzrlib.commands import Command, display_command
54
from bzrlib.option import Option
54
from bzrlib.option import Option, RegistryOption
55
55
from bzrlib.progress import DummyProgress, ProgressPhase
56
56
from bzrlib.trace import mutter, note, log_error, warning, is_quiet, info
96
96
def get_format_type(typestring):
97
97
"""Parse and return a format specifier."""
98
if typestring == "weave":
99
return bzrdir.BzrDirFormat6()
98
# Have to use BzrDirMetaFormat1 directly, so that
99
# RepositoryFormat.set_default_format works
100
100
if typestring == "default":
101
101
return bzrdir.BzrDirMetaFormat1()
102
if typestring == "metaweave":
103
format = bzrdir.BzrDirMetaFormat1()
104
format.repository_format = repository.RepositoryFormat7()
106
if typestring == "knit":
107
format = bzrdir.BzrDirMetaFormat1()
108
format.repository_format = repository.RepositoryFormatKnit1()
110
if typestring == "experimental-knit2":
111
format = bzrdir.BzrDirMetaFormat1()
112
format.repository_format = repository.RepositoryFormatKnit2()
114
msg = "Unknown bzr format %s. Current formats are: default, knit,\n" \
115
"metaweave and weave" % typestring
116
raise errors.BzrCommandError(msg)
103
return bzrdir.format_registry.make_bzrdir(typestring)
105
msg = 'Unknown bzr format "%s". See "bzr help formats".' % typestring
106
raise errors.BzrCommandError(msg)
119
109
# TODO: Make sure no commands unconditionally use the working directory as a
461
451
If the last argument is a versioned directory, all the other names
462
452
are moved into it. Otherwise, there must be exactly two arguments
463
and the file is changed to a new name, which must not already exist.
453
and the file is changed to a new name.
455
If OLDNAME does not exist on the filesystem but is versioned and
456
NEWNAME does exist on the filesystem but is not versioned, mv
457
assumes that the file has been manually moved and only updates
458
its internal inventory to reflect that change.
459
The same is valid when moving many SOURCE files to a DESTINATION.
465
461
Files cannot be moved between branches.
468
464
takes_args = ['names*']
465
takes_options = [Option("after", help="move only the bzr identifier"
466
" of the file (file has already been moved). Use this flag if"
467
" bzr is not able to detect this itself.")]
469
468
aliases = ['move', 'rename']
470
469
encoding_type = 'replace'
472
def run(self, names_list):
471
def run(self, names_list, after=False):
473
472
if names_list is None:
480
479
if os.path.isdir(names_list[-1]):
481
480
# move into existing directory
482
for pair in tree.move(rel_names[:-1], rel_names[-1]):
481
for pair in tree.move(rel_names[:-1], rel_names[-1], after=after):
483
482
self.outf.write("%s => %s\n" % pair)
485
484
if len(names_list) != 2:
486
raise errors.BzrCommandError('to mv multiple files the destination '
487
'must be a versioned directory')
488
tree.rename_one(rel_names[0], rel_names[1])
485
raise errors.BzrCommandError('to mv multiple files the'
486
' destination must be a versioned'
488
tree.rename_one(rel_names[0], rel_names[1], after=after)
489
489
self.outf.write("%s => %s\n" % (rel_names[0], rel_names[1]))
847
old_format = bzrdir.BzrDirFormat.get_default_format()
848
bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirMetaFormat1())
850
source.create_checkout(to_location, revision_id, lightweight)
852
bzrdir.BzrDirFormat.set_default_format(old_format)
847
source.create_checkout(to_location, revision_id, lightweight)
855
850
class cmd_renames(Command):
1095
1090
takes_args = ['location?']
1096
1091
takes_options = [
1092
RegistryOption('format',
1098
1093
help='Specify a format for this branch. Current'
1099
1094
' formats are: default, knit, metaweave and'
1100
1095
' weave. Default is knit; metaweave and'
1101
1096
' weave are deprecated',
1102
type=get_format_type),
1097
registry=bzrdir.format_registry,
1098
converter=get_format_type,
1099
value_switches=True),
1104
1101
def run(self, location=None, format=None):
1105
1102
if format is None:
1152
1149
(add files here)
1154
1151
takes_args = ["location"]
1155
takes_options = [Option('format',
1152
takes_options = [RegistryOption('format',
1156
1153
help='Specify a format for this repository.'
1157
1154
' Current formats are: default, knit,'
1158
1155
' metaweave and weave. Default is knit;'
1159
1156
' metaweave and weave are deprecated',
1160
type=get_format_type),
1157
registry=bzrdir.format_registry,
1158
converter=get_format_type,
1159
value_switches=True),
1161
1160
Option('trees',
1162
1161
help='Allows branches in repository to have'
1163
1162
' a working tree')]
1533
1533
Option('ignored', help='Print ignored files'),
1535
1535
Option('null', help='Null separate the files'),
1538
1538
@display_command
1539
1539
def run(self, revision=None, verbose=False,
1540
1540
non_recursive=False, from_root=False,
1541
1541
unknown=False, versioned=False, ignored=False,
1542
null=False, kind=None):
1542
null=False, kind=None, show_ids=False, path=None):
1544
1544
if kind and kind not in ('file', 'directory', 'symlink'):
1545
1545
raise errors.BzrCommandError('invalid kind specified')
1551
1551
selection = {'I':ignored, '?':unknown, 'V':versioned}
1553
tree, relpath = WorkingTree.open_containing(u'.')
1558
raise errors.BzrCommandError('cannot specify both --from-root'
1562
tree, branch, relpath = bzrdir.BzrDir.open_containing_tree_or_branch(
1558
1568
if revision is not None:
1559
tree = tree.branch.repository.revision_tree(
1560
revision[0].in_history(tree.branch).rev_id)
1569
tree = branch.repository.revision_tree(
1570
revision[0].in_history(branch).rev_id)
1572
tree = branch.basis_tree()
1562
1574
for fp, fc, fkind, fid, entry in tree.list_files(include_root=False):
1563
1575
if fp.startswith(relpath):
1564
fp = fp[len(relpath):]
1576
fp = osutils.pathjoin(prefix, fp[len(relpath):])
1565
1577
if non_recursive and '/' in fp:
1567
1579
if not all and not selection[fc]:
1572
1584
kindch = entry.kind_character()
1573
self.outf.write('%-8s %s%s\n' % (fc, fp, kindch))
1585
outstring = '%-8s %s%s' % (fc, fp, kindch)
1586
if show_ids and fid is not None:
1587
outstring = "%-50s %s" % (outstring, fid)
1588
self.outf.write(outstring + '\n')
1575
1590
self.outf.write(fp + '\0')
1593
self.outf.write(fid)
1594
self.outf.write('\0')
1576
1595
self.outf.flush()
1578
self.outf.write(fp + '\n')
1602
self.outf.write('%-50s %s\n' % (fp, my_id))
1604
self.outf.write(fp + '\n')
1581
1607
class cmd_unknowns(Command):
1956
1982
takes_args = ['url?']
1957
1983
takes_options = [
1959
help='Upgrade to a specific format. Current formats'
1960
' are: default, knit, metaweave and weave.'
1961
' Default is knit; metaweave and weave are'
1963
type=get_format_type),
1984
RegistryOption('format',
1985
help='Upgrade to a specific format. Current formats'
1986
' are: default, knit, metaweave and weave.'
1987
' Default is knit; metaweave and weave are'
1989
registry=bzrdir.format_registry,
1990
converter=get_format_type,
1991
value_switches=True),
2038
2066
class cmd_selftest(Command):
2039
2067
"""Run internal test suite.
2041
This creates temporary test directories in the working directory,
2042
but not existing data is affected. These directories are deleted
2043
if the tests pass, or left behind to help in debugging if they
2044
fail and --keep-output is specified.
2069
This creates temporary test directories in the working directory, but not
2070
existing data is affected. These directories are deleted if the tests
2071
pass, or left behind to help in debugging if they fail and --keep-output
2046
If arguments are given, they are regular expressions that say
2047
which tests should run.
2074
If arguments are given, they are regular expressions that say which tests
2075
should run. Tests matching any expression are run, and other tests are
2078
Alternatively if --first is given, matching tests are run first and then
2079
all other tests are run. This is useful if you have been working in a
2080
particular area, but want to make sure nothing else was broken.
2049
2082
If the global option '--no-plugins' is given, plugins are not loaded
2050
2083
before running the selftests. This has two effects: features provided or
2051
2084
modified by plugins will not be tested, and tests provided by plugins will
2055
2088
bzr selftest ignore
2089
run only tests relating to 'ignore'
2056
2090
bzr --no-plugins selftest -v
2091
disable plugins and list tests as they're run
2058
2093
# TODO: --list should give a list of all available tests
2094
2129
Option('clean-output',
2095
2130
help='clean temporary tests directories'
2096
2131
' without running tests'),
2133
help='run all tests, but run specified tests first',
2136
encoding_type = 'replace'
2099
2138
def run(self, testspecs_list=None, verbose=None, one=False,
2100
2139
keep_output=False, transport=None, benchmark=None,
2101
lsprof_timed=None, cache_dir=None, clean_output=False):
2140
lsprof_timed=None, cache_dir=None, clean_output=False,
2102
2142
import bzrlib.ui
2103
2143
from bzrlib.tests import selftest
2104
2144
import bzrlib.benchmarks as benchmarks
2137
2177
transport=transport,
2138
2178
test_suite_factory=test_suite_factory,
2139
2179
lsprof_timed=lsprof_timed,
2140
bench_history=benchfile)
2180
bench_history=benchfile,
2181
matching_tests_first=first,
2142
2184
if benchfile is not None:
2143
2185
benchfile.close()
2589
2631
other_branch = parent
2590
2632
if other_branch is None:
2591
2633
raise errors.BzrCommandError("No peer location known or specified.")
2592
print "Using last location: " + local_branch.get_parent()
2634
display_url = urlutils.unescape_for_display(parent,
2636
print "Using last location: " + display_url
2593
2638
remote_branch = Branch.open(other_branch)
2594
2639
if remote_branch.base == local_branch.base:
2595
2640
remote_branch = local_branch