700
590
location = stored_loc
702
592
to_transport = transport.get_transport(location)
593
location_url = to_transport.base
704
br_to = repository_to = dir_to = None
706
dir_to = bzrdir.BzrDir.open_from_transport(to_transport)
707
except errors.NotBranchError:
708
pass # Didn't find anything
710
# If we can open a branch, use its direct repository, otherwise see
711
# if there is a repository without a branch.
713
br_to = dir_to.open_branch()
714
except errors.NotBranchError:
715
# Didn't find a branch, can we find a repository?
717
repository_to = dir_to.find_repository()
718
except errors.NoRepositoryPresent:
721
# Found a branch, so we must have found a repository
722
repository_to = br_to.repository
726
# The destination doesn't exist; create it.
727
# XXX: Refactor the create_prefix/no_create_prefix code into a
728
# common helper function
730
to_transport.mkdir('.')
731
except errors.FileExists:
732
if not use_existing_dir:
733
raise errors.BzrCommandError("Target directory %s"
734
" already exists, but does not have a valid .bzr"
735
" directory. Supply --use-existing-dir to push"
736
" there anyway." % location)
737
except errors.NoSuchFile:
738
if not create_prefix:
739
raise errors.BzrCommandError("Parent directory of %s"
741
"\nYou may supply --create-prefix to create all"
742
" leading parent directories."
745
_create_prefix(to_transport)
747
# Now the target directory exists, but doesn't have a .bzr
748
# directory. So we need to create it, along with any work to create
749
# all of the dependent branches, etc.
750
dir_to = br_from.bzrdir.clone_on_transport(to_transport,
597
dir_to = bzrdir.BzrDir.open(location_url)
598
br_to = dir_to.open_branch()
599
except errors.NotBranchError:
601
to_transport = to_transport.clone('..')
602
if not create_prefix:
604
relurl = to_transport.relpath(location_url)
605
mutter('creating directory %s => %s', location_url, relurl)
606
to_transport.mkdir(relurl)
607
except errors.NoSuchFile:
608
raise errors.BzrCommandError("Parent directory of %s "
609
"does not exist." % location)
611
current = to_transport.base
612
needed = [(to_transport, to_transport.relpath(location_url))]
615
to_transport, relpath = needed[-1]
616
to_transport.mkdir(relpath)
618
except errors.NoSuchFile:
619
new_transport = to_transport.clone('..')
620
needed.append((new_transport,
621
new_transport.relpath(to_transport.base)))
622
if new_transport.base == to_transport.base:
623
raise errors.BzrCommandError("Could not create "
625
dir_to = br_from.bzrdir.clone(location_url,
751
626
revision_id=br_from.last_revision())
752
627
br_to = dir_to.open_branch()
753
# TODO: Some more useful message about what was copied
754
note('Created new branch.')
628
count = len(br_to.revision_history())
755
629
# We successfully created the target, remember it
756
630
if br_from.get_push_location() is None or remember:
757
631
br_from.set_push_location(br_to.base)
758
elif repository_to is None:
759
# we have a bzrdir but no branch or repository
760
# XXX: Figure out what to do other than complain.
761
raise errors.BzrCommandError("At %s you have a valid .bzr control"
762
" directory, but not a branch or repository. This is an"
763
" unsupported configuration. Please move the target directory"
764
" out of the way and try again."
767
# We have a repository but no branch, copy the revisions, and then
769
last_revision_id = br_from.last_revision()
770
repository_to.fetch(br_from.repository,
771
revision_id=last_revision_id)
772
br_to = br_from.clone(dir_to, revision_id=last_revision_id)
773
note('Created new branch.')
774
if br_from.get_push_location() is None or remember:
775
br_from.set_push_location(br_to.base)
776
else: # We have a valid to branch
777
633
# We were able to connect to the remote location, so remember it
778
634
# we don't need to successfully push because of possible divergence.
779
635
if br_from.get_push_location() is None or remember:
1065
911
also new, they will also be removed.
1067
913
takes_args = ['file*']
1068
takes_options = ['verbose',
1069
Option('new', help='Remove newly-added files.'),
1070
RegistryOption.from_kwargs('file-deletion-strategy',
1071
'The file deletion mode to be used',
1072
title='Deletion Strategy', value_switches=True, enum_switch=False,
1073
safe='Only delete files if they can be'
1074
' safely recovered (default).',
1075
keep="Don't delete any files.",
1076
force='Delete all the specified files, even if they can not be '
1077
'recovered and even if they are non-empty directories.')]
914
takes_options = ['verbose', Option('new', help='remove newly-added files')]
1078
915
aliases = ['rm']
1079
916
encoding_type = 'replace'
1081
def run(self, file_list, verbose=False, new=False,
1082
file_deletion_strategy='safe'):
918
def run(self, file_list, verbose=False, new=False):
1083
919
tree, file_list = tree_files(file_list)
1085
if file_list is not None:
1086
file_list = [f for f in file_list if f != '']
1088
raise errors.BzrCommandError('Specify one or more files to'
1089
' remove, or use --new.')
921
if file_list is None:
922
raise errors.BzrCommandError('Specify one or more files to'
923
' remove, or use --new.')
1092
925
added = tree.changes_from(tree.basis_tree(),
1093
926
specific_files=file_list).added
1094
927
file_list = sorted([f[0] for f in added], reverse=True)
1095
928
if len(file_list) == 0:
1096
929
raise errors.BzrCommandError('No matching files.')
1097
tree.remove(file_list, verbose=verbose, to_file=self.outf,
1098
keep_files=file_deletion_strategy=='keep',
1099
force=file_deletion_strategy=='force')
930
tree.remove(file_list, verbose=verbose, to_file=self.outf)
1102
933
class cmd_file_id(Command):
1292
1098
raise errors.BranchExistsWithoutWorkingTree(location)
1293
1099
raise errors.AlreadyBranchError(location)
1295
branch = existing_bzrdir.create_branch()
1101
existing_bzrdir.create_branch()
1296
1102
existing_bzrdir.create_workingtree()
1297
if append_revisions_only:
1299
branch.set_append_revisions_only(True)
1300
except errors.UpgradeRequired:
1301
raise errors.BzrCommandError('This branch format cannot be set'
1302
' to append-revisions-only. Try --experimental-branch6')
1305
1105
class cmd_init_repository(Command):
1306
1106
"""Create a shared repository to hold branches.
1308
New branches created under the repository directory will store their
1309
revisions in the repository, not in the branch directory.
1311
If the --no-trees option is used then the branches in the repository
1312
will not have working trees by default.
1108
New branches created under the repository directory will store their revisions
1109
in the repository, not in the branch directory, if the branch format supports
1315
bzr init-repo --no-trees repo
1316
1114
bzr init repo/trunk
1317
1115
bzr checkout --lightweight repo/trunk trunk-checkout
1318
1116
cd trunk-checkout
1319
1117
(add files here)
1321
See 'bzr help repositories' for more information.
1324
_see_also = ['init', 'branch', 'checkout']
1325
takes_args = ["location"]
1326
takes_options = [RegistryOption('format',
1327
help='Specify a format for this repository. See'
1328
' "bzr help formats" for details.',
1329
registry=bzrdir.format_registry,
1330
converter=bzrdir.format_registry.make_bzrdir,
1331
value_switches=True, title='Repository format'),
1333
help='Branches in the repository will default to'
1334
' not having a working tree.'),
1119
takes_args = ["location"]
1120
takes_options = [Option('format',
1121
help='Specify a format for this repository.'
1122
' Current formats are: default, knit,'
1123
' metaweave and weave. Default is knit;'
1124
' metaweave and weave are deprecated',
1125
type=get_format_type),
1127
help='Allows branches in repository to have'
1336
1129
aliases = ["init-repo"]
1338
def run(self, location, format=None, no_trees=False):
1130
def run(self, location, format=None, trees=False):
1339
1131
if format is None:
1340
format = bzrdir.format_registry.make_bzrdir('default')
1132
format = get_format_type('default')
1342
1134
if location is None:
1345
1137
to_transport = transport.get_transport(location)
1346
to_transport.ensure_base()
1139
to_transport.mkdir('.')
1140
except errors.FileExists:
1348
1143
newdir = format.initialize_on_transport(to_transport)
1349
1144
repo = newdir.create_repository(shared=True)
1350
repo.set_make_working_trees(not no_trees)
1145
repo.set_make_working_trees(trees)
1353
1148
class cmd_diff(Command):
1442
1226
tree1, tree2 = None, None
1446
if tree2 is not None:
1447
if revision is not None:
1448
# FIXME: but there should be a clean way to diff between
1449
# non-default versions of two trees, it's not hard to do
1451
raise errors.BzrCommandError(
1452
"Sorry, diffing arbitrary revisions across branches "
1453
"is not implemented yet")
1454
return show_diff_trees(tree1, tree2, sys.stdout,
1455
specific_files=file_list,
1456
external_diff_options=diff_options,
1457
old_label=old_label, new_label=new_label)
1459
return diff_cmd_helper(tree1, file_list, diff_options,
1460
revision_specs=revision,
1461
old_label=old_label, new_label=new_label)
1229
if revision is not None:
1230
if tree2 is not None:
1231
raise errors.BzrCommandError("Can't specify -r with two branches")
1232
if (len(revision) == 1) or (revision[1].spec is None):
1233
return diff_cmd_helper(tree1, file_list, diff_options,
1235
old_label=old_label, new_label=new_label)
1236
elif len(revision) == 2:
1237
return diff_cmd_helper(tree1, file_list, diff_options,
1238
revision[0], revision[1],
1239
old_label=old_label, new_label=new_label)
1241
raise errors.BzrCommandError('bzr diff --revision takes exactly'
1242
' one or two revision identifiers')
1244
if tree2 is not None:
1245
return show_diff_trees(tree1, tree2, sys.stdout,
1246
specific_files=file_list,
1247
external_diff_options=diff_options,
1248
old_label=old_label, new_label=new_label)
1250
return diff_cmd_helper(tree1, file_list, diff_options,
1251
old_label=old_label, new_label=new_label)
1464
1254
class cmd_deleted(Command):
1643
1397
dir, relpath = bzrdir.BzrDir.open_containing(location)
1644
1398
b = dir.open_branch()
1648
if revision is None:
1651
elif len(revision) == 1:
1652
rev1 = rev2 = revision[0].in_history(b)
1653
elif len(revision) == 2:
1654
if revision[1].get_branch() != revision[0].get_branch():
1655
# b is taken from revision[0].get_branch(), and
1656
# show_log will use its revision_history. Having
1657
# different branches will lead to weird behaviors.
1658
raise errors.BzrCommandError(
1659
"Log doesn't accept two revisions in different"
1661
rev1 = revision[0].in_history(b)
1662
rev2 = revision[1].in_history(b)
1400
if revision is None:
1403
elif len(revision) == 1:
1404
rev1 = rev2 = revision[0].in_history(b).revno
1405
elif len(revision) == 2:
1406
if revision[1].get_branch() != revision[0].get_branch():
1407
# b is taken from revision[0].get_branch(), and
1408
# show_log will use its revision_history. Having
1409
# different branches will lead to weird behaviors.
1664
1410
raise errors.BzrCommandError(
1665
'bzr log --revision takes one or two values.')
1667
if log_format is None:
1668
log_format = log.log_formatter_registry.get_default(b)
1670
lf = log_format(show_ids=show_ids, to_file=self.outf,
1671
show_timezone=timezone)
1677
direction=direction,
1678
start_revision=rev1,
1411
"Log doesn't accept two revisions in different branches.")
1412
if revision[0].spec is None:
1413
# missing begin-range means first revision
1416
rev1 = revision[0].in_history(b).revno
1418
if revision[1].spec is None:
1419
# missing end-range means last known revision
1422
rev2 = revision[1].in_history(b).revno
1424
raise errors.BzrCommandError('bzr log --revision takes one or two values.')
1426
# By this point, the revision numbers are converted to the +ve
1427
# form if they were supplied in the -ve form, so we can do
1428
# this comparison in relative safety
1430
(rev2, rev1) = (rev1, rev2)
1432
if (log_format is None):
1433
default = b.get_config().log_format()
1434
log_format = get_log_format(long=long, short=short, line=line,
1436
lf = log_formatter(log_format,
1439
show_timezone=timezone)
1445
direction=direction,
1446
start_revision=rev1,
1686
1451
def get_log_format(long=False, short=False, line=False, default='long'):
1751
1507
selection = {'I':ignored, '?':unknown, 'V':versioned}
1758
raise errors.BzrCommandError('cannot specify both --from-root'
1762
tree, branch, relpath = bzrdir.BzrDir.open_containing_tree_or_branch(
1509
tree, relpath = WorkingTree.open_containing(u'.')
1768
1514
if revision is not None:
1769
tree = branch.repository.revision_tree(
1770
revision[0].in_history(branch).rev_id)
1772
tree = branch.basis_tree()
1515
tree = tree.branch.repository.revision_tree(
1516
revision[0].in_history(tree.branch).rev_id)
1776
for fp, fc, fkind, fid, entry in tree.list_files(include_root=False):
1777
if fp.startswith(relpath):
1778
fp = osutils.pathjoin(prefix, fp[len(relpath):])
1779
if non_recursive and '/' in fp:
1781
if not all and not selection[fc]:
1783
if kind is not None and fkind != kind:
1786
kindch = entry.kind_character()
1787
outstring = '%-8s %s%s' % (fc, fp, kindch)
1788
if show_ids and fid is not None:
1789
outstring = "%-50s %s" % (outstring, fid)
1790
self.outf.write(outstring + '\n')
1792
self.outf.write(fp + '\0')
1795
self.outf.write(fid)
1796
self.outf.write('\0')
1804
self.outf.write('%-50s %s\n' % (fp, my_id))
1806
self.outf.write(fp + '\n')
1518
for fp, fc, kind, fid, entry in tree.list_files(include_root=False):
1519
if fp.startswith(relpath):
1520
fp = fp[len(relpath):]
1521
if non_recursive and '/' in fp:
1523
if not all and not selection[fc]:
1526
kindch = entry.kind_character()
1527
self.outf.write('%-8s %s%s\n' % (fc, fp, kindch))
1529
self.outf.write(fp + '\0')
1532
self.outf.write(fp + '\n')
1811
1535
class cmd_unknowns(Command):
1812
"""List unknown files.
1536
"""List unknown files."""
1818
1537
@display_command
1820
1539
for f in WorkingTree.open_containing(u'.')[0].unknowns():
2101
1777
# XXX: verbose currently does nothing
2103
_see_also = ['bugs', 'uncommit']
2104
1779
takes_args = ['selected*']
2109
help='Commit even if nothing has changed.'),
2110
Option('file', type=str,
2113
help='Take commit message from this file.'),
2115
help="Refuse to commit if there are unknown "
2116
"files in the working tree."),
2117
ListOption('fixes', type=str,
2118
help="Mark a bug as being fixed by this revision."),
2120
help="Perform a local commit in a bound "
2121
"branch. Local commits are not pushed to "
2122
"the master branch until a normal commit "
1780
takes_options = ['message', 'verbose',
1782
help='commit even if nothing has changed'),
1783
Option('file', type=str,
1785
help='file containing commit message'),
1787
help="refuse to commit if there are unknown "
1788
"files in the working tree."),
1790
help="perform a local only commit in a bound "
1791
"branch. Such commits are not pushed to "
1792
"the master branch until a normal commit "
2126
1796
aliases = ['ci', 'checkin']
2128
def _get_bug_fix_properties(self, fixes, branch):
2130
# Configure the properties for bug fixing attributes.
2131
for fixed_bug in fixes:
2132
tokens = fixed_bug.split(':')
2133
if len(tokens) != 2:
2134
raise errors.BzrCommandError(
2135
"Invalid bug %s. Must be in the form of 'tag:id'. "
2136
"Commit refused." % fixed_bug)
2137
tag, bug_id = tokens
2139
bug_url = bugtracker.get_bug_url(tag, branch, bug_id)
2140
except errors.UnknownBugTrackerAbbreviation:
2141
raise errors.BzrCommandError(
2142
'Unrecognized bug %s. Commit refused.' % fixed_bug)
2143
except errors.MalformedBugIdentifier:
2144
raise errors.BzrCommandError(
2145
"Invalid bug identifier for %s. Commit refused."
2147
properties.append('%s fixed' % bug_url)
2148
return '\n'.join(properties)
2150
1798
def run(self, message=None, file=None, verbose=True, selected_list=None,
2151
unchanged=False, strict=False, local=False, fixes=None):
1799
unchanged=False, strict=False, local=False):
2152
1800
from bzrlib.commit import (NullCommitReporter, ReportCommitToLog)
2153
1801
from bzrlib.errors import (PointlessCommit, ConflictsInTree,
2154
1802
StrictCommitFailed)
2170
1815
# selected-file merge commit is not done yet
2171
1816
selected_list = []
2173
bug_property = self._get_bug_fix_properties(fixes, tree.branch)
2175
properties['bugs'] = bug_property
2177
1818
if local and not tree.branch.get_bound_location():
2178
1819
raise errors.LocalRequiresBoundBranch()
2180
def get_message(commit_obj):
2181
"""Callback to get commit message"""
2182
my_message = message
2183
if my_message is None and not file:
2184
template = make_commit_message_template(tree, selected_list)
2185
my_message = edit_commit_message(template)
2186
if my_message is None:
2187
raise errors.BzrCommandError("please specify a commit"
2188
" message with either --message or --file")
2189
elif my_message and file:
2190
raise errors.BzrCommandError(
2191
"please specify either --message or --file")
2193
my_message = codecs.open(file, 'rt',
2194
bzrlib.user_encoding).read()
2195
if my_message == "":
2196
raise errors.BzrCommandError("empty commit message specified")
1820
if message is None and not file:
1821
template = make_commit_message_template(tree, selected_list)
1822
message = edit_commit_message(template)
1824
raise errors.BzrCommandError("please specify a commit message"
1825
" with either --message or --file")
1826
elif message and file:
1827
raise errors.BzrCommandError("please specify either --message or --file")
1830
message = codecs.open(file, 'rt', bzrlib.user_encoding).read()
1833
raise errors.BzrCommandError("empty commit message specified")
2200
1836
reporter = ReportCommitToLog()
2202
1838
reporter = NullCommitReporter()
1840
msgfilename = self._save_commit_message(message, tree.basedir)
2205
tree.commit(message_callback=get_message,
2206
specific_files=selected_list,
1842
tree.commit(message, specific_files=selected_list,
2207
1843
allow_pointless=unchanged, strict=strict, local=local,
2208
reporter=reporter, revprops=properties)
1845
if msgfilename is not None:
1847
os.unlink(msgfilename)
1849
warning("failed to unlink %s: %s; ignored", msgfilename, e)
2209
1850
except PointlessCommit:
2210
1851
# FIXME: This should really happen before the file is read in;
2211
1852
# perhaps prepare the commit; get the message; then actually commit
2212
raise errors.BzrCommandError("no changes to commit."
2213
" use --unchanged to commit anyhow")
1853
if msgfilename is not None:
1854
raise errors.BzrCommandError("no changes to commit."
1855
" use --unchanged to commit anyhow\n"
1856
"Commit message saved. To reuse the message,"
1857
" do\nbzr commit --file " + msgfilename)
1859
raise errors.BzrCommandError("no changes to commit."
1860
" use --unchanged to commit anyhow")
2214
1861
except ConflictsInTree:
2215
raise errors.BzrCommandError('Conflicts detected in working '
2216
'tree. Use "bzr conflicts" to list, "bzr resolve FILE" to'
1862
if msgfilename is not None:
1863
raise errors.BzrCommandError('Conflicts detected in working '
1864
'tree. Use "bzr conflicts" to list, "bzr resolve FILE" to'
1866
'Commit message saved. To reuse the message,'
1867
' do\nbzr commit --file ' + msgfilename)
1869
raise errors.BzrCommandError('Conflicts detected in working '
1870
'tree. Use "bzr conflicts" to list, "bzr resolve FILE" to'
2218
1872
except StrictCommitFailed:
2219
raise errors.BzrCommandError("Commit refused because there are"
2220
" unknown files in the working tree.")
1873
if msgfilename is not None:
1874
raise errors.BzrCommandError("Commit refused because there are"
1875
" unknown files in the working tree.\n"
1876
"Commit message saved. To reuse the message,"
1877
" do\nbzr commit --file " + msgfilename)
1879
raise errors.BzrCommandError("Commit refused because there are"
1880
" unknown files in the working tree.")
2221
1881
except errors.BoundBranchOutOfDate, e:
2222
raise errors.BzrCommandError(str(e) + "\n"
2223
'To commit to master branch, run update and then commit.\n'
2224
'You can also pass --local to commit to continue working '
1882
if msgfilename is not None:
1883
raise errors.BzrCommandError(str(e) + "\n"
1884
'To commit to master branch, run update and then commit.\n'
1885
'You can also pass --local to commit to continue working '
1887
'Commit message saved. To reuse the message,'
1888
' do\nbzr commit --file ' + msgfilename)
1890
raise errors.BzrCommandError(str(e) + "\n"
1891
'To commit to master branch, run update and then commit.\n'
1892
'You can also pass --local to commit to continue working '
1895
def _save_commit_message(self, message, basedir):
1896
# save the commit message and only unlink it if the commit was
1900
tmp_fileno, msgfilename = tempfile.mkstemp(prefix='bzr-commit-',
1904
# No access to working dir, try $TMP
1905
tmp_fileno, msgfilename = tempfile.mkstemp(prefix='bzr-commit-')
1907
# We can't create a temp file, try to work without it
1910
os.write(tmp_fileno, message.encode(bzrlib.user_encoding, 'replace'))
1912
os.close(tmp_fileno)
2228
1916
class cmd_check(Command):
2336
2019
@display_command
2337
2020
def printme(self, branch):
2341
2024
class cmd_selftest(Command):
2342
2025
"""Run internal test suite.
2344
If arguments are given, they are regular expressions that say which tests
2345
should run. Tests matching any expression are run, and other tests are
2348
Alternatively if --first is given, matching tests are run first and then
2349
all other tests are run. This is useful if you have been working in a
2350
particular area, but want to make sure nothing else was broken.
2352
If --exclude is given, tests that match that regular expression are
2353
excluded, regardless of whether they match --first or not.
2355
To help catch accidential dependencies between tests, the --randomize
2356
option is useful. In most cases, the argument used is the word 'now'.
2357
Note that the seed used for the random number generator is displayed
2358
when this option is used. The seed can be explicitly passed as the
2359
argument to this option if required. This enables reproduction of the
2360
actual ordering used if and when an order sensitive problem is encountered.
2362
If --list-only is given, the tests that would be run are listed. This is
2363
useful when combined with --first, --exclude and/or --randomize to
2364
understand their impact. The test harness reports "Listed nn tests in ..."
2365
instead of "Ran nn tests in ..." when list mode is enabled.
2027
This creates temporary test directories in the working directory,
2028
but not existing data is affected. These directories are deleted
2029
if the tests pass, or left behind to help in debugging if they
2030
fail and --keep-output is specified.
2032
If arguments are given, they are regular expressions that say
2033
which tests should run.
2367
2035
If the global option '--no-plugins' is given, plugins are not loaded
2368
2036
before running the selftests. This has two effects: features provided or
2369
2037
modified by plugins will not be tested, and tests provided by plugins will
2373
2041
bzr selftest ignore
2374
run only tests relating to 'ignore'
2375
2042
bzr --no-plugins selftest -v
2376
disable plugins and list tests as they're run
2044
# TODO: --list should give a list of all available tests
2378
For each test, that needs actual disk access, bzr create their own
2379
subdirectory in the temporary testing directory (testXXXX.tmp).
2380
By default the name of such subdirectory is based on the name of the test.
2381
If option '--numbered-dirs' is given, bzr will use sequent numbers
2382
of running tests to create such subdirectories. This is default behavior
2383
on Windows because of path length limitation.
2385
2046
# NB: this is used from the class without creating an instance, which is
2386
2047
# why it does not have a self parameter.
2387
2048
def get_transport_type(typestring):
2403
2064
takes_args = ['testspecs*']
2404
2065
takes_options = ['verbose',
2406
help='Stop when one test fails.',
2409
Option('keep-output',
2410
help='Keep output directories when tests fail.'),
2066
Option('one', help='stop when one test fails'),
2067
Option('keep-output',
2068
help='keep output directories when tests fail'),
2412
2070
help='Use a different transport by default '
2413
2071
'throughout the test suite.',
2414
2072
type=get_transport_type),
2416
help='Run the benchmarks rather than selftests.'),
2073
Option('benchmark', help='run the bzr bencharks.'),
2417
2074
Option('lsprof-timed',
2418
help='Generate lsprof output for benchmarked'
2075
help='generate lsprof output for benchmarked'
2419
2076
' sections of code.'),
2420
2077
Option('cache-dir', type=str,
2421
help='Cache intermediate benchmark output in this '
2423
Option('clean-output',
2424
help='Clean temporary tests directories'
2425
' without running tests.'),
2427
help='Run all tests, but run specified tests first.',
2430
Option('numbered-dirs',
2431
help='Use numbered dirs for TestCaseInTempDir.'),
2433
help='List the tests instead of running them.'),
2434
Option('randomize', type=str, argname="SEED",
2435
help='Randomize the order of tests using the given'
2436
' seed or "now" for the current time.'),
2437
Option('exclude', type=str, argname="PATTERN",
2439
help='Exclude tests that match this regular'
2078
help='a directory to cache intermediate'
2079
' benchmark steps'),
2442
encoding_type = 'replace'
2444
2082
def run(self, testspecs_list=None, verbose=None, one=False,
2445
2083
keep_output=False, transport=None, benchmark=None,
2446
lsprof_timed=None, cache_dir=None, clean_output=False,
2447
first=False, numbered_dirs=None, list_only=False,
2448
randomize=None, exclude=None):
2084
lsprof_timed=None, cache_dir=None):
2449
2085
import bzrlib.ui
2450
2086
from bzrlib.tests import selftest
2451
2087
import bzrlib.benchmarks as benchmarks
2452
2088
from bzrlib.benchmarks import tree_creator
2455
from bzrlib.tests import clean_selftest_output
2456
clean_selftest_output()
2459
warning("notice: selftest --keep-output "
2460
"is no longer supported; "
2461
"test output is always removed")
2463
if numbered_dirs is None and sys.platform == 'win32':
2464
numbered_dirs = True
2466
2090
if cache_dir is not None:
2467
2091
tree_creator.TreeCreator.CACHE_ROOT = osutils.abspath(cache_dir)
2468
2092
print '%10s: %s' % ('bzr', osutils.realpath(sys.argv[0]))
2574
2198
default, use --remember. The value will only be saved if the remote
2575
2199
location can be accessed.
2577
The results of the merge are placed into the destination working
2578
directory, where they can be reviewed (with bzr diff), tested, and then
2579
committed to record the result of the merge.
2583
To merge the latest revision from bzr.dev:
2584
bzr merge ../bzr.dev
2203
To merge the latest revision from bzr.dev
2204
bzr merge ../bzr.dev
2586
To merge changes up to and including revision 82 from bzr.dev:
2587
bzr merge -r 82 ../bzr.dev
2206
To merge changes up to and including revision 82 from bzr.dev
2207
bzr merge -r 82 ../bzr.dev
2589
2209
To merge the changes introduced by 82, without previous changes:
2590
bzr merge -r 81..82 ../bzr.dev
2210
bzr merge -r 81..82 ../bzr.dev
2592
2212
merge refuses to run if there are any uncommitted changes, unless
2593
2213
--force is given.
2215
The following merge types are available:
2596
_see_also = ['update', 'remerge', 'status-flags']
2597
2217
takes_args = ['branch?']
2598
2218
takes_options = ['revision', 'force', 'merge-type', 'reprocess', 'remember',
2599
Option('show-base', help="Show base revision text in "
2601
Option('uncommitted', help='Apply uncommitted changes'
2602
' from a working copy, instead of branch changes.'),
2603
Option('pull', help='If the destination is already'
2604
' completely merged into the source, pull from the'
2605
' source rather than merging. When this happens,'
2606
' you do not need to commit the result.'),
2608
help='Branch to merge into, '
2609
'rather than the one containing the working directory.',
2219
Option('show-base', help="Show base revision text in "
2221
Option('uncommitted', help='Apply uncommitted changes'
2222
' from a working copy, instead of branch changes')]
2225
from inspect import getdoc
2226
return getdoc(self) + '\n' + _mod_merge.merge_type_help()
2615
2228
def run(self, branch=None, revision=None, force=False, merge_type=None,
2616
show_base=False, reprocess=False, remember=False,
2617
uncommitted=False, pull=False,
2620
from bzrlib.tag import _merge_tags_if_possible
2621
other_revision_id = None
2229
show_base=False, reprocess=False, remember=False,
2622
2231
if merge_type is None:
2623
2232
merge_type = _mod_merge.Merge3Merger
2625
if directory is None: directory = u'.'
2626
# XXX: jam 20070225 WorkingTree should be locked before you extract its
2627
# inventory. Because merge is a mutating operation, it really
2628
# should be a lock_write() for the whole cmd_merge operation.
2629
# However, cmd_merge open's its own tree in _merge_helper, which
2630
# means if we lock here, the later lock_write() will always block.
2631
# Either the merge helper code should be updated to take a tree,
2632
# (What about tree.merge_from_branch?)
2633
tree = WorkingTree.open_containing(directory)[0]
2634
change_reporter = delta._ChangeReporter(
2635
unversioned_filter=tree.is_ignored)
2234
tree = WorkingTree.open_containing(u'.')[0]
2637
2236
if branch is not None:
2639
mergeable = bundle.read_mergeable_from_url(
2238
reader = bundle.read_bundle_from_url(branch)
2641
2239
except errors.NotABundle:
2642
2240
pass # Continue on considering this url a Branch
2644
if revision is not None:
2645
raise errors.BzrCommandError(
2646
'Cannot use -r with merge directives or bundles')
2647
other_revision_id = mergeable.install_revisions(
2648
tree.branch.repository)
2649
revision = [RevisionSpec.from_string(
2650
'revid:' + other_revision_id)]
2242
conflicts = merge_bundle(reader, tree, not force, merge_type,
2243
reprocess, show_base)
2652
2249
if revision is None \
2653
2250
or len(revision) < 1 or revision[0].needs_branch():
2952
2532
class cmd_missing(Command):
2953
2533
"""Show unmerged/unpulled revisions between two branches.
2955
2535
OTHER_BRANCH may be local or remote.
2958
_see_also = ['merge', 'pull']
2959
2537
takes_args = ['other_branch?']
2961
Option('reverse', 'Reverse the order of revisions.'),
2963
'Display changes in the local branch only.'),
2964
Option('this' , 'Same as --mine-only.'),
2965
Option('theirs-only',
2966
'Display changes in the remote branch only.'),
2967
Option('other', 'Same as --theirs-only.'),
2538
takes_options = [Option('reverse', 'Reverse the order of revisions'),
2540
'Display changes in the local branch only'),
2541
Option('theirs-only',
2542
'Display changes in the remote branch only'),
2972
2550
encoding_type = 'replace'
2974
2552
@display_command
2975
2553
def run(self, other_branch=None, reverse=False, mine_only=False,
2976
2554
theirs_only=False, log_format=None, long=False, short=False, line=False,
2977
show_ids=False, verbose=False, this=False, other=False):
2978
from bzrlib.missing import find_unmerged, iter_log_revisions
2555
show_ids=False, verbose=False):
2556
from bzrlib.missing import find_unmerged, iter_log_data
2979
2557
from bzrlib.log import log_formatter
2986
2558
local_branch = Branch.open_containing(u".")[0]
2987
2559
parent = local_branch.get_parent()
2988
2560
if other_branch is None:
2989
2561
other_branch = parent
2990
2562
if other_branch is None:
2991
2563
raise errors.BzrCommandError("No peer location known or specified.")
2992
display_url = urlutils.unescape_for_display(parent,
2994
print "Using last location: " + display_url
2564
print "Using last location: " + local_branch.get_parent()
2996
2565
remote_branch = Branch.open(other_branch)
2997
2566
if remote_branch.base == local_branch.base:
2998
2567
remote_branch = local_branch
3360
2909
takes_options = [
3362
help='Serve on stdin/out for use from inetd or sshd.'),
2911
help='serve on stdin/out for use from inetd or sshd'),
3364
help='Listen for connections on nominated port of the form '
3365
'[hostname:]portnumber. Passing 0 as the port number will '
3366
'result in a dynamically allocated port. The default port is '
2913
help='listen for connections on nominated port of the form '
2914
'[hostname:]portnumber. Passing 0 as the port number will '
2915
'result in a dynamically allocated port.',
3369
2917
Option('directory',
3370
help='Serve contents of this directory.',
2918
help='serve contents of directory',
3372
2920
Option('allow-writes',
3373
help='By default the server is a readonly server. Supplying '
2921
help='By default the server is a readonly server. Supplying '
3374
2922
'--allow-writes enables write access to the contents of '
3375
'the served directory and below.'
2923
'the served directory and below. '
3379
2927
def run(self, port=None, inet=False, directory=None, allow_writes=False):
3380
from bzrlib.smart import medium, server
2928
from bzrlib.transport import smart
3381
2929
from bzrlib.transport import get_transport
3382
from bzrlib.transport.chroot import ChrootServer
3383
from bzrlib.transport.remote import BZR_DEFAULT_PORT, BZR_DEFAULT_INTERFACE
3384
2930
if directory is None:
3385
2931
directory = os.getcwd()
3386
2932
url = urlutils.local_path_to_url(directory)
3387
2933
if not allow_writes:
3388
2934
url = 'readonly+' + url
3389
chroot_server = ChrootServer(get_transport(url))
3390
chroot_server.setUp()
3391
t = get_transport(chroot_server.get_url())
2935
t = get_transport(url)
3393
smart_server = medium.SmartServerPipeStreamMedium(
3394
sys.stdin, sys.stdout, t)
3396
host = BZR_DEFAULT_INTERFACE
3398
port = BZR_DEFAULT_PORT
2937
server = smart.SmartServerPipeStreamMedium(sys.stdin, sys.stdout, t)
2938
elif port is not None:
2940
host, port = port.split(':')
3401
host, port = port.split(':')
3403
smart_server = server.SmartTCPServer(t, host=host, port=port)
3404
print 'listening on port: ', smart_server.port
2943
server = smart.SmartTCPServer(t, host=host, port=int(port))
2944
print 'listening on port: ', server.port
3405
2945
sys.stdout.flush()
3406
# for the duration of this server, no UI output is permitted.
3407
# note that this may cause problems with blackbox tests. This should
3408
# be changed with care though, as we dont want to use bandwidth sending
3409
# progress over stderr to smart server clients!
3410
old_factory = ui.ui_factory
3412
ui.ui_factory = ui.SilentUIFactory()
3413
smart_server.serve()
3415
ui.ui_factory = old_factory
3418
class cmd_join(Command):
3419
"""Combine a subtree into its containing tree.
3421
This command is for experimental use only. It requires the target tree
3422
to be in dirstate-with-subtree format, which cannot be converted into
3425
The TREE argument should be an independent tree, inside another tree, but
3426
not part of it. (Such trees can be produced by "bzr split", but also by
3427
running "bzr branch" with the target inside a tree.)
3429
The result is a combined tree, with the subtree no longer an independant
3430
part. This is marked as a merge of the subtree into the containing tree,
3431
and all history is preserved.
3433
If --reference is specified, the subtree retains its independence. It can
3434
be branched by itself, and can be part of multiple projects at the same
3435
time. But operations performed in the containing tree, such as commit
3436
and merge, will recurse into the subtree.
3439
_see_also = ['split']
3440
takes_args = ['tree']
3442
Option('reference', help='Join by reference.'),
3446
def run(self, tree, reference=False):
3447
sub_tree = WorkingTree.open(tree)
3448
parent_dir = osutils.dirname(sub_tree.basedir)
3449
containing_tree = WorkingTree.open_containing(parent_dir)[0]
3450
repo = containing_tree.branch.repository
3451
if not repo.supports_rich_root():
3452
raise errors.BzrCommandError(
3453
"Can't join trees because %s doesn't support rich root data.\n"
3454
"You can use bzr upgrade on the repository."
3458
containing_tree.add_reference(sub_tree)
3459
except errors.BadReferenceTarget, e:
3460
# XXX: Would be better to just raise a nicely printable
3461
# exception from the real origin. Also below. mbp 20070306
3462
raise errors.BzrCommandError("Cannot join %s. %s" %
3466
containing_tree.subsume(sub_tree)
3467
except errors.BadSubsumeSource, e:
3468
raise errors.BzrCommandError("Cannot join %s. %s" %
3472
class cmd_split(Command):
3473
"""Split a tree into two trees.
3475
This command is for experimental use only. It requires the target tree
3476
to be in dirstate-with-subtree format, which cannot be converted into
3479
The TREE argument should be a subdirectory of a working tree. That
3480
subdirectory will be converted into an independent tree, with its own
3481
branch. Commits in the top-level tree will not apply to the new subtree.
3482
If you want that behavior, do "bzr join --reference TREE".
3485
_see_also = ['join']
3486
takes_args = ['tree']
3490
def run(self, tree):
3491
containing_tree, subdir = WorkingTree.open_containing(tree)
3492
sub_id = containing_tree.path2id(subdir)
3494
raise errors.NotVersionedError(subdir)
3496
containing_tree.extract(sub_id)
3497
except errors.RootNotRich:
3498
raise errors.UpgradeRequired(containing_tree.branch.base)
3502
class cmd_merge_directive(Command):
3503
"""Generate a merge directive for auto-merge tools.
3505
A directive requests a merge to be performed, and also provides all the
3506
information necessary to do so. This means it must either include a
3507
revision bundle, or the location of a branch containing the desired
3510
A submit branch (the location to merge into) must be supplied the first
3511
time the command is issued. After it has been supplied once, it will
3512
be remembered as the default.
3514
A public branch is optional if a revision bundle is supplied, but required
3515
if --diff or --plain is specified. It will be remembered as the default
3516
after the first use.
3519
takes_args = ['submit_branch?', 'public_branch?']
3522
RegistryOption.from_kwargs('patch-type',
3523
'The type of patch to include in the directive',
3525
value_switches=True,
3527
bundle='Bazaar revision bundle (default).',
3528
diff='Normal unified diff.',
3529
plain='No patch, just directive.'),
3530
Option('sign', help='GPG-sign the directive.'), 'revision',
3531
Option('mail-to', type=str,
3532
help='Instead of printing the directive, email to this address.'),
3533
Option('message', type=str, short_name='m',
3534
help='Message to use when committing this merge.')
3537
encoding_type = 'exact'
3539
def run(self, submit_branch=None, public_branch=None, patch_type='bundle',
3540
sign=False, revision=None, mail_to=None, message=None):
3541
from bzrlib.revision import ensure_null, NULL_REVISION
3542
if patch_type == 'plain':
3544
branch = Branch.open('.')
3545
stored_submit_branch = branch.get_submit_branch()
3546
if submit_branch is None:
3547
submit_branch = stored_submit_branch
3549
if stored_submit_branch is None:
3550
branch.set_submit_branch(submit_branch)
3551
if submit_branch is None:
3552
submit_branch = branch.get_parent()
3553
if submit_branch is None:
3554
raise errors.BzrCommandError('No submit branch specified or known')
3556
stored_public_branch = branch.get_public_branch()
3557
if public_branch is None:
3558
public_branch = stored_public_branch
3559
elif stored_public_branch is None:
3560
branch.set_public_branch(public_branch)
3561
if patch_type != "bundle" and public_branch is None:
3562
raise errors.BzrCommandError('No public branch specified or'
3564
if revision is not None:
3565
if len(revision) != 1:
3566
raise errors.BzrCommandError('bzr merge-directive takes '
3567
'exactly one revision identifier')
3569
revision_id = revision[0].in_history(branch).rev_id
3571
revision_id = branch.last_revision()
3572
revision_id = ensure_null(revision_id)
3573
if revision_id == NULL_REVISION:
3574
raise errors.BzrCommandError('No revisions to bundle.')
3575
directive = merge_directive.MergeDirective.from_objects(
3576
branch.repository, revision_id, time.time(),
3577
osutils.local_time_offset(), submit_branch,
3578
public_branch=public_branch, patch_type=patch_type,
3582
self.outf.write(directive.to_signed(branch))
3584
self.outf.writelines(directive.to_lines())
3586
message = directive.to_email(mail_to, branch, sign)
3587
s = SMTPConnection(branch.get_config())
3588
s.send_email(message)
3591
class cmd_tag(Command):
3592
"""Create a tag naming a revision.
3594
Tags give human-meaningful names to revisions. Commands that take a -r
3595
(--revision) option can be given -rtag:X, where X is any previously
3598
Tags are stored in the branch. Tags are copied from one branch to another
3599
along when you branch, push, pull or merge.
3601
It is an error to give a tag name that already exists unless you pass
3602
--force, in which case the tag is moved to point to the new revision.
3605
_see_also = ['commit', 'tags']
3606
takes_args = ['tag_name']
3609
help='Delete this tag rather than placing it.',
3612
help='Branch in which to place the tag.',
3617
help='Replace existing tags.',
3622
def run(self, tag_name,
3628
branch, relpath = Branch.open_containing(directory)
3632
branch.tags.delete_tag(tag_name)
3633
self.outf.write('Deleted tag %s.\n' % tag_name)
3636
if len(revision) != 1:
3637
raise errors.BzrCommandError(
3638
"Tags can only be placed on a single revision, "
3640
revision_id = revision[0].in_history(branch).rev_id
3642
revision_id = branch.last_revision()
3643
if (not force) and branch.tags.has_tag(tag_name):
3644
raise errors.TagAlreadyExists(tag_name)
3645
branch.tags.set_tag(tag_name, revision_id)
3646
self.outf.write('Created tag %s.\n' % tag_name)
3651
class cmd_tags(Command):
3654
This tag shows a table of tag names and the revisions they reference.
3660
help='Branch whose tags should be displayed.',
3670
branch, relpath = Branch.open_containing(directory)
3671
for tag_name, target in sorted(branch.tags.get_tag_dict().items()):
3672
self.outf.write('%-20s %s\n' % (tag_name, target))
2947
raise errors.BzrCommandError("bzr serve requires one of --inet or --port")
3675
2951
# command-line interpretation helper for merge-related commands