]> git.eshelyaron.com Git - emacs.git/commitdiff
* lisp/dired-aux.el (dired-vc-rename-file): New defcustom.
authorJuri Linkov <juri@linkov.net>
Wed, 6 Nov 2019 23:14:58 +0000 (01:14 +0200)
committerJuri Linkov <juri@linkov.net>
Wed, 6 Nov 2019 23:14:58 +0000 (01:14 +0200)
(dired-rename-file): Call vc-rename-file when dired-vc-rename-file is non-nil.

* lisp/vc/vc.el (vc-rename-file): Allow renaming added files.
Call vc-file-clearprops on new file too for the case when
old and new files were renamed to each other back and forth.

https://lists.gnu.org/archive/html/emacs-devel/2019-11/msg00069.html

etc/NEWS
lisp/dired-aux.el
lisp/vc/vc.el

index 737053a099a4e8f21e219c3450c869286bf4c35e..4d5d9f2a7d6c17c18b41817024655c19e4614c0c 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -846,6 +846,9 @@ directories in the destination.
 *** The non-nil value of 'dired-dwim-target' uses one of the most recently
 visited windows with a Dired buffer instead of the next window.
 
+*** When the new user option 'dired-vc-rename-file' is non-nil,
+Dired performs file renaming using underlying version control system.
+
 ** Find-Dired
 
 *** New user option 'find-dired-refine-function'.
index b1521ecf01871825656ef2936be29e5ebe9e3908..722d036e3fc769b01ce68642d205f3a6cfa12d35 100644 (file)
@@ -1635,11 +1635,26 @@ If `ask', ask for user confirmation."
               dired-create-files-failures)
         (dired-log "Can't set date on %s:\n%s\n" from err))))))
 
+(defcustom dired-vc-rename-file nil
+  "Whether Dired should register file renaming in underlying vc system.
+If nil, use default `rename-file'.
+If non-nil and the renamed files are under version control,
+rename them using `vc-rename-file'."
+  :type '(choice (const :tag "Use rename-file" nil)
+                 (const :tag "Use vc-rename-file" t))
+  :group 'dired
+  :version "27.1")
+
 ;;;###autoload
 (defun dired-rename-file (file newname ok-if-already-exists)
   (dired-handle-overwrite newname)
   (dired-maybe-create-dirs (file-name-directory newname))
-  (rename-file file newname ok-if-already-exists) ; error is caught in -create-files
+  (if (and dired-vc-rename-file
+           (vc-backend file)
+           (ignore-errors (vc-responsible-backend newname)))
+      (vc-rename-file file newname)
+    ;; error is caught in -create-files
+    (rename-file file newname ok-if-already-exists))
   ;; Silently rename the visited file of any buffer visiting this file.
   (and (get-file-buffer file)
        (with-current-buffer (get-file-buffer file)
index c982b0220e3d012b1b2b0fa17b65b4d42283ca87..20056dec7f901db6e75162917aac8bced64f1b18 100644 (file)
@@ -2913,11 +2913,12 @@ current buffer's file name if it's under version control."
     (when (file-exists-p new)
       (error "New file already exists"))
     (let ((state (vc-state old)))
-      (unless (memq state '(up-to-date edited))
+      (unless (memq state '(up-to-date edited added))
        (error "Please %s files before moving them"
               (if (stringp state) "check in" "update"))))
     (vc-call rename-file old new)
     (vc-file-clearprops old)
+    (vc-file-clearprops new)
     ;; Move the actual file (unless the backend did it already)
     (when (file-exists-p old) (rename-file old new))
     ;; ?? Renaming a file might change its contents due to keyword expansion.