Skip to content

Commit

Permalink
magit-version: Handle Straight's fake symlinks
Browse files Browse the repository at this point in the history
Add a new function `magit--straight-chase-links' to do so.
Closes radian-software/straight.el#520.
  • Loading branch information
raxod502 authored and tarsius committed Jun 11, 2020
1 parent a6d0fa4 commit 6eba95f
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions lisp/magit.el
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,20 @@ is run in the top-level directory of the current working tree."
"The version of Magit that you're using.
Use the function by the same name instead of this variable.")

(defun magit--straight-chase-links (filename)
"Chase links in FILENAME until a name that is not a link.
This is the same as `file-chase-links', except that it also
handles fake symlinks that are created by the package manager
straight.el on Windows.
See <https://github.com/raxod502/straight.el/issues/520>."
(when (and (bound-and-true-p straight-symlink-emulation-mode)
(fboundp 'straight-chase-emulated-symlink))
(when-let ((target (straight-chase-emulated-symlink filename)))
(unless (eq target 'broken)
(setq filename target))))
(file-chase-links filename))

;;;###autoload
(defun magit-version (&optional print-dest)
"Return the version of Magit currently in use.
Expand All @@ -403,15 +417,15 @@ and Emacs to it."
(unless (and toplib
(equal (file-name-nondirectory toplib) "magit.el"))
(setq toplib (locate-library "magit.el")))
(setq toplib (and toplib (file-chase-links toplib)))
(setq toplib (and toplib (magit--straight-chase-links toplib)))
(push toplib debug)
(when toplib
(let* ((topdir (file-name-directory toplib))
(gitdir (expand-file-name
".git" (file-name-directory
(directory-file-name topdir))))
(static (locate-library "magit-version.el" nil (list topdir)))
(static (and static (file-chase-links static))))
(static (and static (magit--straight-chase-links static))))
(or (progn
(push 'repo debug)
(when (and (file-exists-p gitdir)
Expand Down

0 comments on commit 6eba95f

Please sign in to comment.