27
27
from bzrlib.commands import Command, display_command
28
28
from bzrlib.branch import Branch
29
29
from bzrlib.revision import common_ancestor
30
import bzrlib.errors as errors
30
31
from bzrlib.errors import (BzrError, BzrCheckError, BzrCommandError,
31
32
NotBranchError, DivergedBranches, NotConflicted,
32
33
NoSuchFile, NoWorkingTree, FileInWrongBranch)
1127
1128
is found exports to a directory (equivalent to --format=dir).
1129
1130
Root may be the top directory for tar, tgz and tbz2 formats. If none
1130
is given, the top directory will be the root name of the file."""
1131
# TODO: list known exporters
1131
is given, the top directory will be the root name of the file.
1133
Note: export of tree with non-ascii filenames to zip is not supported.
1135
Supported formats Autodetected by extension
1136
----------------- -------------------------
1139
tbz2 .tar.bz2, .tbz2
1132
1143
takes_args = ['dest']
1133
1144
takes_options = ['revision', 'format', 'root']
1134
1145
def run(self, dest, revision=None, format=None, root=None):
1147
from bzrlib.export import export
1136
1148
tree = WorkingTree.open_containing('.')[0]
1137
1149
b = tree.branch
1138
1150
if revision is None:
1139
1151
# should be tree.last_revision FIXME
1140
rev_id = tree.branch.last_revision()
1152
rev_id = b.last_revision()
1142
1154
if len(revision) != 1:
1143
1155
raise BzrError('bzr export --revision takes exactly 1 argument')
1144
1156
rev_id = revision[0].in_history(b).rev_id
1145
1157
t = b.revision_tree(rev_id)
1146
arg_root, ext = os.path.splitext(os.path.basename(dest))
1147
if ext in ('.gz', '.bz2'):
1148
new_root, new_ext = os.path.splitext(arg_root)
1149
if new_ext == '.tar':
1155
if ext in (".tar",):
1157
elif ext in (".tar.gz", ".tgz"):
1159
elif ext in (".tar.bz2", ".tbz2"):
1163
t.export(dest, format, root)
1159
export(t, dest, format, root)
1160
except errors.NoSuchExportFormat, e:
1161
raise BzrCommandError('Unsupported export format: %s' % e.format)
1166
1164
class cmd_cat(Command):
1383
1381
def run(self, testspecs_list=None, verbose=False, one=False,
1384
1382
keep_output=False):
1385
1383
import bzrlib.ui
1386
from bzrlib.selftest import selftest
1384
from bzrlib.tests import selftest
1387
1385
# we don't want progress meters from the tests to go to the
1388
1386
# real output; and we don't want log messages cluttering up
1389
1387
# the real logs.
1861
1859
raise BzrCommandError('Please supply either one revision, or a range.')
1862
class cmd_uncommit(bzrlib.commands.Command):
1863
"""Remove the last committed revision.
1865
By supplying the --all flag, it will not only remove the entry
1866
from revision_history, but also remove all of the entries in the
1869
--verbose will print out what is being removed.
1870
--dry-run will go through all the motions, but not actually
1873
In the future, uncommit will create a changeset, which can then
1876
takes_options = ['all', 'verbose', 'revision',
1877
Option('dry-run', help='Don\'t actually make changes'),
1878
Option('force', help='Say yes to all questions.')]
1879
takes_args = ['location?']
1882
def run(self, location=None, all=False,
1883
dry_run=False, verbose=False,
1884
revision=None, force=False):
1885
from bzrlib.branch import Branch
1886
from bzrlib.log import log_formatter
1888
from bzrlib.uncommit import uncommit
1890
if location is None:
1892
b, relpath = Branch.open_containing(location)
1894
if revision is None:
1896
rev_id = b.last_revision()
1898
revno, rev_id = revision[0].in_history(b)
1900
print 'No revisions to uncommit.'
1902
for r in range(revno, b.revno()+1):
1903
rev_id = b.get_rev_id(r)
1904
lf = log_formatter('short', to_file=sys.stdout,show_timezone='original')
1905
lf.show(r, b.get_revision(rev_id), None)
1908
print 'Dry-run, pretending to remove the above revisions.'
1910
val = raw_input('Press <enter> to continue')
1912
print 'The above revision(s) will be removed.'
1914
val = raw_input('Are you sure [y/N]? ')
1915
if val.lower() not in ('y', 'yes'):
1919
uncommit(b, remove_files=all,
1920
dry_run=dry_run, verbose=verbose,
1864
1924
# these get imported and then picked up by the scan for cmd_*
1865
1925
# TODO: Some more consistent way to split command definitions across files;
1866
1926
# we do need to load at least some information about them to know of