In response to a question about adding an action to magit's push menu, I've written an Emacs Lisp command to implement the extension, and I've learned that I can extend the push menu by calling
magit-define-popup-action. However, not every repository supports the new action. I've defined another Emacs Lisp function that will tell me, in a particular repository, whether the action is supported. I want to define a new popup action only when the action is supported.
Is there a hook or other trick I can use to define the new popup action only on those repositories where the action is supported? Or some other conditional code I can arrange for so that the menu knows, in a way sensitive to a particular repository, whether the action is enabled? I know for example that P p and P u change their descriptions depending on settings in the git configuration, but I don't see how that is done.
Ideally if the action is not supported, there is no change of setting that can make it supported, and I'd prefer not to have the item on the menu. But I'd settle for a way to give a description saying the action is unavailable. And bonus points if I can "gray it out."