changeset 4991:9da6c6c24ddd

(vc-rename-file): Don't overwrite an existing file. Fix test for unsaved files. Calculate name of new master file properly.
author Richard M. Stallman <rms@gnu.org>
date Fri, 12 Nov 1993 22:31:12 +0000
parents 8f5a44af0114
children 8a3293abe1ba
files lisp/vc.el
diffstat 1 files changed, 27 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/vc.el	Fri Nov 12 22:16:44 1993 +0000
+++ b/lisp/vc.el	Fri Nov 12 22:31:12 1993 +0000
@@ -1137,19 +1137,38 @@
   "Rename file OLD to NEW, and rename its master file likewise."
   (interactive "fVC rename file: \nFRename to: ")
   (let ((oldbuf (get-file-buffer old)))
-    (if (buffer-modified-p oldbuf)
+    (if (and oldbuf (buffer-modified-p oldbuf))
 	(error "Please save files before moving them"))
     (if (get-file-buffer new)
 	(error "Already editing new file name"))
+    (if (file-exists-p new)
+	(error "New file already exists"))
     (let ((oldmaster (vc-name old)))
       (if oldmaster
-	(if (vc-locking-user old)
-	    (error "Please check in files before moving them"))
-	(if (or (file-symlink-p oldmaster)
-		;; This had FILE, I changed it to OLD. -- rms.
-		(file-symlink-p (vc-backend-subdirectory-name old)))
-	    (error "This is not a safe thing to do in the presence of symbolic links"))
-	(rename-file oldmaster (vc-name new)))
+	  (progn
+	    (if (vc-locking-user old)
+		(error "Please check in files before moving them"))
+	    (if (or (file-symlink-p oldmaster)
+		    ;; This had FILE, I changed it to OLD. -- rms.
+		    (file-symlink-p (vc-backend-subdirectory-name old)))
+		(error "This is not a safe thing to do in the presence of symbolic links"))
+	    (rename-file
+	     oldmaster
+	     (let ((backend (vc-backend-deduce old))
+		   (newdir (or (file-name-directory new) ""))
+		   (newbase (file-name-nondirectory new)))
+	       (catch 'found
+		 (mapcar
+		  (function
+		   (lambda (s)
+		     (if (eq backend (cdr s))
+			 (let* ((newmaster (format (car s) newdir newbase))
+				(newmasterdir (file-name-directory newmaster)))
+			   (if (or (not newmasterdir)
+				   (file-directory-p newmasterdir))
+			       (throw 'found newmaster))))))
+		  vc-master-templates)
+		 (error "New file lacks a version control directory"))))))
       (if (or (not oldmaster) (file-exists-p old))
 	  (rename-file old new)))
 ; ?? Renaming a file might change its contents due to keyword expansion.