I'm using diff-hl https://github.com/dgutov/diff-hl and was looking for a way to update all the buffers when I had commited something, I wrote some function and an advice:
(defun diff-hl-update-each-buffer ()
(mapc (lambda (buffer)
(defadvice magit-update-vc-modeline (after my-magit-update-vc-modeline activate)
to avoid that it would be nice to have hook, maybe even some way to run a command on every magit buffer after a commit has been made? (comparable to magit-vc-update-vc-modeline)
(Note to myself: the hook should be in `magit-refresh-wrapper'.)
We will start using git-commit-mode instead of magit-log-edit shortly, so I am closing this as wontadd.
Adding a hook somewhere in the refresh machinery is planned. This will however be done in a general way, not specialized as some sort of after-commit-hook.
Hi... is there such a hook now? I can't find it...
Yes, try magit-refresh-file-buffer-hook.
I noticed that this didn't work anymore and digging further I found that magit-refresh-file-buffer-hook has been removed.
I wrote some advice to tackle it:
(defadvice git-commit-commit (after git-commit-commit-after activate)
(dolist (buffer (buffer-list))
not very nice but it works. do you have any other suggestion? or could you add some kind of hook again for this?
@tarsius I'm having the same problem - I'm using diff-hl, but I need some after commit hook to use it properly with magit. Obviously I can live with an advice, but I'm wondering if there's a better/cleaner way to achieve this.
I'll look into creating an "after commit" hook.
A problem git-commit-post-commit-hook would have is that, without further precautions (which likely would be complicated), it is not guaranteed that it would run before magit-refresh (which among other things triggers reverting file-visiting buffers). Also such a hook would be run just once, instead of once per file. I will probably add such a hook eventually but will do it on git-modes's next branch, not directly on master.
Alternative I could run a hook magit-revert-hook once per file (inside the repository) in magit-revert-buffers. However that already runs auto-revert-handler which in turns runs the hook vc-find-file-hook, regardless of whether the file was reverted and provided auto-revert-check-vc-info is non-nil. The default value of that variable is nil but I am considering overriding that using a let-binding around the call to auto-revert-handler.
Could you please try that hook for now. Also please post your magit related hook functions and advices here, so that I can better determine whether I should add new hooks or whether better documenting existing hooks is enough. Thanks.
Here it is - https://github.com/dgutov/diff-hl/blob/master/diff-hl.el#L237
vc-find-file-hook is not a hook, it's just a function, which unfortunately doesn't run any hooks in turn, which I might've been able to hook into, AFAICS.
Ideally, any new hook you would add will run after the call to auto-revert-handler, then we'll be able to take advantage of the newly cached vc state information (when it's updated).
magit-revert-buffers now runs magit-revert-buffer-hook for each of the appropriate file-visiting buffers. To be on the safe side wrap your hook functions body with (when (buffer-file-name) ...). We might, or might not, use that for other buffers too in the future. When that is decided I will also explicitly define the hook variable and add documentation. This hook does more or less what magit-refresh-file-buffer-hook used to do, which probably got removed when we started to rely on library autorevert (which came with a messy transition).
(when (buffer-file-name) ...)
I haven't added an after-commit-hook yet, and thinking about it again I tend to come to the same conclusion as almost a year ago: a after-refresh-hook would be more useful, and also easier to do.