1066
1066
class cmd_remove(Command):
1067
1067
"""Remove files or directories.
1069
This makes bzr stop tracking changes to the specified files and
1070
delete them if they can easily be recovered using revert.
1072
You can specify one or more files, and/or --new. If you specify --new,
1073
only 'added' files will be removed. If you specify both, then new files
1074
in the specified directories will be removed. If the directories are
1075
also new, they will also be removed.
1069
This makes bzr stop tracking changes to the specified files. bzr will delete
1070
them if they can easily be recovered using revert. If no options or
1071
parameters are given bzr will scan for files that are being tracked by bzr
1072
but missing in your tree and stop tracking them for you.
1077
1074
takes_args = ['file*']
1078
1075
takes_options = ['verbose',
1079
Option('new', help='Remove newly-added files.'),
1076
Option('new', help='Only remove files that have never been committed.'),
1080
1077
RegistryOption.from_kwargs('file-deletion-strategy',
1081
1078
'The file deletion mode to be used.',
1082
1079
title='Deletion Strategy', value_switches=True, enum_switch=False,
1085
1082
keep="Don't delete any files.",
1086
1083
force='Delete all the specified files, even if they can not be '
1087
1084
'recovered and even if they are non-empty directories.')]
1085
aliases = ['rm', 'del']
1089
1086
encoding_type = 'replace'
1091
1088
def run(self, file_list, verbose=False, new=False,
1095
1092
if file_list is not None:
1096
1093
file_list = [f for f in file_list]
1098
raise errors.BzrCommandError('Specify one or more files to'
1099
' remove, or use --new.')
1102
added = tree.changes_from(tree.basis_tree(),
1103
specific_files=file_list).added
1104
file_list = sorted([f[0] for f in added], reverse=True)
1105
if len(file_list) == 0:
1106
raise errors.BzrCommandError('No matching files.')
1107
tree.remove(file_list, verbose=verbose, to_file=self.outf,
1108
keep_files=file_deletion_strategy=='keep',
1109
force=file_deletion_strategy=='force')
1097
# Heuristics should probably all move into tree.remove_smart or
1100
added = tree.changes_from(tree.basis_tree(),
1101
specific_files=file_list).added
1102
file_list = sorted([f[0] for f in added], reverse=True)
1103
if len(file_list) == 0:
1104
raise errors.BzrCommandError('No matching files.')
1105
elif file_list is None:
1106
# missing files show up in iter_changes(basis) as
1107
# versioned-with-no-kind.
1109
for change in tree.iter_changes(tree.basis_tree()):
1110
# Find paths in the working tree that have no kind:
1111
if change[1][1] is not None and change[6][1] is None:
1112
missing.append(change[1][1])
1113
file_list = sorted(missing, reverse=True)
1114
file_deletion_strategy = 'keep'
1115
tree.remove(file_list, verbose=verbose, to_file=self.outf,
1116
keep_files=file_deletion_strategy=='keep',
1117
force=file_deletion_strategy=='force')
1112
1122
class cmd_file_id(Command):