(or load-file-name
(when (boundp 'bytecomp-filename) bytecomp-filename)
buffer-file-name))))
- "magit"))
+ "magit/lisp"))
(add-to-list 'load-path (concat (file-name-directory
(directory-file-name
(or load-file-name
(when (boundp 'bytecomp-filename) bytecomp-filename)
buffer-file-name))))
- "git-modes"))
+ "with-editor"))
(add-to-list 'load-path (concat (file-name-directory
(directory-file-name
(require 'magit)
+(setq magit-refs-local-branch-format "%C %-48n %U%m\n")
+(setq magit-refs-remote-branch-format "%C %-48n %m\n")
+
(when (eq system-type 'windows-nt)
(require 'advice)
(global-set-key "\C-cGS" 'magit-status)
+(defun my-shell-command-to-string (cmd)
+ (shell-command cmd " *my-shell-command-to-string*")
+ (save-current-buffer
+ (set-buffer " *my-shell-command-to-string*")
+ (prog1
+ (buffer-string)
+ (kill-buffer " *my-shell-command-to-string*"))))
+
+(defun git-repo-files ()
+ (let ((default-directory (magit-toplevel default-directory)))
+ (split-string (my-shell-command-to-string "git ls-files") "\n")))
+
(defun find-file-in-git-repo ()
(interactive)
- (let* ((repo (magit-get-top-dir default-directory))
- (files (shell-command-to-string (format "cd %s && git ls-files" repo))))
+ (let ((repo (magit-toplevel default-directory))
+ (files (git-repo-files)))
(find-file
(concat repo
(ido-completing-read
"Find file in git repo: "
(remove-if (lambda (x) (string= "" x))
- (split-string files "\n")))))))
+ files))))))
(defun grep-in-git-repo (regexp &optional words-only)
- (interactive "sGrep files in Git repo regexp: \np")
- (let ((default-directory (magit-get-top-dir default-directory)))
+ (interactive "sGrep files in Git repo regexp: \nP")
+ (let ((default-directory (magit-toplevel default-directory)))
(if (not default-directory)
(error "not a Git directory"))
- (grep (format "git ls-files -z | xargs -r0 grep -nH -E%s -- %s | cat -"
+ (grep (format "git ls-files -z | xargs -r0 grep -d skip -nH -E%s -- %s"
(if words-only " -w" "") (shell-quote-argument regexp)))))
(setenv "GIT_PAGER" "cat")
(defun find-file-maybe-git (&optional nogit)
(interactive "P")
- (if (and (not nogit) (magit-get-top-dir default-directory))
+ (if (and (not nogit) (magit-toplevel default-directory))
(call-interactively 'find-file-in-git-repo)
(call-interactively 'ido-find-file)))
(defun git-files-find-symbol (symbol)
(interactive (list (read-string "Symbol: " (current-word))))
- (let ((dir (magit-get-top-dir default-directory)))
+ (let ((dir (magit-toplevel default-directory)))
+ (if (not dir) (error "No git repository"))
+ (let ((default-directory dir))
+ (grep (format "git ls-files -z | xargs -r0 grep -d skip -nwHF %s" symbol)))))
+
+(defun git-files-find-class-decl (symbol)
+ (interactive (list (read-string "Symbol: " (current-word))))
+ (let ((dir (magit-toplevel default-directory)))
(if (not dir) (error "No git repository"))
(let ((default-directory dir))
- (grep (format "git ls-files -z | xargs -r0 grep -nwHF %s | cat -" symbol)))))
+ (grep (format (concat "git ls-files -z"
+ " | xargs -r0 grep -d skip -nwHF %s"
+ " | grep -Ew '(class|struct|typedef|using)'"
+ " | grep -vEw 'friend'")
+ symbol)))))
(global-set-key "\C-cGF" 'git-files-find-symbol)
+(global-set-key "\C-cGC" 'git-files-find-class-decl)
(defun dired-git-files ()
(interactive)
- (let ((default-directory (magit-get-top-dir default-directory))
- (ls-lisp-use-insert-directory-program t))
- (dired (cons default-directory (split-string (shell-command-to-string "git ls-files") "\n")))))
+ (let ((default-directory (magit-toplevel default-directory))\
+ (ls-lisp-use-insert-directory-program t)
+ files)
+ (setq files (delete-if '(lambda (file) (string= file ""))
+ (split-string (shell-command-to-string "git ls-files") "\n")))
+ (dired (cons default-directory files))))
(global-set-key "\C-cGD" 'dired-git-files)
+(defun dired-grep-git-files (regexp &optional words-only)
+ (interactive "sRegexp: \nP")
+ (let ((default-directory (magit-toplevel default-directory))
+ (cmd (format "git ls-files -z | xargs -r0 grep -d skip -l -E%s -- %s"
+ (if words-only " -w" "") (shell-quote-argument regexp))))
+ (if (not default-directory)
+ (error "not in Git repository"))
+ (setq files (delete-if '(lambda (file) (string= file ""))
+ (split-string (shell-command-to-string cmd) "\n")))
+ (dired (cons default-directory files))))
+
+(global-set-key "\C-cGH" 'dired-grep-git-files)
+
(defun magit-svn-fetch ()
(interactive)
(magit-run-git-async "svn" "fetch"))
(interactive "P")
(quit-window kill-buffer))
-(setq magit-diff-options '("-w"))
+(defun magit-diff-master-mergebase (&optional args files)
+ (interactive (magit-diff-arguments))
+ (magit-diff-working-tree
+ (magit-git-string "merge-base" "master" "HEAD") args files))
+
+(magit-define-popup-action 'magit-diff-popup
+ ?m "Diff merge-base master" 'magit-diff-master-mergebase)
+
+; ignore whitespace
+; (setq magit-diff-options '("-w"))