diff --git a/modules/tools/magit/autoload.el b/modules/tools/magit/autoload.el index 90e7f7ee9..e1bf68980 100644 --- a/modules/tools/magit/autoload.el +++ b/modules/tools/magit/autoload.el @@ -101,12 +101,12 @@ window that already exists in that direction. It will split otherwise." (defun +magit--revert-buffer (buffer) (with-current-buffer buffer (kill-local-variable '+magit--stale-p) - (when (and buffer-file-name (file-exists-p buffer-file-name)) - (if (buffer-modified-p (current-buffer)) - (when (bound-and-true-p vc-mode) - (vc-refresh-state) - (force-mode-line-update)) - (revert-buffer t t t))))) + (when (magit-auto-revert-repository-buffer-p buffer) + (when (bound-and-true-p vc-mode) + (vc-refresh-state)) + (unless (buffer-modified-p buffer) + (revert-buffer t t t)) + (force-mode-line-update)))) ;;;###autoload (defun +magit-mark-stale-buffers-h () diff --git a/modules/tools/magit/config.el b/modules/tools/magit/config.el index 49f5dc97d..0319b723e 100644 --- a/modules/tools/magit/config.el +++ b/modules/tools/magit/config.el @@ -39,16 +39,18 @@ Only has an effect in GUI Emacs.") magit-revision-insert-related-refs nil) (add-hook 'magit-process-mode-hook #'goto-address-mode) - (defadvice! +magit-revert-repo-buffers-deferred-a (&rest _) - :after '(magit-checkout magit-branch-and-checkout) - ;; Since the project likely now contains new files, best we undo the - ;; projectile cache so it can be regenerated later. - (projectile-invalidate-cache nil) - ;; Use a more efficient strategy to auto-revert buffers whose git state has - ;; changed: refresh the visible buffers immediately... - (+magit-mark-stale-buffers-h)) - ;; ...then refresh the rest only when we switch to them, not all at once. + ;; Since the project likely now contains new files, best we undo the + ;; projectile cache so it can be regenerated later. + (add-hook! 'magit-post-refresh-hook + (defun +magit-invalidate-projectile-cache-h () + (projectile-invalidate-cache nil))) + ;; Use a more efficient strategy to auto-revert buffers whose git state has + ;; changed: refresh the visible buffers immediately... + (add-hook 'magit-post-refresh-hook #'+magit-mark-stale-buffers-h) + ;; ...then refresh the rest only when we switch to them or refocus the active + ;; frame, not all at once. (add-hook 'doom-switch-buffer-hook #'+magit-revert-buffer-maybe-h) + (add-hook 'focus-in-hook #'+magit-mark-stale-buffers-h) ;; The default location for git-credential-cache is in ;; ~/.cache/git/credential. However, if ~/.git-credential-cache/ exists, then