Statically specify git repositories for magit

Relying on projectile's project list seems to be fragile and often
includes too many repositories, so let's let magit find those
repositories itself.
This commit is contained in:
Daniel Borchmann 2024-06-08 09:24:02 +02:00
parent 3dee200729
commit de68fc30b2
No known key found for this signature in database
GPG Key ID: 784AA8DF0CCDF625

22
init.el
View File

@ -1413,12 +1413,13 @@ Note that this workaround is incomplete, as explained in this comment."
(use-package magit (use-package magit
:ensure t :ensure t
:commands (magit-status :commands (magit-status
magit-list-repositories magit-list-repositories)
db/sync-magit-repos-from-projectile)
:init (progn :init (progn
(setq magit-diff-refine-hunk nil (setq magit-diff-refine-hunk nil
magit-commit-show-diff nil) magit-commit-show-diff nil
magit-repository-directories '(("~/" . 0)
("~/Documents/" . 3)))
(when on-windows (when on-windows
;; Experimental: on Windows, do not refresh magit-status-buffers ;; Experimental: on Windows, do not refresh magit-status-buffers
@ -1428,20 +1429,7 @@ Note that this workaround is incomplete, as explained in this comment."
:config (progn :config (progn
(when (fboundp 'global-magit-file-mode) (when (fboundp 'global-magit-file-mode)
(global-magit-file-mode -1)) (global-magit-file-mode -1))
(global-git-commit-mode 1) (global-git-commit-mode 1)))
(defun db/sync-magit-repos-from-projectile ()
"Update repositories known to magit from projectile's."
(interactive)
(eval-when-compile ; to silence the byte compiler
(require 'projectile))
(setq magit-repository-directories
(->> projectile-known-projects
(--filter (and (not (file-remote-p it))
(file-exists-p (concat it "/.git"))))
(--map (cons it 0)))))
(db/sync-magit-repos-from-projectile)))
(use-package page-break-lines (use-package page-break-lines
:pin "melpa-stable" :pin "melpa-stable"