5

I'm using Emacs 24 on OS X 10.6.8. Doing magit-status says

Searching for program: no such file or directory, git

However, the Emacs shell is able to find git, so this does not seem to be a $PATH issue. What else could it be?

BartoszKP
  • 34,786
  • 15
  • 102
  • 130
Pranav
  • 3,340
  • 8
  • 35
  • 48
  • 1
    The emacs shell reads the shell startup file which needn't apply to Emacs, so it could still be a `$PATH` issue. Evaluate `(insert (getenv "PATH"))` in a buffer to see the value of `PATH` Emacs uses to start external commands. – user4815162342 Sep 12 '12 at 19:22

2 Answers2

5

Try checking the value of exec-path variable. This controls the directories which are looked by Emacs for external executables (including git).

This is a customizable variable, and you can add the path to git to the list of existing directories.

I have the elisp snippet in my .emacs.d/init.el file for my Emacs install under OSX, which sets both the PATH and exec-path correctly.

;;; Set localized PATH for OS X
(defun my-add-path (path-element)
  "Add the specified PATH-ELEMENT to the Emacs PATH."
  (interactive "DEnter directory to be added to path: ")
  (if (file-directory-p path-element)
     (progn
       (setenv "PATH" (concat (expand-file-name path-element) path-separator (getenv "PATH")))
       (add-to-list 'exec-path (expand-file-name path-element)))))

(if (fboundp 'my-add-path)
   (let ((my-paths (list "/opt/local/bin" "/usr/local/bin" "/usr/local/git/bin")))
      (dolist (path-to-add my-paths (getenv "PATH"))
         (my-add-path path-to-add))))
Anupam
  • 1,470
  • 2
  • 11
  • 7
  • You need to parse the files under `/etc/path.d/`, too, or executables from 3rd party installers will not be available. Prominent example is MacTeX which puts executables into `/usr/texbin/`. –  Sep 13 '12 at 10:52
1

Emacs on OS X uses the system-wide environment variables, which can be overridden by creating a magic environment.plist XML file in the right directory. A better solution, though, is to have Emacs copy the value of $PATH from your shell, so that it matches what you see in Terminal.app.

@Anupam's answer is based on a snippet of code which I originally wrote for this purpose, but I've now improved that code and published it as a little elisp library called exec-path-from-shell which you can install from Marmalade or Melpa.

sanityinc
  • 15,002
  • 2
  • 49
  • 43
  • +1 for the idea of getting `$PATH` from the shell and putting this idea into a package. –  Sep 13 '12 at 10:50