212
213
self.outf.write(b.repository.get_revision_xml(rev_id).decode('utf-8'))
216
class cmd_remove_tree(Command):
217
"""Remove the working tree from a given branch/checkout.
219
Since a lightweight checkout is little more than a working tree
220
this will refuse to run against one.
225
takes_args = ['location?']
227
def run(self, location='.'):
228
d = bzrdir.BzrDir.open(location)
231
working = d.open_workingtree()
232
except errors.NoWorkingTree:
233
raise errors.BzrCommandError("No working tree to remove")
234
except errors.NotLocalUrl:
235
raise errors.BzrCommandError("You cannot remove the working tree of a "
238
working_path = working.bzrdir.root_transport.base
239
branch_path = working.branch.bzrdir.root_transport.base
240
if working_path != branch_path:
241
raise errors.BzrCommandError("You cannot remove the working tree from "
242
"a lightweight checkout")
244
d.destroy_workingtree()
215
247
class cmd_revno(Command):
216
248
"""Show current revision number.
1802
1833
StrictCommitFailed)
1803
1834
from bzrlib.msgeditor import edit_commit_message, \
1804
1835
make_commit_message_template
1805
from tempfile import TemporaryFile
1807
1837
# TODO: Need a blackbox test for invoking the external editor; may be
1808
1838
# slightly problematic to run this cross-platform.
1810
1840
# TODO: do more checks that the commit will succeed before
1811
1841
# spending the user's valuable time typing a commit message.
1813
# TODO: if the commit *does* happen to fail, then save the commit
1814
# message to a temporary file where it can be recovered
1815
1842
tree, selected_list = tree_files(selected_list)
1816
1843
if selected_list == ['']:
1817
1844
# workaround - commit of root of tree should be exactly the same
1840
1867
reporter = ReportCommitToLog()
1842
1869
reporter = NullCommitReporter()
1871
msgfilename = self._save_commit_message(message, tree.basedir)
1845
1873
tree.commit(message, specific_files=selected_list,
1846
1874
allow_pointless=unchanged, strict=strict, local=local,
1847
1875
reporter=reporter)
1876
if msgfilename is not None:
1878
os.unlink(msgfilename)
1880
warning("failed to unlink %s: %s; ignored", msgfilename, e)
1848
1881
except PointlessCommit:
1849
1882
# FIXME: This should really happen before the file is read in;
1850
1883
# perhaps prepare the commit; get the message; then actually commit
1851
raise errors.BzrCommandError("no changes to commit."
1852
" use --unchanged to commit anyhow")
1884
if msgfilename is not None:
1885
raise errors.BzrCommandError("no changes to commit."
1886
" use --unchanged to commit anyhow\n"
1887
"Commit message saved. To reuse the message,"
1888
" do\nbzr commit --file " + msgfilename)
1890
raise errors.BzrCommandError("no changes to commit."
1891
" use --unchanged to commit anyhow")
1853
1892
except ConflictsInTree:
1854
raise errors.BzrCommandError("Conflicts detected in working tree. "
1855
'Use "bzr conflicts" to list, "bzr resolve FILE" to resolve.')
1893
if msgfilename is not None:
1894
raise errors.BzrCommandError('Conflicts detected in working '
1895
'tree. Use "bzr conflicts" to list, "bzr resolve FILE" to'
1897
'Commit message saved. To reuse the message,'
1898
' do\nbzr commit --file ' + msgfilename)
1900
raise errors.BzrCommandError('Conflicts detected in working '
1901
'tree. Use "bzr conflicts" to list, "bzr resolve FILE" to'
1856
1903
except StrictCommitFailed:
1857
raise errors.BzrCommandError("Commit refused because there are unknown "
1858
"files in the working tree.")
1904
if msgfilename is not None:
1905
raise errors.BzrCommandError("Commit refused because there are"
1906
" unknown files in the working tree.\n"
1907
"Commit message saved. To reuse the message,"
1908
" do\nbzr commit --file " + msgfilename)
1910
raise errors.BzrCommandError("Commit refused because there are"
1911
" unknown files in the working tree.")
1859
1912
except errors.BoundBranchOutOfDate, e:
1860
raise errors.BzrCommandError(str(e) + "\n"
1913
if msgfilename is not None:
1914
raise errors.BzrCommandError(str(e) + "\n"
1915
'To commit to master branch, run update and then commit.\n'
1916
'You can also pass --local to commit to continue working '
1918
'Commit message saved. To reuse the message,'
1919
' do\nbzr commit --file ' + msgfilename)
1921
raise errors.BzrCommandError(str(e) + "\n"
1861
1922
'To commit to master branch, run update and then commit.\n'
1862
1923
'You can also pass --local to commit to continue working '
1863
1924
'disconnected.')
1926
def _save_commit_message(self, message, basedir):
1927
# save the commit message and only unlink it if the commit was
1931
tmp_fileno, msgfilename = tempfile.mkstemp(prefix='bzr-commit-',
1935
# No access to working dir, try $TMP
1936
tmp_fileno, msgfilename = tempfile.mkstemp(prefix='bzr-commit-')
1938
# We can't create a temp file, try to work without it
1941
os.write(tmp_fileno, message.encode(bzrlib.user_encoding, 'replace'))
1943
os.close(tmp_fileno)
1865
1947
class cmd_check(Command):
1866
1948
"""Validate consistency of branch history.
2058
2121
if cache_dir is not None:
2059
2122
tree_creator.TreeCreator.CACHE_ROOT = osutils.abspath(cache_dir)
2060
# we don't want progress meters from the tests to go to the
2061
# real output; and we don't want log messages cluttering up
2063
save_ui = ui.ui_factory
2064
2123
print '%10s: %s' % ('bzr', osutils.realpath(sys.argv[0]))
2065
2124
print '%10s: %s' % ('bzrlib', bzrlib.__path__[0])
2067
info('running tests...')
2126
if testspecs_list is not None:
2127
pattern = '|'.join(testspecs_list)
2131
test_suite_factory = benchmarks.test_suite
2134
# TODO: should possibly lock the history file...
2135
benchfile = open(".perf_history", "at")
2137
test_suite_factory = None
2069
ui.ui_factory = ui.SilentUIFactory()
2070
if testspecs_list is not None:
2071
pattern = '|'.join(testspecs_list)
2075
test_suite_factory = benchmarks.test_suite
2078
# TODO: should possibly lock the history file...
2079
benchfile = open(".perf_history", "at")
2081
test_suite_factory = None
2086
result = selftest(verbose=verbose,
2088
stop_on_failure=one,
2089
keep_output=keep_output,
2090
transport=transport,
2091
test_suite_factory=test_suite_factory,
2092
lsprof_timed=lsprof_timed,
2093
bench_history=benchfile)
2095
if benchfile is not None:
2098
info('tests passed')
2100
info('tests failed')
2101
return int(not result)
2142
result = selftest(verbose=verbose,
2144
stop_on_failure=one,
2145
keep_output=keep_output,
2146
transport=transport,
2147
test_suite_factory=test_suite_factory,
2148
lsprof_timed=lsprof_timed,
2149
bench_history=benchfile)
2103
ui.ui_factory = save_ui
2151
if benchfile is not None:
2154
info('tests passed')
2156
info('tests failed')
2157
return int(not result)
2106
2160
class cmd_version(Command):
2452
2507
class cmd_assert_fail(Command):
2453
2508
"""Test reporting of assertion failures"""
2509
# intended just for use in testing
2456
assert False, "always fails"
2514
raise AssertionError("always fails")
2459
2517
class cmd_help(Command):
2460
2518
"""Show help on a command or other topic.
2462
For a list of all available commands, say 'bzr help commands'."""
2520
For a list of all available commands, say 'bzr help commands'.
2463
2522
takes_options = [Option('long', 'show help on all commands')]
2464
2523
takes_args = ['topic?']
2465
2524
aliases = ['?', '--help', '-?', '-h']
2467
2526
@display_command
2468
2527
def run(self, topic=None, long=False):
2470
2529
if topic is None and long:
2471
2530
topic = "commands"
2531
bzrlib.help.help(topic)
2475
2534
class cmd_shell_complete(Command):
2476
2535
"""Show appropriate completions for context.
2478
For a list of all available commands, say 'bzr shell-complete'."""
2537
For a list of all available commands, say 'bzr shell-complete'.
2479
2539
takes_args = ['context?']
2480
2540
aliases = ['s-c']