Subject: bug#39452: [PATCH] vc-git-state fails for filenames with wildcards

From: Dmitry Gutov <[email-masked]>
Date: Sat, 14 Aug 2021 03:11:56 +0300

On 22.07.2021 15:42, Lars Ingebrigtsen wrote:
> Nobody had any opinions, and the "if it's good enough for Magit"
> argument is a good one.  So I went ahead and applied Dmitry's patch to
> Emacs 28, and we'll see whether there's any push back on that...

As luck would have it, I have a bit of code (namely 
project--vc-list-files) that got broken with that change.

Because, when EXTRA-IGNORES are present, it constructs some non-literal 
pathspecs, which naturally fail (get misinterpreted) with 
GIT_LITERAL_PATHSPECS=1.

So we need an escape hatch to turn off this feature, which could take 
form of a dynamic variable, like in the patch below.

Or we could revert to the other approach. What do people think?

diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el
index 714edeba5f..824ea55e7b 100644
--- a/lisp/progmodes/project.el
+++ b/lisp/progmodes/project.el
@@ -523,6 +523,7 @@ project--vc-list-files
      (`Git
       (let ((default-directory (expand-file-name 
(file-name-as-directory dir)))
             (args '("-z"))
+           vc-git-use-literal-pathspecs
             files)
         ;; Include unregistered.
         (setq args (append args
diff --git a/lisp/vc/vc-git.el b/lisp/vc/vc-git.el
index 143087122f..1082e724ff 100644
--- a/lisp/vc/vc-git.el
+++ b/lisp/vc/vc-git.el
@@ -220,6 +220,9 @@ vc-git-revision-complete-only-branches
    :type 'boolean
    :version "28.1")

+(defvar vc-git-use-literal-pathspecs t
+  "Non-nil to interpret all Git pathspecs literally.")
+
  ;; History of Git commands.
  (defvar vc-git-history nil)

@@ -1772,7 +1775,8 @@ vc-git-command
          (process-environment
           (append
            `("GIT_DIR"
-            "GIT_LITERAL_PATHSPECS=1"
+            ,@(when vc-git-use-literal-pathspecs
+                '("GIT_LITERAL_PATHSPECS=1"))
              ;; Avoid repository locking during background operations
              ;; (bug#21559).
              ,@(when revert-buffer-in-progress-p
@@ -1807,8 +1811,9 @@ vc-git--call
  	(process-environment
  	 (append
  	  `("GIT_DIR"
-            "GIT_LITERAL_PATHSPECS=1"
-	    ;; Avoid repository locking during background operations
+            ,@(when vc-git-use-literal-pathspecs
+                '("GIT_LITERAL_PATHSPECS=1"))
+            ;; Avoid repository locking during background operations
  	    ;; (bug#21559).
  	    ,@(when revert-buffer-in-progress-p
  		'("GIT_OPTIONAL_LOCKS=0")))