Solving a magit issue with Emacs 26.3
Ping Zhou, 2019-12-18
Some point after my Emacs was upgraded to 26.3, I started seeing errors whenever I try to open file from git repository (i.e. directories with .git subdirectory). The error was annoying as it prevented me from opening files.
So I dig a little into the error and found out that it was from magit (the package that deals with git stuff). The error was caused by wrong argument number provided to function magit-turn-on-auto-revert-mode-if-desired:
(defun magit-turn-on-auto-revert-mode-if-desired (&optional file) (if file (--when-let (find-buffer-visiting file) (with-current-buffer it (magit-turn-on-auto-revert-mode-if-desired))) (when (and buffer-file-name (file-readable-p buffer-file-name) (executable-find magit-git-executable t) ; see #3684 (magit-toplevel) (or (not magit-auto-revert-tracked-only) (magit-file-tracked-p buffer-file-name)) (not auto-revert-mode) ; see #3014 (not global-auto-revert-mode)) ; see #3460 (auto-revert-mode 1))))
The source file is located at .emacs.d/elpa/magit-20191207.2321/magit-autorevert.el
.
Now the problem is that function executable-find
(provided by Emacs 26.3) only takes one argument, while it was given 2 arguments from magit-turn-on-auto-revert-mode-if-desired
:
(executable-find magit-git-executable t)
This was the root cause of the “wrong argument number” error from magit when I tried to open files from git repository.
How to fix? For short-term I just removed the 2nd argument (“t”) from the call:
(executable-find magit-git-executable)
Also I had to remove the pre-compiled file (magit-autorevert.elc
) from the magit directory to make sure my change takes effect. After this I restarted Emacs and the issue was gone. Yeah!
Longer term, this needs to be fixed either in magit or Emacs in future updates.