HOME

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:

(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 [2018-02-05 Mon 10:31]

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)

Author: Toby Tripp

Created: 2018-02-09 Fri 15:33

Validate