bug#81625: 31.0.60; vc-git-status can return incorrect status information

Lester Longley via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <[email protected]>
Newsgroups gmane.emacs.bugs
Message-ID <CAA30959aCsSTdkh8xwKW8bGUiGmZ+f8y0zOtXikqNFHfR94FNw@mail.gmail.com>
Hello

On Sat, Aug 15, 2026 at 4:55 PM Lester Longley <[email protected]> wrote:
> The subject of this bug should have specified re: "vc-git-state",
> rather than "vc-git-status". (Apologies)

On Sat, Aug 15, 2026 at 1:35 PM Lester Longley via Bug reports for GNU
Emacs, the Swiss army knife of text editors <[email protected]>
wrote:
> It seems to me that one solution would be for `vc-git-state' to
> post-process the `status',
> as returned from (status (apply #'vc-git--run-command-string file args)),
> so as to match up the returned info. with the specified `file'.

Here's my proposed fix, to `vc-git-state' (in lisp/vc/vc-git.el),
which uses `seq-filter` to narrow the "git status" results
to only those records which correspond directly to the `file' whose
state is being analyzed.

Regards,
Lester
vc-git.diff (application/octet-stream, 1.2 KB)
diff --git i/lisp/vc/vc-git.el w/lisp/vc/vc-git.el
index 6b9530c9570..e5646e1c917 100644
--- i/lisp/vc/vc-git.el
+++ w/lisp/vc/vc-git.el
@@ -414,7 +414,8 @@ in the order given by `git status'."
             ,@(when (version<= "1.7.6.3" (vc-git--program-version))
                 '("--ignored"))
             "--"))
-        (status (apply #'vc-git--run-command-string file args)))
+        (status (apply #'vc-git--run-command-string file args))
+        (file-git (file-relative-name file (vc-git-root default-directory))))
     (if (null status)
         ;; If status is nil, there was an error calling git, likely because
         ;; the file is not in a git repo.
@@ -425,7 +426,10 @@ in the order given by `git status'."
       (vc-git--git-status-to-vc-state
        (mapcar (lambda (s)
                  (substring s 0 2))
-               (split-string status "\0" t))))))
+               ;; #81625 - Narrow 'git status' results to that for `file[-git]'
+               (seq-filter (lambda (s)
+                             (equal file-git (substring s 3)))
+                           (split-string status "\0" t)))))))
 
 (defun vc-git-working-revision (_file)
   "Git-specific version of `vc-working-revision'."
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.