views:

816

answers:

2

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.

+4  A: 

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:

  1. 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.

  2. 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 a defcustom, 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.

haxney
git executable is in my path. i can type git in terminal also running env git executes git. but still emacs fails to locate it.
Hamza Yerlikaya
+7  A: 

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

Alex Ott