1974
1974
if to_file is None:
1975
1975
to_file = sys.stdout
1977
files_to_backup = []
1977
1979
def recurse_directory_to_add_files(directory):
1978
1980
# Recurse directory and add all files
1979
1981
# so we can check if they have changed.
1980
1982
for parent_info, file_infos in self.walkdirs(directory):
1981
1983
for relpath, basename, kind, lstat, fileid, kind in file_infos:
1982
1984
# Is it versioned or ignored?
1983
if self.path2id(relpath) or self.is_ignored(relpath):
1985
if self.path2id(relpath):
1984
1986
# Add nested content for deletion.
1985
1987
new_files.add(relpath)
1987
# Files which are not versioned and not ignored
1989
# Files which are not versioned
1988
1990
# should be treated as unknown.
1989
unknown_nested_files.add((relpath, None, kind))
1991
files_to_backup.append(relpath)
1991
1993
for filename in files:
1992
1994
# Get file name into canonical form.
2007
2009
# Bail out if we are going to delete files we shouldn't
2008
2010
if not keep_files and not force:
2009
has_changed_files = len(unknown_nested_files) > 0
2010
if not has_changed_files:
2011
for (file_id, path, content_change, versioned, parent_id, name,
2012
kind, executable) in self.iter_changes(self.basis_tree(),
2013
include_unchanged=True, require_versioned=False,
2014
want_unversioned=True, specific_files=files):
2015
if versioned == (False, False):
2016
# The record is unknown ...
2017
if not self.is_ignored(path[1]):
2018
# ... but not ignored
2019
has_changed_files = True
2021
elif (content_change and (kind[1] is not None) and
2022
osutils.is_inside_any(files, path[1])):
2023
# Versioned and changed, but not deleted, and still
2024
# in one of the dirs to be deleted.
2025
has_changed_files = True
2028
if has_changed_files:
2029
# Make delta show ALL applicable changes in error message.
2030
tree_delta = self.changes_from(self.basis_tree(),
2031
require_versioned=False, want_unversioned=True,
2032
specific_files=files)
2033
for unknown_file in unknown_nested_files:
2034
if unknown_file not in tree_delta.unversioned:
2035
tree_delta.unversioned.extend((unknown_file,))
2036
raise errors.BzrRemoveChangedFilesError(tree_delta)
2011
for (file_id, path, content_change, versioned, parent_id, name,
2012
kind, executable) in self.iter_changes(self.basis_tree(),
2013
include_unchanged=True, require_versioned=False,
2014
want_unversioned=True, specific_files=files):
2015
if versioned[0] == False:
2016
# The record is unknown or newly added
2017
files_to_backup.append(path[1])
2018
elif (content_change and (kind[1] is not None) and
2019
osutils.is_inside_any(files, path[1])):
2020
# Versioned and changed, but not deleted, and still
2021
# in one of the dirs to be deleted.
2022
files_to_backup.append(path[1])
2038
2024
# Build inv_delta and delete files where applicable,
2039
2025
# do this before any modifications to inventory.
2063
2049
len(os.listdir(abs_path)) > 0):
2065
2051
osutils.rmtree(abs_path)
2052
message = "deleted %s" % (f,)
2067
message = "%s is not an empty directory "\
2068
"and won't be deleted." % (f,)
2054
backup_name = self.bzrdir.gen_backup_name(f)
2055
osutils.rename(abs_path, self.abspath(backup_name))
2056
message = "removed %s (but kept a copy: %s)" % (
2070
osutils.delete_any(abs_path)
2071
message = "deleted %s" % (f,)
2059
if f in files_to_backup:
2060
backup_name = self.bzrdir.gen_backup_name(f)
2061
osutils.rename(abs_path, self.abspath(backup_name))
2062
message = "removed %s (but kept a copy: %s)" % (
2065
osutils.delete_any(abs_path)
2066
message = "deleted %s" % (f,)
2072
2067
elif message is not None:
2073
2068
# Only care if we haven't done anything yet.
2074
2069
message = "%s does not exist." % (f,)