Closed zilongshanren closed 3 months ago
For reference, this was already the case with previous commit.
:+1:
Actually whenever you use `magit-checkout´ to switch from one branch to another, the powerline won't refresh and it will give you misleading information.
Tested with
This is quite annoying.
I just reproduced it on develop
. @TheBB it is something to do on spaceline, or to report upstream?
It's not really a Spaceline bug, it's somewhere in the integration between Magit and VC. But of course we can provide a workaround either in Spacemacs or in Spaceline (probably Spacemacs).
I think @justbur found something that worked in Emacs 25. I can't find it :-(
There's a function that's called something like vc-refresh-state (name changes between 24 and 25) that needs to be called. I think magit should probably do it but maybe there's a hook that can be used.
Should we report to magit then, or do we do it on our side?
Maybe it's not technically a magit issue actually because it doesn't affect magit functionality. Just deal with it here I'd say. On Sat, Nov 7, 2015 at 5:42 PM Fabien Dubosson notifications@github.com wrote:
Should we report to magit then, or do we do it on our side?
— Reply to this email directly or view it on GitHub https://github.com/syl20bnr/spacemacs/issues/2172#issuecomment-154760587 .
Try setting auto-revert-check-vc-info
to t
.
Seems this might be caused when changing the branch doesn't cause the content of the file to change. Then auto-revert
won't do anything.
Just a note. auto-revert-check-vc-info
did work to fix this issue for me. However, the next few days were spent with me trying to debug why emacs was constantly taking up 20+% of my cpu.
This was the setting that caused it, for sure.
From emacswiki
When Auto Revert mode (see Reverting) reverts a buffer that is under version control, it updates the
version control information in the mode line. However, Auto Revert mode may not properly update this
information if the version control status changes without changes to the work file, from outside the
current Emacs session. If you set auto-revert-check-vc-info to t, Auto Revert mode updates the
version control status information every auto-revert-interval seconds, even if the work file itself is
unchanged. **The resulting CPU usage depends on the version control system, but is usually not
excessive**.
It seems like a hook or two would be way better at fixing this issue than auto-reverting every x number of seconds.
@TheBB yes. The branch name will not update if file content has not diff between two branch.
In the mean time if anyone is interested I have made this function:
(defun my-magit-checkout (revision)
"Checks out a branch updating the mode line (reverts the buffer)."
(interactive (list (magit-read-other-branch-or-commit "Checkout")))
(magit-checkout revision)
(revert-buffer t t))
It will update the branch name displayed in the powerline, but be careful if you have unsaved changes in the buffer those will be gone (which I guess is ok because you're doing a checkout).
However in multi-window it will not revert other buffers, thus one window showing misleading information. If this issue isn't fixed, at least most of users would be happy with a function that does that.
The costs of keeping this information up-to-date are very high and the benefit is very small. I therefore suggest that you stop worrying and start to love the outdated information. Or if it continues to bother you too much, that you simply remove it. Then at least it won't be outdated.
There is a Magit FAQ entry on the subject and I also just added a new page to the Magit wiki for those users who care deeply about this part of the mode-line being up-to-date and are willing to make the necessary investment.
If I were you I would probably close this issue.
I might eventually do something about this, see magit/magit#2687.
The issue still persists.
I still have the same issue.
I'm not using Spacemacs (for now) but I fixed this behaviour by advising some magit functions:
https://gist.github.com/damien-biasotto/b26f47bdfc7a8a7c76107e2160f57591
And now if you're checking out or creating a branch, the git modeline will be refreshed..
@damien-biasotto where should I put that function? I'm using spacemacs, and the issue still persists 😢
@roeeyn damien-biasotto's suggestion (modified), can be added to the dotspacemacs/user-config
section in your .spacemacs
.
https://gist.github.com/damien-biasotto/b26f47bdfc7a8a7c76107e2160f57591
;;Trigger a refresh of vc-modeline on some magit functions
(require 'magit)
(defun refresh-vc-state (&rest r) (message "%S" (current-buffer))(vc-refresh-state))
(advice-add 'magit-checkout-revision :after 'refresh-vc-state '((name . "magit-refresh-on-checkout-revision")))
(advice-add 'magit-branch-create :after 'refresh-vc-state '((name . "magit-refresh-on-branch-create")))
(advice-add 'magit-branch-and-checkout :after 'refresh-vc-state '((name . "magit-refresh-on-checkout-and-branch")))
(advice-add 'magit-branch-or-checkout :after 'refresh-vc-state '((name . "magit-refresh-on-branch-or-checkout")))
This might be where damien-biasotto got the suggestion from: https://www.reddit.com/r/emacs/comments/d2j8n3/advising_some_magit_functions_to_trigger/
;; Trigger a refresh of vc-modeline on some magit functions
(with-eval-after-load 'magit
(defun refresh-vc-state (&rest r) (message "%S" (current-buffer))(vc-refresh-state))
(advice-add 'magit-checkout :after 'refresh-vc-state '((name . "magit-refresh-on-checkout")))
(advice-add 'magit-branch-create :after 'refresh-vc-state '((name . "magit-refresh-on-branch-create")))
(advice-add 'magit-branch-and-checkout :after 'refresh-vc-state '((name . "magit-refresh-on-checkout-and-branch")))
(advice-add 'magit-branch-or-checkout :after 'refresh-vc-state '((name . "magit-refresh-on-branch-or-checkout"))))
(require 'magit)
line was changed to: with-eval-after-load 'magit
I don't know if there's a difference but other package specific configurations have used with-eval-after-load
to load them after a package has loaded.(advice-add 'magit-checkout-revision :after 'refresh-vc-state '((name . "magit-refresh-on-checkout-revision")))
to:
(advice-add 'magit-checkout :after 'refresh-vc-state '((name . "magit-refresh-on-checkout")))
because there doesn't seem to be a function with the name: magit-checkout-revision
maybe it's been renamed.With the advice above evaluated, the mode line branch name updates in the current buffer, when:
SPC g m b b
SPC g m b c
(SPC g m
calls magit-dispatch
, which opens the Magit Transient and dwim commands popup
, where b
opens the Magit Branch popup.#### System Info :computer: - OS: windows-nt - Emacs: 27.1 - Spacemacs: 0.300.0 - Spacemacs branch: develop (rev. b83eb11e3) - Graphic display: t - Distribution: spacemacs - Editing style: vim - Completion: helm - Layers: ```elisp (autohotkey command-log emacs-lisp git haskell helm (javascript :variables javascript-backend 'lsp) lsp multiple-cursors org (python :variables python-backend 'lsp python-lsp-server 'mspyls) shell version-control treemacs) ``` - System configuration features: XPM JPEG TIFF GIF PNG RSVG SOUND NOTIFY W32NOTIFY ACL GNUTLS LIBXML2 HARFBUZZ ZLIB TOOLKIT_SCROLL_BARS MODULES THREADS JSON PDUMPER LCMS2 GMP
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Please let us know if this issue is still valid!
Is this still a bug?
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Please let us know if this issue is still valid!
When create a new branch and switch to the branch with
b B
after magit-status popup, the powerline git branch name doesn't update.