1 (add-to-list 'load-path (concat (file-name-directory
5 (when (boundp 'bytecomp-filename) bytecomp-filename)
9 (add-to-list 'load-path (concat (file-name-directory
13 (when (boundp 'bytecomp-filename) bytecomp-filename)
17 (add-to-list 'load-path (concat (file-name-directory
21 (when (boundp 'bytecomp-filename) bytecomp-filename)
27 (if (not (functionp 'run-hook-wrapped))
28 (defun run-hook-wrapped (hook wrap-function &rest args)
30 thereis (apply 'wrap-function fn args))))
32 (if (not (functionp 'process-live-p))
33 (defun process-live-p (process)
34 (memq (process-status process)
35 '(run open listen connect stop))))
39 (when (eq system-type 'windows-nt)
43 (setf (symbol-function 'builtin-process-file) (symbol-function 'process-file))
45 (defvar my-magit-shell "c:\\Program Files (x86)\\Git\\bin\\sh")
47 (defun my-magit-process-file (program &optional infile buffer display &rest args)
48 (builtin-process-file my-magit-shell infile buffer display
49 "-c" (mapconcat 'shell-quote-argument (cons "/bin/git" args) " ")))
51 (defadvice magit-cmd-output (around my-magit-process-file activate)
52 (letf (((symbol-function 'process-file) (symbol-function 'my-magit-process-file)))
55 (defadvice magit-git-exit-code (around my-magit-process-file activate)
56 (letf (((symbol-function 'process-file) (symbol-function 'my-magit-process-file)))
59 (defadvice magit-run (around activate)
60 (letf (((symbol-function 'process-file) (symbol-function 'my-magit-process-file)))
65 (defadvice magit-mode-quit-window (around my-magit-mode-quit-window activate)
66 (letf (((symbol-function 'selected-window) (lambda ())))
69 (global-set-key "\C-cGS" 'magit-status)
71 (defun find-file-in-git-repo ()
73 (let* ((repo (magit-get-top-dir default-directory))
74 (files (shell-command-to-string (format "cd %s && git ls-files" repo))))
78 "Find file in git repo: "
79 (remove-if (lambda (x) (string= "" x))
80 (split-string files "\n")))))))
82 (defun grep-in-git-repo (regexp &optional words-only)
83 (interactive "sGrep files in Git repo regexp: \np")
84 (let ((default-directory (magit-get-top-dir default-directory)))
85 (if (not default-directory)
86 (error "not a Git directory"))
87 (grep (format "git ls-files -z | xargs -r0 grep -nH -E%s -- %s | cat -"
88 (if words-only " -w" "") (shell-quote-argument regexp)))))
90 (setenv "GIT_PAGER" "cat")
91 (setenv "GIT_MAN_VIEWER" "woman")
92 (setenv "GIT_EDITOR" "emacsclient")
94 (defun find-file-maybe-git (&optional nogit)
96 (if (and (not nogit) (magit-get-top-dir default-directory))
97 (call-interactively 'find-file-in-git-repo)
98 (call-interactively 'ido-find-file)))
100 (global-set-key "\C-x\C-f" 'find-file-maybe-git)
101 (global-set-key "\C-cGG" 'grep-in-git-repo)
103 (defun git-files-find-symbol (symbol)
104 (interactive (list (read-string "Symbol: " (current-word))))
105 (let ((dir (magit-get-top-dir default-directory)))
106 (if (not dir) (error "No git repository"))
107 (let ((default-directory dir))
108 (grep (format "git ls-files -z | xargs -r0 grep -nwHF %s | cat -" symbol)))))
110 (global-set-key "\C-cGF" 'git-files-find-symbol)
112 (defun dired-git-files ()
114 (let ((default-directory (magit-get-top-dir default-directory))
115 (ls-lisp-use-insert-directory-program t))
116 (dired (cons default-directory (split-string (shell-command-to-string "git ls-files") "\n")))))
118 (global-set-key "\C-cGD" 'dired-git-files)
120 (defun magit-svn-fetch ()
122 (magit-run-git-async "svn" "fetch"))
124 (define-key magit-mode-map "Nf" 'magit-svn-fetch)
126 (defun magit-quit-window (&optional kill-buffer)
128 (quit-window kill-buffer))
130 (setq magit-diff-options '("-w"))