branch: elpa/git-commit
commit fc485bae0da283a8d5ae319ac287c2a7c79ea5d4
Author: Kyle Meyer <k...@kyleam.com>
Commit: Kyle Meyer <k...@kyleam.com>

    magit-insert-remote-branches: Skip HEAD if not symref
    
    magit-insert-remote-branches strips the remote name from the short
    refname (e.g., "origin/foo") when magit-refs-show-remote-prefix is
    nil.  That can trigger an error if 1) the remote is mis-configured in
    a way where for-each-ref reports an empty symref field for the HEAD
    ref and 2) the Git version is recent enough to shorten the HEAD ref to
    "$remote" instead of "$remote/HEAD".
    
    Note that mis-configuring a remote in such a way isn't as easy as just
    checking out a detached HEAD in the remote repo (git-clone won't
    create the HEAD ref in that case) or creating an ambiguous
    refs/heads/HEAD branch in the remote repo (git-clone will still use
    the regular HEAD symref in that case).  The key pieces of the
    problematic remotes reported in gh-5092 are 1) an ambiguous
    refs/heads/HEAD and 2) the regular HEAD symref pointing to a ref that
    does not exist.
    
    Replaces #5092.
---
 lisp/magit-refs.el | 22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)

diff --git a/lisp/magit-refs.el b/lisp/magit-refs.el
index 31bbf62448..ea046ae842 100644
--- a/lisp/magit-refs.el
+++ b/lisp/magit-refs.el
@@ -578,14 +578,18 @@ line is inserted at all."
                        (cl-substitute nil ""
                                       (split-string line "\0")
                                       :test #'equal)))
-            (if head-branch
-                ;; Note: Use `ref' instead of `branch' for the check
-                ;; below because 'refname:short' shortens the remote
-                ;; HEAD to '<remote>' instead of '<remote>/HEAD' as of
-                ;; Git v2.40.0.
-                (progn (cl-assert
-                        (equal ref (concat "refs/remotes/" remote "/HEAD")))
-                       (setq head head-branch))
+            (cond
+             (head-branch
+              ;; Note: Use `ref' instead of `branch' for the check
+              ;; below because 'refname:short' shortens the remote
+              ;; HEAD to '<remote>' instead of '<remote>/HEAD' as of
+              ;; Git v2.40.0.
+              (cl-assert
+               (equal ref (concat "refs/remotes/" remote "/HEAD")))
+              (setq head head-branch))
+             ((not (equal ref (concat "refs/remotes/" remote "/HEAD")))
+              ;; ^ Skip mis-configured remotes where HEAD is not a
+              ;; symref.  See #5092.
               (when (magit-refs--insert-refname-p branch)
                 (magit-insert-section (branch branch t)
                   (let ((headp (equal branch head))
@@ -605,7 +609,7 @@ line is inserted at all."
                       (and msg (magit-log-propertize-keywords nil msg))))
                   (when (magit-buffer-margin-p)
                     (magit-refs--format-margin branch))
-                  (magit-refs--insert-cherry-commits branch)))))))
+                  (magit-refs--insert-cherry-commits branch))))))))
       (insert ?\n)
       (magit-make-margin-overlay nil t))))
 

Reply via email to