summary refs log tree commit diff
path: root/emacs.d/custom/fcuny-git.el
blob: e3b8c45a04b56792dea4a19e00e6d76c22d0d669 (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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
(require 'fcuny-defuns)

(use-package gitconfig-mode
  :ensure t)

(use-package gitattributes-mode
  :ensure t)

(use-package gitignore-mode
  :ensure t)

(use-package magit
  :ensure t
  :after (flyspell)
  :bind (("C-x g" . magit-status))
  :custom
  (vc-follow-symlinks t))

(use-package git-commit
  :ensure t
  :after magit
  :hook (git-commit-mode . fcuny/git-commit-auto-fill)
  :custom
  (git-commit-summary-max-length 50)
  :preface
  (defun fcuny/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)))

;; from https://sideshowcoder.com/2020/07/02/opening-sourcegraph-from-emacs/
;; in a repo, add the following in .git/config:
;;
;; [git-link]
;;        remote = mysourcegraph.sourcegraph
;; [remote "mysourcegraph.sourcegraph"]
;;        url = https://sourcegraph.twitter.biz/gitpuppet.twitter.biz/puppet-twitter
;;
(use-package git-link
  :ensure t
  :config
  (defun git-link-sourcegraph (hostname dirname filename _branch commit start end)
    (let ((line-or-range (if end (format "%s-%s" start end) start)))
      (format "https://%s/%s@%s/-/blob/%s#L%s"
              hostname
              dirname
              commit
              filename
              line-or-range)))

  (defun git-link-commit-sourcegraph (hostname dirname commit)
    (format "https://%s/%s/-/commit/%s"
            hostname
            dirname
            commit))

  (add-to-list 'git-link-remote-alist '("sourcegraph" git-link-sourcegraph))
  (add-to-list 'git-link-commit-remote-alist '("sourcegraph" git-link-commit-sourcegraph))

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

;; https://magit.vc/manual/magit/Per_002dRepository-Configuration.html
;; we don't want to refresh buffers in source. This should help with
;; performances.
(dir-locals-set-class-variables 'huge-git-repository
                                '((nil . ((magit-refresh-buffers . nil)))))

(dir-locals-set-directory-class
 "/Users/fcuny/workspace/source" 'huge-git-repository)

;; https://magit.vc/manual/magit/Performance.html
;; disable Git from the VC mode, since we use magit. This should help
;; with performances.
(setq vc-handled-backends (delq 'Git vc-handled-backends))

(provide 'fcuny-git)