Skip to content

Commit

Permalink
Use the "real" git of Git for Windows 2+
Browse files Browse the repository at this point in the history
Git for Windows 2.x reorganized the directory structure so both cmd/git
and bin/git are just wrappers that call the real thing.  Try to find and
use the "real" one instead (it's faster) by executing `which' via the
wrapper.  We also need to set PATH so that git can find all its
utitilities and dlls, this can be retrieved from the wrapper as well.

close #2259
  • Loading branch information
npostavs committed Oct 2, 2015
1 parent 5e1163b commit 724ea52
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 14 deletions.
33 changes: 25 additions & 8 deletions lisp/magit-git.el
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@
"Git and other external processes used by Magit."
:group 'magit)

(defvar magit-git-environment nil
"Prepended to `process-environment' while running git.")

(defcustom magit-git-executable
;; Git might be installed in a different location on a remote, so
;; it is better not to use the full path to the executable, except
Expand All @@ -58,14 +61,28 @@
;; than using "bin/git.exe" directly.
(or (and (eq system-type 'windows-nt)
(--when-let (executable-find "git.exe")
(let ((alt (directory-file-name (file-name-directory it))))
(if (and (equal (file-name-nondirectory alt) "cmd")
(setq alt (expand-file-name
(convert-standard-filename "bin/git.exe")
(file-name-directory alt)))
(file-executable-p alt))
alt
it))))
(or (with-temp-buffer
(when (save-excursion
(= (call-process
it nil '(t t) nil "-c"
"alias.exe=!which git | cygpath -wf -" "exe") 0))
(prog1 (delete-and-extract-region 1 (line-end-position))
(save-excursion
(insert "PATH=")
(call-process
it nil '(t t) nil "-c"
"alias.path=!cygpath -wp \"$PATH\"" "path"))
(setq magit-git-environment
(buffer-substring-no-properties
(point) (line-end-position))))))
(let ((alt (directory-file-name (file-name-directory it))))
(if (and (equal (file-name-nondirectory alt) "cmd")
(setq alt (expand-file-name
(convert-standard-filename "bin/git.exe")
(file-name-directory alt)))
(file-executable-p alt))
alt
it)))))
"git")
"The Git executable used by Magit."
:group 'magit-process
Expand Down
13 changes: 7 additions & 6 deletions lisp/magit-process.el
Original file line number Diff line number Diff line change
Expand Up @@ -265,12 +265,13 @@ Identical to `process-file' but temporarily enable Cygwin's
(apply #'process-file args)))

(defun magit-cygwin-env-vars ()
(when magit-need-cygwin-noglob
(mapcar (lambda (var)
(concat var "=" (--if-let (getenv var)
(concat it " noglob")
"noglob")))
'("CYGWIN" "MSYS"))))
(append magit-git-environment
(when magit-need-cygwin-noglob
(mapcar (lambda (var)
(concat var "=" (--if-let (getenv var)
(concat it " noglob")
"noglob")))
'("CYGWIN" "MSYS")))))

(defun magit-run-git-with-input (input &rest args)
"Call Git in a separate process.
Expand Down

0 comments on commit 724ea52

Please sign in to comment.