Function: magit-version
magit-version is an autoloaded, interactive and byte-compiled function
defined in magit.el.
Signature
(magit-version &optional PRINT-DEST)
Documentation
Return the version of Magit currently in use.
If optional argument PRINT-DEST is non-nil, also print the used versions of Magit, Transient, Git and Emacs to the output stream selected by that argument. Interactively use the echo area, or with a prefix argument use the current buffer. Additionally put the output in the kill ring.
Key Bindings
Source Code
;; Defined in ~/.emacs.d/elpa/magit-20260411.1452/magit.el
;;;###autoload
(defun magit-version (&optional print-dest interactive nowarn)
"Return the version of Magit currently in use.
If optional argument PRINT-DEST is non-nil, also print the used
versions of Magit, Transient, Git and Emacs to the output stream
selected by that argument. Interactively use the echo area, or
with a prefix argument use the current buffer. Additionally put
the output in the kill ring.
\n(fn &optional PRINT-DEST)"
(interactive (list (if current-prefix-arg (current-buffer) t) t))
(let ((magit-git-global-arguments nil)
(toplib (or load-file-name buffer-file-name))
debug)
(unless (and toplib
(member (file-name-nondirectory toplib)
'("magit.el" "magit.el.gz")))
(let ((load-suffixes (reverse load-suffixes))) ; prefer .el than .elc
(setq toplib (locate-library "magit"))))
(setq toplib (and toplib (magit--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 (magit--chase-links static))))
(or (progn
(push 'repo debug)
(when (and (file-exists-p gitdir)
;; It is a repo, but is it the Magit repo?
(file-exists-p
(expand-file-name "../lisp/magit.el" gitdir)))
(push t debug)
;; Inside the repo the version file should only exist
;; while running make.
(when (and static (not noninteractive))
(ignore-errors (delete-file static)))
(setq magit-version
(let ((default-directory topdir))
(magit-git-string "describe"
"--tags" "--dirty" "--always")))))
(progn
(push 'static debug)
(when (and static (file-exists-p static))
(push t debug)
(load-file static)
magit-version))
(when (and (featurep 'package)
(boundp 'package-alist)
(fboundp 'package-version-join))
(push 'elpa debug)
(ignore-errors
(when-let ((version (cadr (assq 'magit package-alist))))
(push t debug)
(setq magit-version
(and (fboundp 'package-desc-version)
(package-version-join
(package-desc-version version)))))))
(progn
(push 'dirname debug)
(let ((dirname (file-name-nondirectory
(directory-file-name topdir))))
(when (string-match "\\`magit-\\([0-9].*\\)" dirname)
(setq magit-version (match-str 1 dirname)))))
;; If all else fails, just report the commit hash. It's
;; better than nothing and we cannot do better in the case
;; of e.g., a shallow clone.
(progn
(push 'hash debug)
;; Same check as above to see if it's really the Magit repo.
(when (and (file-exists-p gitdir)
(file-exists-p
(expand-file-name "../lisp/magit.el" gitdir)))
(setq magit-version
(let ((default-directory topdir))
(magit-git-string "rev-parse" "HEAD"))))))))
(if (stringp magit-version)
(when print-dest
(let* ((alt (or (and (ignore-errors
(magit--version>= magit-version "2008"))
(ignore-errors
(require 'lisp-mnt)
(and (fboundp 'lm-header)
(with-temp-buffer
(insert-file-contents
(locate-library "magit.el" t))
(lm-header "Package-Version")))))))
(str (format
"Magit %s%s, Transient %s,%s Git %s, Emacs %s, %s"
(or magit-version "(unknown)")
(if (and alt (not (equal alt magit-version)))
(format " [>= %s]" alt)
"")
(or (ignore-errors
(require 'lisp-mnt)
(and (fboundp 'lm-header)
(with-temp-buffer
(insert-file-contents
(locate-library "transient.el" t))
(lm-header "Package-Version"))))
"(unknown)")
(let ((lib (locate-library "forge.el" t)))
(or (and lib
(format
" Forge %s,"
(or (ignore-errors
(require 'lisp-mnt)
(with-temp-buffer
(insert-file-contents lib)
(and (fboundp 'lm-header)
(lm-header "Package-Version"))))
"(unknown)")))
""))
(magit--safe-git-version)
emacs-version
system-type)))
(when interactive
(kill-new str))
(princ str print-dest)))
(setq debug (reverse debug))
(setq magit-version 'error)
(when magit-version
(push magit-version debug))
(unless (or nowarn (equal (getenv "CI") "true"))
(message "Cannot determine Magit's version %S" debug)))
magit-version))