From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Ashwin Kafle Newsgroups: gmane.emacs.bugs Subject: bug#52507: [PATCH] Option for vc-delete-file to keep file on disk Date: Wed, 15 Dec 2021 15:38:24 +0545 Message-ID: <20211215095324.18195-1-ashwin@ashwink.com.np> Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="40856"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Ashwin Kafle , Dmitry Gutov To: 52507@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Dec 15 14:54:35 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mxUjr-000AUh-8G for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 15 Dec 2021 14:54:35 +0100 Original-Received: from localhost ([::1]:55602 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mxUjp-000091-Te for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 15 Dec 2021 08:54:33 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:53126) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mxTpC-0000Xz-Ty for bug-gnu-emacs@gnu.org; Wed, 15 Dec 2021 07:56:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:48897) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mxTpC-0004sU-KR for bug-gnu-emacs@gnu.org; Wed, 15 Dec 2021 07:56:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mxTpC-0006gI-KK for bug-gnu-emacs@gnu.org; Wed, 15 Dec 2021 07:56:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Ashwin Kafle Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 15 Dec 2021 12:56:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 52507 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.163957292125610 (code B ref -1); Wed, 15 Dec 2021 12:56:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 15 Dec 2021 12:55:21 +0000 Original-Received: from localhost ([127.0.0.1]:60439 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mxToW-0006ey-5k for submit@debbugs.gnu.org; Wed, 15 Dec 2021 07:55:21 -0500 Original-Received: from lists.gnu.org ([209.51.188.17]:55346) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mxQy7-00082i-J2 for submit@debbugs.gnu.org; Wed, 15 Dec 2021 04:53:03 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:56468) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mxQy7-0000xk-BA for bug-gnu-emacs@gnu.org; Wed, 15 Dec 2021 04:53:03 -0500 Original-Received: from mail.cock.li ([37.120.193.124]:35494) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mxQy4-0004zK-Nh for bug-gnu-emacs@gnu.org; Wed, 15 Dec 2021 04:53:02 -0500 X-Mailer: git-send-email 2.34.1 Received-SPF: pass client-ip=37.120.193.124; envelope-from=birdsite@airmail.cc; helo=mail.cock.li X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, HEADER_FROM_DIFFERENT_DOMAINS=0.249, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Wed, 15 Dec 2021 07:55:18 -0500 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:222421 Archived-At: Add a prefix argument on vc-delete-file to keep affected file on disk and keep the current buffer intact. This option relies on the backends to not delete files themselves. * doc/emacs/vc1-xtra.texi: Document the change. * lisp/vc/vc-git.el: Make git leave files on disk. * lisp/vc/vc.el: Change vc-delete-file to accept optional prefix argument. --- I've already signed the copyright papers. doc/emacs/vc1-xtra.texi | 3 ++- etc/NEWS | 4 ++++ lisp/vc/vc-git.el | 4 ++-- lisp/vc/vc.el | 20 +++++++++++--------- 4 files changed, 19 insertions(+), 12 deletions(-) diff --git a/doc/emacs/vc1-xtra.texi b/doc/emacs/vc1-xtra.texi index 4cd00cba6c..2cf69583b3 100644 --- a/doc/emacs/vc1-xtra.texi +++ b/doc/emacs/vc1-xtra.texi @@ -122,7 +122,8 @@ VC Delete/Rename If you wish to delete a version-controlled file, use the command @kbd{M-x vc-delete-file}. This prompts for the file name, and deletes it via the version control system. The file is removed from the -working tree, and in the VC Directory buffer +working tree, and in the VC Directory buffer. If you give a prefix argument, +the file is not deleted from disk. @iftex (@pxref{VC Directory Mode,,, emacs, the Emacs Manual}), @end iftex diff --git a/etc/NEWS b/etc/NEWS index 8d83b2a7e3..2469060a3d 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -372,6 +372,10 @@ info node. This command only works for the Emacs and Emacs Lisp manuals. ** vc +*** 'C-x v x' accepts a prefix argument to keep file on disk +Previously 'C-x v x' always deleted the selected file. Now if you give it +prefix argument, it will keep the buffer and file on disk intact. +Currently this is only implemented for vc-git. --- *** 'C-x v v' on an unregistered file will now use the most specific backend. Previously, if you had an SVN-covered "~/" directory, and a Git-covered diff --git a/lisp/vc/vc-git.el b/lisp/vc/vc-git.el index 5c6a39aec9..69ef216529 100644 --- a/lisp/vc/vc-git.el +++ b/lisp/vc/vc-git.el @@ -1569,8 +1569,8 @@ vc-git-next-revision (or (vc-git-symbolic-commit next-rev) next-rev))) (defun vc-git-delete-file (file) - (vc-git-command nil 0 (vc-git--literal-pathspec file) "rm" "-f" "--")) - + (vc-git-command nil 0 (vc-git--literal-pathspec file) "rm" "-f" "--cached" "--")) +) (defun vc-git-rename-file (old new) (vc-git-command nil 0 (list old new) "mv" "-f" "--")) diff --git a/lisp/vc/vc.el b/lisp/vc/vc.el index 64f752f248..43fc0e787e 100644 --- a/lisp/vc/vc.el +++ b/lisp/vc/vc.el @@ -2970,14 +2970,13 @@ vc-transfer-file (vc-checkin file new-backend comment (stringp comment))))) ;;;###autoload -(defun vc-delete-file (file) +(defun vc-delete-file (file &optional keep-file) "Delete file and mark it as such in the version control system. If called interactively, read FILE, defaulting to the current -buffer's file name if it's under version control." - (interactive (list (read-file-name "VC delete file: " nil - (when (vc-backend buffer-file-name) - buffer-file-name) - t))) +buffer's file name if it's under version control. +If a prefix argument is given (optional argument KEEP-FILE) then +don't delete the file from the disk" + (interactive "f\nP") (setq file (expand-file-name file)) (let ((buf (get-file-buffer file)) (backend (vc-backend file))) @@ -2999,19 +2998,22 @@ vc-delete-file (unless (or (file-directory-p file) (null make-backup-files) (not (file-exists-p file))) (with-current-buffer (or buf (find-file-noselect file)) - (let ((backup-inhibited nil)) + (let ((backup-inhibited nil) + ;; if you don't set this, then for some reason, the file is never brought back + (backup-by-copying t)) (backup-buffer)))) ;; Bind `default-directory' so that the command that the backend ;; runs to remove the file is invoked in the correct context. (let ((default-directory (file-name-directory file))) (vc-call-backend backend 'delete-file file)) ;; If the backend hasn't deleted the file itself, let's do it for him. - (when (file-exists-p file) (delete-file file)) + (when (and (file-exists-p file) (null keep-file)) + (delete-file file)) ;; Forget what VC knew about the file. (vc-file-clearprops file) ;; Make sure the buffer is deleted and the *vc-dir* buffers are ;; updated after this. - (vc-resynch-buffer file nil t))) + (vc-resynch-buffer file keep-file t))) ;;;###autoload (defun vc-rename-file (old new) -- 2.34.1