Subject: bug#43464: 28.0.50; vc: Error calling vc-revert for repo root

From: Andrii Kolomoiets <[email-masked]>
Date: Fri, 18 Sep 2020 18:45:08 +0300

Dmitry Gutov <[email-masked]> writes:

> On 18.09.2020 12:30, Andrii Kolomoiets wrote:
>> Calling `vc-git-revert` or `vc-hg-revert` directly with repo root or any
>> directory within repo works fine.
>
> True. That's how Git and Hg work anyway.
>
> I'm not saying the current situation is ideal, but we'd either have to
> give up any attempt to revert a directory (with a more appropriate
> message), or somehow differentiate between different backends where it
> would or wouldn't work.

BTW vc-revert is also works fine in Git repo when point is on
subdirectory.  So for the vc-git only reverting repo root is not
working.

Please see attached patch which make it possible for vc-hg to revert
directory.

>From 47adbf50d6d3719a9fe9e350897b30917bc1220d Mon Sep 17 00:00:00 2001
From: Andrii Kolomoiets <[email-masked]>
Date: Fri, 18 Sep 2020 18:38:19 +0300
Subject: [PATCH] vc: Treat directory as registered

* lisp/vc/vc-hg.el (vc-hg-registered): Treat directory as registered
* lisp/vc/vc.el (vc-register): Treat directory as unregistered
---
 lisp/vc/vc-hg.el | 5 +++--
 lisp/vc/vc.el    | 3 ++-
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/lisp/vc/vc-hg.el b/lisp/vc/vc-hg.el
index cb0657e70a..fec2235446 100644
--- a/lisp/vc/vc-hg.el
+++ b/lisp/vc/vc-hg.el
@@ -222,8 +222,9 @@ vc-hg-update-on-retrieve-tag
 (defun vc-hg-registered (file)
   "Return non-nil if FILE is registered with hg."
   (when (vc-hg-root file)           ; short cut
-    (let ((state (vc-hg-state file)))  ; expensive
-      (and state (not (memq state '(ignored unregistered)))))))
+    (or (file-directory-p file)
+        (let ((state (vc-hg-state file)))  ; expensive
+          (and state (not (memq state '(ignored unregistered))))))))
 
 (defun vc-hg-state (file)
   "Hg-specific version of `vc-state'."
diff --git a/lisp/vc/vc.el b/lisp/vc/vc.el
index 3852a64550..77ba97fb73 100644
--- a/lisp/vc/vc.el
+++ b/lisp/vc/vc.el
@@ -1370,7 +1370,8 @@ vc-register
       (let ((bname (get-file-buffer fname)))
 	(unless fname
 	  (setq fname buffer-file-name))
-	(when (vc-call-backend backend 'registered fname)
+	(when (and (not (file-directory-p fname))
+                   (vc-call-backend backend 'registered fname))
 	  (error "This file is already registered"))
 	;; Watch out for new buffers of size 0: the corresponding file
 	;; does not exist yet, even though buffer-modified-p is nil.
-- 
2.15.1