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 my-shell-command-to-string (cmd)
72 (shell-command cmd " *my-shell-command-to-string*")
74 (set-buffer " *my-shell-command-to-string*")
77 (kill-buffer " *my-shell-command-to-string*"))))
79 (defun git-repo-files ()
80 (let ((default-directory (magit-get-top-dir default-directory)))
81 (split-string (my-shell-command-to-string "git ls-files") "\n")))
83 (defun find-file-in-git-repo ()
85 (let ((repo (magit-get-top-dir default-directory))
86 (files (git-repo-files)))
90 "Find file in git repo: "
91 (remove-if (lambda (x) (string= "" x))
94 (defun grep-in-git-repo (regexp &optional words-only)
95 (interactive "sGrep files in Git repo regexp: \nP")
96 (let ((default-directory (magit-get-top-dir default-directory)))
97 (if (not default-directory)
98 (error "not a Git directory"))
99 (grep (format "git ls-files -z | xargs -r0 grep -nH -E%s -- %s | cat -"
100 (if words-only " -w" "") (shell-quote-argument regexp)))))
102 (setenv "GIT_PAGER" "cat")
103 (setenv "GIT_MAN_VIEWER" "woman")
104 (setenv "GIT_EDITOR" "emacsclient")
106 (defun find-file-maybe-git (&optional nogit)
108 (if (and (not nogit) (magit-get-top-dir default-directory))
109 (call-interactively 'find-file-in-git-repo)
110 (call-interactively 'ido-find-file)))
112 (global-set-key "\C-x\C-f" 'find-file-maybe-git)
113 (global-set-key "\C-cGG" 'grep-in-git-repo)
115 (defun git-files-find-symbol (symbol)
116 (interactive (list (read-string "Symbol: " (current-word))))
117 (let ((dir (magit-get-top-dir default-directory)))
118 (if (not dir) (error "No git repository"))
119 (let ((default-directory dir))
120 (grep (format "git ls-files -z | xargs -r0 grep -nwHF %s | cat -" symbol)))))
122 (global-set-key "\C-cGF" 'git-files-find-symbol)
123 (defun dired-git-files ()
125 (let ((default-directory (magit-get-top-dir default-directory))
126 (ls-lisp-use-insert-directory-program t)
128 (setq files (shell-command-to-string "git ls-files"))
129 (dired (cons default-directory (split-string files "\n")))))
131 (global-set-key "\C-cGD" 'dired-git-files)
133 (defun magit-svn-fetch ()
135 (magit-run-git-async "svn" "fetch"))
137 (define-key magit-mode-map "Nf" 'magit-svn-fetch)
139 (defun magit-quit-window (&optional kill-buffer)
141 (quit-window kill-buffer))
143 (setq magit-diff-options '("-w"))