Listen for git push event from plugin in 2019.2
Answered
In this post a colleague of mine asked the question how to listen for push events in an Intellij Plugin.
The answer worked for us until Intellij version 2019.2 came around. In that version, the class GitPushProcessCustomization was removed (in this commit).
Is there now another way to react to the results of a push or is it no longer possible?
Please sign in to leave a comment.
There is direct API to listen for Push, however, this can be achieved with some heuristic.
One can listen for GIT_AUTHENTICATION_SUCCESS to know when any remote operation (pull, push or fetch) completes successfully.
Then, to make sure it was actually a push, one can use git4idea.branch.GitBranchIncomingOutgoingManager#hasIncomingFor. It should be true before the operation and false after it.
Thanks for your help, the listener works.
But I dont quite get the check for a push to work. For example if I push and then fetch, hasIncomingFor also returns false for the fetch.
Is there any other way to get that information?
Sorry, my bad, you should check `hasOutgoingFor`, not `hasIncomingFor`, of course. Push is about transferring commits from the local repo after all.
Also, see https://youtrack.jetbrains.com/issue/IDEA-219145
I'm sorry, but I still dont really get it to work (probably because I dont really know how this should work).
Am I correct and the hasOutgoingFor basically checks if this small green arrow is next to the branch in the branch dropdown?
If thats true, then I think it should work to test the state before and after the push, but how do I do that. As far as I can see it, the listener is only called before (?) the actual push, at least at that point hasOutgoingFor returns true. But how would I make the check after the operation?
why my program is error
>why my program is error
Hard to tell without any relevant source code, but likely an incorrectly registered GitAuthenticationListener.