~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

  • Committer: Robert Collins
  • Date: 2008-08-13 03:52:23 UTC
  • mto: This revision was merged to the branch mainline in revision 3637.
  • Revision ID: robertc@robertcollins.net-20080813035223-i9sxgq2rp5477oc5
 * ``bzr rm`` will now scan for files that are missing and remove just
   them automatically, much as ``bzr add`` scans for new files that
   are not ignored and adds them automatically. (Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1066
1066
class cmd_remove(Command):
1067
1067
    """Remove files or directories.
1068
1068
 
1069
 
    This makes bzr stop tracking changes to the specified files and
1070
 
    delete them if they can easily be recovered using revert.
1071
 
 
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 and delete them
 
1070
    if they can easily be recovered using revert. If no options or parameters
 
1071
    are given bzr will scan for files that are versioned by bzr but missing in
 
1072
    your tree and unversion them for you.
1076
1073
    """
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,
1094
1091
 
1095
1092
        if file_list is not None:
1096
1093
            file_list = [f for f in file_list]
1097
 
        elif not new:
1098
 
            raise errors.BzrCommandError('Specify one or more files to'
1099
 
            ' remove, or use --new.')
1100
1094
 
1101
 
        if 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')
 
1095
        tree.lock_write()
 
1096
        try:
 
1097
            # Heuristics should probably all move into tree.remove_smart or
 
1098
            # some such?
 
1099
            if new:
 
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.
 
1108
                missing = []
 
1109
                for change in tree.iter_changes(tree.basis_tree()):
 
1110
                    if change[6][1] is None:
 
1111
                        missing.append(change[1][1])
 
1112
                file_list = sorted(missing, reverse=True)
 
1113
                file_deletion_strategy = 'keep'
 
1114
            tree.remove(file_list, verbose=verbose, to_file=self.outf,
 
1115
                keep_files=file_deletion_strategy=='keep',
 
1116
                force=file_deletion_strategy=='force')
 
1117
        finally:
 
1118
            tree.unlock()
1110
1119
 
1111
1120
 
1112
1121
class cmd_file_id(Command):