2

Every time I use M-x magit-status b b to checkout a different branch, the projectile cache is of course out of date. I then use M-x projectile-invalidate-cache to force projectile to rebuild its cache and that does work fine.

How could I automate this? I have no idea how to check which magit-xyz command is triggered when using b b in magit-status. And even if I knew: How would I transparently "overwrite" that command to first call its previous definition and then projectile-invalidate-cache?

6

I have no idea how to check which magit-xyz command is triggered when using b b in magit-status.

Use b ? b in magit-status. This tells you it runs magit-checkout.

And even if I knew: How would I transparently "overwrite" that command to first call its previous definition and then projectile-invalidate-cache?

Use advice:

(defun run-projectile-invalidate-cache (&rest _args)
  ;; We ignore the args to `magit-checkout'.
  (projectile-invalidate-cache nil))
(advice-add 'magit-checkout
            :after #'run-projectile-invalidate-cache)
(advice-add 'magit-branch-and-checkout ; This is `b c'.
            :after #'run-projectile-invalidate-cache)

Another idea might be to use file notifications to invalidate the cache (this could work also if you did a checkout from the command line).

  • This results in run-projectile-invalidate-cache: Wrong number of arguments: ((t) (arg) "Remove the current project's files from projectile-projects-cache'.`. Any ideas? – Nickolay Kolev Aug 16 '16 at 9:04
  • 1
    @NickolayKolev oops, projectile-invalidate-cache requires an argument, fixed now. – npostavs Aug 16 '16 at 12:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.