Commit 7d5a71d8f1f1

Vincent Demeester <vincent@sbr.pm>
2020-01-31 13:22:35
emacs.org: move setup-vcs.el
Signed-off-by: Vincent Demeester <vincent@sbr.pm>
1 parent 615f914
Changed files (2)
lisp/setup-vcs.el
@@ -1,8 +1,4 @@
-;;; setup-vcs.el --- setup vcs related mode (like magit ๐ŸŒŸ)
-;;; Commentary:
-;;; Code:
 ;;; -*- lexical-binding: t; -*-
-
 (use-package vc-hooks                   ; Simple version control
   :bind (("S-<f5>" . vc-revert)
          ("C-c v r" . vc-refresh-state))
@@ -121,8 +117,3 @@
     (kill-buffer commit-buf)))
 
 (provide 'setup-vcs)
-
-;; Local Variables:
-;; coding: utf-8
-;; indent-tabs-mode: nil
-;; End:
emacs.org
@@ -389,7 +389,6 @@
   (provide 'setup-nix)
 #+end_src
 
-
 ** ~setup-org.el~
 
 #+begin_src emacs-lisp :tangle lisp/setup-org.el
@@ -1157,3 +1156,127 @@
 
   (provide 'setup-style)
 #+end_src
+
+** ~setup-vcs.el~
+
+#+begin_src emacs-lisp :tangle lisp/setup-vcs.el
+  ;;; -*- lexical-binding: t; -*-
+  (use-package vc-hooks                   ; Simple version control
+    :bind (("S-<f5>" . vc-revert)
+           ("C-c v r" . vc-refresh-state))
+    :config
+    ;; Always follow symlinks to files in VCS repos
+    (setq vc-follow-symlinks t))
+
+  (use-package magit                      ; The best Git client out there
+    :bind (("C-c v c" . magit-clone)
+           ("C-c v C" . magit-checkout)
+           ("C-c v d" . magit-dispatch-popup)
+           ("C-c v g" . magit-blame)
+           ("C-c v l" . magit-log-buffer-file)
+           ("C-c v p" . magit-pull)
+           ("C-c v v" . magit-status))
+    :config
+    (setq
+     magit-save-repository-buffers 'dontask
+     magit-refs-show-commit-count 'all
+     magit-branch-prefer-remote-upstream '("master")
+     magit-display-buffer-function #'magit-display-buffer-traditional
+     magit-completing-read-function 'ivy-completing-read
+     )
+
+    (magit-define-popup-option 'magit-rebase-popup
+      ?S "Sign using gpg" "--gpg-sign=" #'magit-read-gpg-secret-key)
+    (magit-define-popup-switch 'magit-log-popup
+      ?m "Omit merge commits" "--no-merges")
+
+    ;; Hide "Recent Commits"
+    (magit-add-section-hook 'magit-status-sections-hook
+                            'magit-insert-unpushed-to-upstream
+                            'magit-insert-unpushed-to-upstream-or-recent
+                            'replace)
+
+    (use-package magit-files
+      :config
+      (global-magit-file-mode))
+
+    ;; Show refined hunks during diffs
+    (set-default 'magit-diff-refine-hunk t)
+
+    (add-hook 'projectile-switch-project-hook
+              #'mu-magit-set-repo-dirs-from-projectile)
+
+    ;; Refresh `magit-status' after saving a buffer
+    (add-hook 'after-save-hook #'magit-after-save-refresh-status)
+
+    ;; Free C-c C-w for Eyebrowse
+    (unbind-key "C-c C-w" git-commit-mode-map)  )
+
+  (use-package forge
+    :after magit)
+
+  (use-package magit-repos
+    :after magit
+    :commands magit-list-repositories
+    :config
+    (setq magit-repository-directories
+          '(("~/src" . 3))))
+
+  (use-package git-commit                 ; Git commit message mode
+    :defer 2
+    :init (global-git-commit-mode)
+    :config
+    (setq git-commit-summary-max-length 50)
+    (setq git-commit-known-pseudo-headers
+          '("Signed-off-by"
+            "Acked-by"
+            "Modified-by"
+            "Cc"
+            "Suggested-by"
+            "Reported-by"
+            "Tested-by"
+            "Reviewed-by"))
+    (setq git-commit-style-convention-checks
+          '(non-empty-second-line
+            overlong-summary-line))
+    (remove-hook 'git-commit-finish-query-functions
+                 #'git-commit-check-style-conventions))
+
+  (use-package gitconfig-mode             ; Git configuration mode
+    :defer 2)
+
+  (use-package gitignore-mode             ; .gitignore mode
+    :defer 2)
+
+  (use-package gitattributes-mode         ; Git attributes mode
+    :defer 2)
+
+  (use-package dired-git-info
+    :bind (:map dired-mode-map
+                (")" . dired-git-info-mode))
+    :defer 2)
+
+  (defun git-blame-line ()
+    "Runs `git blame` on the current line and
+     adds the commit id to the kill ring"
+    (interactive)
+    (let* ((line-number (save-excursion
+                          (goto-char (point-at-bol))
+                          (+ 1 (count-lines 1 (point)))))
+           (line-arg (format "%d,%d" line-number line-number))
+           (commit-buf (generate-new-buffer "*git-blame-line-commit*")))
+      (call-process "git" nil commit-buf nil
+                    "blame" (buffer-file-name) "-L" line-arg)
+      (let* ((commit-id (with-current-buffer commit-buf
+                          (buffer-substring 1 9)))
+             (log-buf (generate-new-buffer "*git-blame-line-log*")))
+        (kill-new commit-id)
+        (call-process "git" nil log-buf nil
+                      "log" "-1" "--pretty=%h   %an   %s" commit-id)
+        (with-current-buffer log-buf
+          (message "Line %d: %s" line-number (buffer-string)))
+        (kill-buffer log-buf))
+      (kill-buffer commit-buf)))
+
+  (provide 'setup-vcs)
+#+end_src