Subject: Re: bug#51460: emacs-magit: path error during commit

From: Kyle Meyer <[email-masked]>
Date: Sat, 26 Feb 2022 17:54:29 -0500

Hello,

I came across this bug report when searching for something else.  In
case it helps...

Christopher Howard writes:

> Hello, for a long time I've struggled with getting a path error when I
> try to do a commit using emacs-magit. Here is an example log copied from
> the magit-process buffer:
>
> ```
>   0 git … add -u -- Genesis/gen_1.org
>   1 git … commit --
> hint: Waiting for your editor to close the file...
> Waiting for Emacs...
> *ERROR*: Searching for program: No such file or directory, git
> error: There was a problem with the editor
> '/gnu/store/dpky3z5844bclhswdk69z90vayy65b58-emacs-27.2/bin/emacsclient
> --socket-name=/run/user/1000/emacs/server'.
> Please supply the message using either -m or -F option.
> ```

In Magit v3.3.0 and earlier, this error matches what you would see if
"git" isn't in $PATH for the editor that pops up.  This is true even
when magit-git-executable points to an executable.

In the development version of Magit, this should no longer happen as of
77255776 (git-commit: Use magit-git-executable function if available,
2022-02-21).  The issue that prompted that is
<https://github.com/magit/with-editor/issues/106>.  (I know that below
you say you don't use GitHub, but for others that may find that useful.)

(Based on what you say below, it sounds like "git" should be in $PATH,
so things aren't quite adding up still.)

> I find this confusing because
> - I can use magit to stage my commits
> - In the Magit Group (M-x customize-group magit), the Magit Git
> Executable is set to /home/christopher/.guix-profile/bin/git, and that
> file does exist in my profile.
> - /gnu/store/dpky3z5844bclhswdk69z90vayy65b58-emacs-27.2/bin/emacsclient 
> also does exist

Yes, staging and most of things in Magit respect magit-git-executable.
As I mention above and you suspect in the quoted text below, that value
wasn't consulted by the code path relevant for the error above (in
git-commit.el).

> - Within emacs, I can run the shell command M-! git commit or M-! git
> commit -m "..." and this works fine.

Hmm, so your main Emacs session has "git" on its exec-path.  Perhaps
there's something going on with the with-editor launched editor.  I'd
suggest looking at with-editor-debug and seeing if
/home/christopher/.guix-profile/bin is in the path it reports.

> I suspect that emacs-magit might not be properly using the Magit Git
> Executable path for this action, but haven't had a chance to look at the
> source code yet.

Yep, that's it, and, as I mentioned above, should be fixed by 77255776
(git-commit: Use magit-git-executable function if available,
2022-02-21).