Git Source Control
Git Executable Path
(setenv "EDITOR" "/usr/local/bin/emacsclient") (setenv "PATH" (concat (getenv "PATH") ":" "/usr/local/bin" ":" "/usr/local/git/bin/")) (setq exec-path (append exec-path '("/usr/local/bin"))) (setq exec-path (append exec-path '("/usr/local/git/bin")))
Magit
Probably the very best git front-end out there.
I like it to open full-screen and then restore my windows where they were when it is done:
fullframe is an autoloaded Lisp macro in ‘fullframe.el’.
(fullframe COMMAND-ON COMMAND-OFF &optional KILL-ON-COFF AFTER-COMMAND-ON-FUNC)
Save window/frame state when executing COMMAND-ON.
Advises COMMAND-ON so that the buffer it displays will appear in a full-frame window. The previous window configuration will be restored when COMMAND-OFF is executed in that buffer. If KILL-ON-COFF is non-nil, then the buffer will also be killed after COMMAND-OFF has completed.
This function uses ‘defadvice’ on versions of emacs < 24.4, ‘advice-add’ otherwise.
AFTER-COMMAND-ON-FUNC is called after COMMAND-ON was called and the window it generated is the only one in in the frame.
(require-package 'magit) (require-package 'fullframe) (eval-after-load "magit" '(progn (fullframe magit-status magit-mode-quit-window nil) (fullframe vc-annotate quit-window)))
diff-hl
integration
(require-package 'diff-hl) (autoload 'diff-hl-magit-post-refresh "diff-hl")
Keybingings
Quick one-button git status:
(global-set-key (kbd "<f2>") 'magit-status)
EXPERIMENTAL Snippets
- State "EXPERIMENTAL" from
Snippet-ize git commit templates:
(defun toby/update-tracker-id (&optional story-file) (interactive) (save-excursion (let* ((story-f (if (consp story-file) story-file "../.story_id")) (story-id (if (file-readable-p story-f) (with-temp-buffer (insert-file-contents story-f) (goto-char (point-min)) (re-search-forward "^\\(#[0-9]+\\)[[:space:]]*" nil) (replace-match (match-string 1)) (buffer-string)) ""))) (goto-char (point-min)) (re-search-forward "_STORY_ID_" nil t) (replace-match story-id))) (yas-minor-mode-on) (goto-char (point-min)) (forward-word 2) (yas-expand))
git-grep
(defun git-grep-rb (regexp) "Run git-grep on ruby files in the current project" (interactive "sSearch for (regexp): ") (vc-git-grep regexp "'*.rb'" (textmate-project-root))) (defun git-grep (regexp) "Run git-grep on files in the current project" (interactive "sSearch for (regexp): ") (vc-git-grep regexp "'*.rb' '*.clj'" (textmate-project-root)))
vc-annotate
Built-in to Emacs and really useful. It allows you to not only view source control annotations, but also to move back and forward in time within the file. Very nice.
It's nicer, I think, when it ignores white-space:
(defun vc-git-annotate-command (file buf &optional rev) (let ((name (file-relative-name file))) (vc-git-command buf 0 name "blame" "-w" rev)))
(provide 'git-init)