unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: dick <dick.r.chiang@gmail.com>
To: 58709@debbugs.gnu.org
Subject: bug#58709: 29.0.50; [PATCH] Fallout 307ad21
Date: Sat, 22 Oct 2022 08:35:59 -0400	[thread overview]
Message-ID: <87r0z0yr0w.fsf@dick> (raw)
In-Reply-To: <87czal12oi.fsf@dick> (dick's message of "Fri, 21 Oct 2022 13:55:57 -0400")

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: 0001-Fallout-307ad21.patch --]
[-- Type: text/x-diff, Size: 4111 bytes --]

From 2ad882ac82cbb03674699f09c98bdb5e7481843b Mon Sep 17 00:00:00 2001
From: dickmao <dick.r.chiang@gmail.com>
Date: Sat, 22 Oct 2022 08:33:53 -0400
Subject: [PATCH] Fallout 307ad21

* lisp/vc/vc-git.el (vc-git-working-revision):
For better or worse, 307ad21 dupes vc-git--symbolic-ref
into this function.  Throw the sha1 onto the retval as a hack
to recover sha1.
(vc-git-mode-line-string): Recover the sha1 for John Q. User.
* test/lisp/vc/vc-git-tests.el (vc-git-test--mock-repo):
(vc-git-test-detached-head): Test the failure when
vc-refresh-state goes after a detached HEAD branch.
---
 lisp/vc/vc-git.el            | 26 +++++++++-----------------
 test/lisp/vc/vc-git-tests.el | 25 +++++++++++++++++++++++++
 2 files changed, 34 insertions(+), 17 deletions(-)

diff --git a/lisp/vc/vc-git.el b/lisp/vc/vc-git.el
index 3c6afec0378..8682770635d 100644
--- a/lisp/vc/vc-git.el
+++ b/lisp/vc/vc-git.el
@@ -374,31 +374,23 @@ vc-git-state
 (defun vc-git-working-revision (_file)
   "Git-specific version of `vc-working-revision'."
   (let* ((process-file-side-effects nil)
-         (commit (vc-git--rev-parse "HEAD" t)))
-    (or (vc-git-symbolic-commit commit) commit)))
-
-(defun vc-git--symbolic-ref (file)
-  (or
-   (vc-file-getprop file 'vc-git-symbolic-ref)
-   (let* (process-file-side-effects
-          (str (vc-git--run-command-string nil "symbolic-ref" "HEAD")))
-     (vc-file-setprop file 'vc-git-symbolic-ref
-                      (if str
-                          (if (string-match "^\\(refs/heads/\\)?\\(.+\\)$" str)
-                              (match-string 2 str)
-                            str))))))
+         (commit (vc-git--rev-parse "HEAD" t))
+         (name (vc-git-symbolic-commit commit)))
+    (or (prog1 name
+          (add-text-properties 0 (length name) `(commit ,commit) name))
+        commit)))
 
 (defun vc-git-mode-line-string (file)
   "Return a string for `vc-mode-line' to put in the mode line for FILE."
   (let* ((rev (vc-working-revision file 'Git))
-         (disp-rev (or (vc-git--symbolic-ref file)
-                       (and rev (substring rev 0 7))))
          (def-ml (vc-default-mode-line-string 'Git file))
          (help-echo (get-text-property 0 'help-echo def-ml))
          (face   (get-text-property 0 'face def-ml)))
-    (propertize (concat (substring def-ml 0 4) disp-rev)
+    (propertize (concat (substring def-ml 0 4) rev)
                 'face face
-                'help-echo (concat help-echo "\nCurrent revision: " rev))))
+                'help-echo (concat help-echo "\nCurrent revision: "
+                                   (when rev
+                                     (or (get-text-property 0 'commit rev) rev))))))
 
 (cl-defstruct (vc-git-extra-fileinfo
             (:copier nil)
diff --git a/test/lisp/vc/vc-git-tests.el b/test/lisp/vc/vc-git-tests.el
index dc9641ed46b..c46e1c55942 100644
--- a/test/lisp/vc/vc-git-tests.el
+++ b/test/lisp/vc/vc-git-tests.el
@@ -56,6 +56,31 @@ vc-git-test-program-version-invalid-leading-dot
    "git version .2.30.1.5"
    "0"))
 
+(defmacro vc-git-test--mock-repo (&rest body)
+  (declare (indent defun))
+  `(let* ((dir (make-temp-file "vc-git-tests" t))
+          (default-directory dir))
+     (unwind-protect
+         (progn
+           (vc-git-create-repo)
+           (vc-git-command nil 0 nil "config" "--add" "user.name" "frou")
+           ,@body)
+       (delete-directory dir t))))
+
+(ert-deftest vc-git-test-detached-head ()
+  (skip-unless (executable-find vc-git-program))
+  (require 'log-edit)
+  (vc-git-test--mock-repo
+    (with-temp-file "foo")
+    (condition-case err
+        (progn
+          (vc-git-register (split-string "foo"))
+          (vc-git-checkin (split-string "foo") "No-Verify: yes
+his fooness")
+          (vc-git-checkout nil (vc-git--rev-parse "HEAD" t)))
+      (error (signal (car err) (with-current-buffer "*vc*" (buffer-string)))))
+    (find-file-noselect "foo")))
+
 (defun vc-git-test--run-program-version-test
     (mock-version-string expected-output)
   (cl-letf* (((symbol-function 'vc-git--run-command-string)
-- 
2.36.1






  reply	other threads:[~2022-10-22 12:35 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-21 17:55 bug#58709: 29.0.50; [PATCH] Fallout 307ad21 dick
2022-10-22 12:35 ` dick [this message]
2022-10-24 19:39 ` Juri Linkov
2022-10-26  7:16   ` Philip Kaludercic
2022-11-07 17:39     ` Matt Armstrong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87r0z0yr0w.fsf@dick \
    --to=dick.r.chiang@gmail.com \
    --cc=58709@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).