GNU bug report logs - #14459
git vc-annotate fails in detached HEAD state

Previous Next

Package: emacs;

Reported by: claudio.bley <at> gmail.com (Claudio Bley)

Date: Fri, 24 May 2013 13:38:01 UTC

Severity: normal

Fixed in version 24.4

Done: Dmitry Gutov <dgutov <at> yandex.ru>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: help-debbugs <at> gnu.org (GNU bug Tracking System)
To: Dmitry Gutov <dgutov <at> yandex.ru>
Cc: tracker <at> debbugs.gnu.org
Subject: bug#14459: closed (git vc-annotate fails in detached HEAD state)
Date: Mon, 27 May 2013 23:16:02 +0000
[Message part 1 (text/plain, inline)]
Your message dated Tue, 28 May 2013 03:14:04 +0400
with message-id <87bo7w583n.fsf <at> yandex.ru>
and subject line Re: bug#14459: git vc-annotate fails in detached HEAD state
has caused the debbugs.gnu.org bug report #14459,
regarding git vc-annotate fails in detached HEAD state
to be marked as done.

(If you believe you have received this mail in error, please contact
help-debbugs <at> gnu.org.)


-- 
14459: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=14459
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
From: claudio.bley <at> gmail.com (Claudio Bley)
To: bug-gnu-emacs <at> gnu.org
Subject: git vc-annotate fails in detached HEAD state
Date: Fri, 24 May 2013 15:07:37 +0200
Hi.

1. I open a git versioned file with vc-git enabled in a directory
   currently in detached HEAD state (e.g. after checking out a tag)
2. notice the mode line says "Git:!"

Now, when I do

C-x v g (vc-annotate)

The annotation buffer will be displayed, only saying

,----
| fatal: bad revision ''
`----

Apparently, vc-git-working-revision calls "git symbolic-ref HEAD",
which - in this case - gives:

$ git symbolic-ref HEAD
fatal: ref HEAD is not a symbolic ref

So, vc-git-working-revision returns an empty string as the current
"revision" vc-mode refers to.

M-: (vc-git-working-revision (buffer-file-name))

-> ""

When calling vc-annotate, the vc-git-annotate-command gets called with
the empty string for the rev parameter leading to the error.

This patch fixes it for me:

----------------- 8< --------------------- 8< -------------
diff --git a/lisp/vc/vc-git.el b/lisp/vc/vc-git.el
index 06474cb..63a7115 100644
--- a/lisp/vc/vc-git.el
+++ b/lisp/vc/vc-git.el
@@ -885,7 +885,7 @@ or BRANCH^ (where \"^\" can be repeated)."
 
 (defun vc-git-annotate-command (file buf &optional rev)
   (let ((name (file-relative-name file)))
-    (vc-git-command buf 'async nil "blame" "--date=iso" "-C" "-C" rev "--" name)))
+    (vc-git-command buf 'async nil "blame" "--date=iso" "-C" "-C" (if (> (length rev) 0) rev) "--" name)))
 
 (declare-function vc-annotate-convert-time "vc-annotate" (time))
 
-- 
Claudio




[Message part 3 (message/rfc822, inline)]
From: Dmitry Gutov <dgutov <at> yandex.ru>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 14459-done <at> debbugs.gnu.org
Subject: Re: bug#14459: git vc-annotate fails in detached HEAD state
Date: Tue, 28 May 2013 03:14:04 +0400
Version: 24.4

Claudio Bley <claudio.bley <at> googlemail.com> writes:
> Yes, this is way better than what I've come up with. But shouldn't we
> also use the "--short[=n]" option to restrict the length of the
> revision string as it is displayed in the modeline? I think 40 chars
> is a bit long a text taking up precious space in my modeline.

Thanks, I missed that. And also the fact that
`vc-git-mode-line-string' relied on the non-standard return value (empty
string) to determine whether it should add the appropriate help-echo,
("No current branch (detached HEAD)").

I've checked in a more comprehensive patch, using the same help-echo
format in both cases.

Stefan Monnier <monnier <at> iro.umontreal.ca> writes:
> The shortening could also be limited to the modeline.

Done. Shortening the mode-line format in `vc-git-mode-line-string'
wasn't an obvious solution for me, but it seems to work well enough.


This bug report was last modified 12 years and 49 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.