>From 7eb35ef941df7620c99a43f4656b0737b16f67c4 Mon Sep 17 00:00:00 2001 From: dickmao Date: Fri, 21 Oct 2022 13:35:52 -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 X. 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 | 25 ++++++++----------------- test/lisp/vc/vc-git-tests.el | 21 +++++++++++++++++++++ 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/lisp/vc/vc-git.el b/lisp/vc/vc-git.el index 3c6afec0378..ea0d5b78249 100644 --- a/lisp/vc/vc-git.el +++ b/lisp/vc/vc-git.el @@ -374,31 +374,22 @@ 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: " + (get-text-property 0 'commit 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..f8ee92bbe74 100644 --- a/test/lisp/vc/vc-git-tests.el +++ b/test/lisp/vc/vc-git-tests.el @@ -56,6 +56,27 @@ 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) + ,@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") + (vc-git-register (split-string "foo")) + (vc-git-checkin (split-string "foo") "his fooness") + (vc-git-checkout nil (vc-git--rev-parse "HEAD" t)) + (with-current-buffer (find-file-noselect "foo") + (vc-git-mode-line-string (buffer-file-name))))) + (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