问题
I am trying to configure git.el. When i do git-status i can see the status buffer with changed i can also add files using 'a' but when i try to commit a file using c writing the commit log and finishing it with C-c C-c gives me
env: git: No such file or directory
error and file is not committed. I am using emacs 23 on OS X. The only customization i added to my .emacs is
(setq exec-path (append exec-path '("/opt/local/bin")) )
because emacs failed to find git executable.
回答1:
In my .emacs for Mac OS X i have following code:
(when (equal system-type 'darwin)
(setenv "PATH" (concat "/opt/local/bin:/usr/local/bin:" (getenv "PATH")))
(push "/opt/local/bin" exec-path))
It seems, that the problem is, that when you run terminal.app it use your shell initialization file to setup all environment variables, but when you launch Emacs from Dock, then these variables aren't set.
P.S. By the way - there are other packages to work with Git from Emacs - magit, DVC, egg... You can read about them in my article
回答2:
Well, since the beginning of the error line is env:
, it suggests that git.el is using the program "env" to find git and call it. Looking at the source confirms this since all calls to git appear to go through here:
(defun git-call-process-env (buffer env &rest args)
"Wrapper for call-process that sets environment strings."
(if env
(apply #'call-process "env" nil buffer nil
(append (git-get-env-strings env) (list "git") args))
(apply #'call-process "git" nil buffer nil args)))
Scanning through the code showed that in most cases, Emacs calls git directly with call-process
, but it sometimes uses the "env" command, particularly when it needs to pass environment variables (like "GIT_INDEX_FILE").
The problem is that Emacs doesn't pass it's exec-path
to env
when running it via call-process
, so setting exec-path
in Emacs won't help `env' find git.
There are really two solutions:
Figure out how to get
env
to know where git is. I'm afraid I can't really help you on this one, since I don't know how to set up that sort of thing on a Mac, but it should be a fairly straightforward modification of PATH.Hack git.el to pass
PATH=/path/to/git
to env when calling git. This is less clean, but it's not all that bad of a hack, and especially if you made the choice of path into adefcustom
, it could be useful to others.
I would suggest starting out with 1, though. You can change the environment variables for Emacs using:
(setenv "PATH" (concat "/opt/local/bin:" (getenv "PATH")))
And trying git.el then. While Emacs doesn't pass the variable exec-path
to child processes, it does copy along its PATH environment variable from whatever it was invoked with. Since Emacs also calls git directly, you will also need to set exec-path
in the way that you already are.
Hope that helps.
回答3:
A very simple way to solve this problem is to modify the exec path in your .emacs file
(add-to-list 'exec-path "/usr/local/git/bin/")
This does the trick for me.
来源:https://stackoverflow.com/questions/930439/using-git-with-emacs