syl20bnr / spacemacs

A community-driven Emacs distribution - The best editor is neither Emacs nor Vim, it's Emacs *and* Vim!
http://spacemacs.org
GNU General Public License v3.0
23.69k stars 4.89k forks source link

magit-next create branch the powerline mode line branch name doesn't update #2172

Closed zilongshanren closed 3 months ago

zilongshanren commented 9 years ago

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.

syl20bnr commented 9 years ago

For reference, this was already the case with previous commit.

PierreR commented 9 years ago

:+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

System Info

This is quite annoying.

StreakyCobra commented 8 years ago

I just reproduced it on develop. @TheBB it is something to do on spaceline, or to report upstream?

TheBB commented 8 years ago

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 :-(

justbur commented 8 years ago

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.

StreakyCobra commented 8 years ago

Should we report to magit then, or do we do it on our side?

justbur commented 8 years ago

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 .

TheBB commented 8 years ago

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.

synic commented 8 years ago

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.

maple-leaf commented 8 years ago

@TheBB yes. The branch name will not update if file content has not diff between two branch.

zzantares commented 8 years ago

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.

tarsius commented 8 years ago

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.

tarsius commented 8 years ago

I might eventually do something about this, see magit/magit#2687.

osenvosem commented 6 years ago

The issue still persists.

shae128 commented 5 years ago

I still have the same issue.

damien-biasotto commented 5 years ago

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

roeeyn commented 4 years ago

@damien-biasotto where should I put that function? I'm using spacemacs, and the issue still persists 😢

duianto commented 4 years ago

@roeeyn damien-biasotto's suggestion (modified), can be added to the dotspacemacs/user-config section in your .spacemacs.

Before

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/

After

  ;; 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"))))

Modifications:

With the advice above evaluated, the mode line branch name updates in the current buffer, when:

Windows 10, System Info (Click to expand)
#### 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

github-actions[bot] commented 2 years ago

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!

lebensterben commented 2 years ago

Is this still a bug?

github-actions[bot] commented 6 months ago

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!