fix(magit): reload related buffers after git ops

And when refocusing a frame.
This commit is contained in:
Henrik Lissner
2025-03-29 01:34:48 -04:00
parent 9e624b5dfe
commit 17a870fef8
2 changed files with 17 additions and 15 deletions

View File

@ -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 ()

View File

@ -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