Subject: Re: bug#26066: 26.0.50; vc-git-status gives wrong result

From: Jonathan Ganc <[email-masked]>
Date: Fri, 17 Mar 2017 22:38:07 -0400

Hi.

I have never submitted an emacs patch before so I don't know if I am 
doing this correctly (or if one of you has already submitted a fix). I 
have attached a patch file.

Later, I will submit the more elegant fix.

On 03/15/2017 08:48 PM, Dmitry Gutov wrote:
> On 16.03.2017 02:42, [email-masked] wrote:
>> As an aside, is there a reason that vc-git-status does not use "git
>> status -z --porcelain --ignored"? It seems more natural/straightfoward
>> and it would also deal with ignored and removed files. It could also
>> work with directories, which the current function doesn't.
>
> Like mentioned in a discussion on a different bug, we'll accept a 
> patch like that. You can even reuse some code from 
> `vc-git-conflicted-files`.

>From 85a9df8a15b32dc7d884efa74e53c6d20fabaee6 Mon Sep 17 00:00:00 2001
From: Jonathan Ganc <[email-masked]>
Date: Fri, 17 Mar 2017 22:35:46 -0400
Subject: [PATCH] Fix default-directory for vc-git (Bug#2606)

---
 lisp/vc/vc-git.el | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/lisp/vc/vc-git.el b/lisp/vc/vc-git.el
index 1a3f1bf..6f20a8d 100644
--- a/lisp/vc/vc-git.el
+++ b/lisp/vc/vc-git.el
@@ -244,8 +244,12 @@ (defun vc-git-state (file)
   ;; This assumes that status is known to be not `unregistered' because
   ;; we've been successfully dispatched here from `vc-state', that
   ;; means `vc-git-registered' returned t earlier once.  Bug#11757
-  (let ((diff (vc-git--run-command-string
-               file "diff-index" "-p" "--raw" "-z" "HEAD" "--")))
+
+  ;; `default-directory' determines where vc-git-... looks for the
+  ;; local git repository
+  (let* ((default-directory (file-name-directory file))
+         (diff (vc-git--run-command-string
+                file "diff-index" "-p" "--raw" "-z" "HEAD" "--")))
     (if (and diff
              (string-match ":[0-7]\\{6\\} [0-7]\\{6\\} [0-9a-f]\\{40\\} [0-9a-f]\\{40\\} \\([ADMUT]\\)\0[^\0]+\0\\(.*\n.\\)?"
                            diff))
-- 
2.9.3