~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/workingtree.py

  • Committer: Marius Kruger
  • Date: 2006-12-22 16:49:38 UTC
  • mto: (2220.1.1 bzr.enhanced_move)
  • mto: This revision was merged to the branch mainline in revision 2241.
  • Revision ID: amanic@gmail.com-20061222164938-rbjxiq858d78k5lw
Converted move/rename error messages to show source => target.

Show diffs side-by-side

added added

removed removed

Lines of Context:
82
82
    compact_date,
83
83
    file_kind,
84
84
    isdir,
85
 
    pathjoin,
 
85
    normpath,
 
86
    pathjoin,    
 
87
    rand_chars,    
 
88
    realpath,
86
89
    safe_unicode,
87
90
    splitpath,
88
 
    rand_chars,
89
 
    normpath,
90
 
    realpath,
91
91
    supports_executable,
92
92
    )
93
93
from bzrlib.trace import mutter, note
982
982
                # if we finished all children, pop it off the stack
983
983
                stack.pop()
984
984
 
 
985
    def _getRenameFailedMessage(self, from_path, to_path, action="rename"):
 
986
        
 
987
        return self._getMoveFailedMessage(from_path, to_path, action)
 
988
        
 
989
    def _getMoveFailedMessage(self, from_path, to_path, action="move"):
 
990
 
 
991
        #RFC maybe we want the relative path not just the last component:
 
992
        #from_path = self.relpath(from_path)
 
993
        #to_rel = self.relpath(to_path)
 
994
        
 
995
        has_from = len(from_path) > 0
 
996
        has_to = len(to_path) > 0
 
997
        if has_from:
 
998
            from_path = splitpath(from_path)[-1]
 
999
        if has_to:
 
1000
            to_path = splitpath(to_path)[-1]
 
1001
 
 
1002
        prefix = "Could not %s " % action
 
1003
        if has_from and has_to:
 
1004
            return "%s%s => %s"%(prefix,from_path,to_path)
 
1005
        if has_from:
 
1006
            return "%sfrom %s"%(prefix,from_path)
 
1007
        if has_to:
 
1008
            return "%sto %s"%(prefix,to_path)
 
1009
        return "%sfile"%prefix        
 
1010
 
985
1011
    @needs_tree_write_lock
986
1012
    def move(self, from_paths, to_dir=None, after=False, **kwargs):
987
1013
        """Rename files.
1037
1063
        to_abs = self.abspath(to_dir)
1038
1064
        if not isdir(to_abs):
1039
1065
            raise errors.NotADirectory(to_abs, 
1040
 
                extra="Invalid move destination")
 
1066
                extra=self._getMoveFailedMessage('',to_dir))
1041
1067
        if not self.has_filename(to_dir):
1042
1068
            raise errors.NotInWorkingDirectory(to_dir, 
1043
 
                extra="(Invalid move destination)")
 
1069
                extra=self._getMoveFailedMessage('',to_dir))
1044
1070
        to_dir_id = inv.path2id(to_dir)
1045
1071
        if to_dir_id is None:
1046
1072
            raise errors.NotVersionedError(path=str(to_dir),
1047
 
                context_info="Invalid move destination")
 
1073
                context_info=self._getMoveFailedMessage('',to_dir))
1048
1074
            
1049
1075
        to_dir_ie = inv[to_dir_id]
1050
1076
        if to_dir_ie.kind != 'directory':
1051
1077
            raise errors.NotADirectory(to_abs, 
1052
 
                extra="Invalid move destination")
 
1078
                extra=self._getMoveFailedMessage('',to_dir))
1053
1079
 
1054
1080
        # create rename entries and tuples
1055
1081
        for from_rel in from_paths:
1057
1083
            from_id = inv.path2id(from_rel)
1058
1084
            if from_id is None:
1059
1085
                raise errors.NotVersionedError(path=str(from_rel),
1060
 
                    context_info="Invalid source")
 
1086
                    context_info=self._getMoveFailedMessage(from_rel,to_dir))
1061
1087
 
1062
1088
            from_entry = inv[from_id]
1063
1089
            from_parent_id = from_entry.parent_id
1106
1132
            # check the inventory for source and destination
1107
1133
            if from_id is None:
1108
1134
                raise errors.NotVersionedError(path=str(from_rel),
1109
 
                    context_info="Could not move file")
 
1135
                    context_info=self._getMoveFailedMessage(from_rel,to_rel))
1110
1136
            if to_id is not None:
1111
1137
                raise errors.AlreadyVersionedError(path=str(to_rel),
1112
 
                    context_info="Could not move file")
 
1138
                    context_info=self._getMoveFailedMessage(from_rel,to_rel))
1113
1139
 
1114
1140
            # try to determine the mode for rename (only change inv or change 
1115
1141
            # inv and file system)
1127
1153
                if not self.has_filename(from_rel) and \
1128
1154
                   not self.has_filename(to_rel):
1129
1155
                    raise PathsDoNotExist(paths=(str(from_rel), str(to_rel)),
1130
 
                        extra="Could not rename file")
 
1156
                        extra=self._getRenameFailedMessage(from_rel,to_rel))
1131
1157
                else:
1132
1158
                    raise errors.FilesExist(paths=(str(from_rel), str(to_rel)),
1133
 
                        extra="Could not rename file. Use option '--after' to"
1134
 
                              " force rename.")
 
1159
                        extra=self._getRenameFailedMessage(from_rel,to_rel)+
 
1160
                        ". Use option '--after' to force rename.")
1135
1161
            rename_entry.only_change_inv = only_change_inv                       
1136
1162
        return rename_entries
1137
1163
 
1220
1246
        from_id = inv.path2id(from_rel)
1221
1247
        if from_id is None:
1222
1248
            raise errors.NotVersionedError(path=str(from_rel),
1223
 
                    context_info="Could not rename file")
 
1249
                    context_info=self._getRenameFailedMessage(from_rel,to_rel,))
1224
1250
        from_entry = inv[from_id]
1225
1251
        from_parent_id = from_entry.parent_id
1226
1252
        to_dir, to_tail = os.path.split(to_rel)