summary refs log tree commit diff
path: root/emacs/custom/my-git.el
blob: 2270f917a5ecdd5b6b72a07cfdb43b107f4d1800 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
;;; my-git --- configures git for emacs -*- lexical-binding: t -*-

;;; Commentary:

;;; Code:

(require 'magit)
(require 'git-link)

;;; settings
(setq vc-follow-symlinks t)

;; we're not barbarians
(setq git-commit-summary-max-length 70)

;; open the link in the browser
(setq git-link-open-in-browser 't)

;; I prefer to have the status buffer in full frame
(setq magit-display-buffer-function #'magit-display-buffer-fullframe-status-v1)

;; expand a number of sections with magit
(add-to-list 'magit-section-initial-visibility-alist '(untracked . show))
(add-to-list 'magit-section-initial-visibility-alist '(unstaged  . show))
(add-to-list 'magit-section-initial-visibility-alist '(unpulled  . show))
(add-to-list 'magit-section-initial-visibility-alist '(unpushed  . show))

(add-to-list 'auto-mode-alist '("\\.gitconfig\\'"     . gitconfig-mode))
(add-to-list 'auto-mode-alist '("\\.git/config\\'"    . gitconfig-mode))
(add-to-list 'auto-mode-alist '("\\.gitmodules\\'"    . gitconfig-mode))
(add-to-list 'auto-mode-alist '("\\.gitignore\\'"     . gitconfig-mode))
(add-to-list 'auto-mode-alist '("\\.dockerignore\\'"  . gitconfig-mode))
(add-to-list 'auto-mode-alist '("\\.gitattributes\\'" . gitattributes-mode))

;;; bindings
(global-set-key (kbd "C-x g") 'magit-status)
(global-set-key (kbd "C-c g l") 'git-link)
(global-set-key (kbd "C-c g c") 'git-link-commit)

;;; hooks
(defun my/git-commit-auto-fill ()
  "Ensures that the commit body does not exceed 72 characters."
  (setq-local fill-column 72)
  (setq-local comment-auto-fill-only-comments nil))

(add-hook 'git-commit-mode-hook 'my/git-commit-auto-fill)

(provide 'my-git)

;;; my-git.el ends here