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?

0
6 comments

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.

0
Avatar
Benjamin Zembrodt

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?

0

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

0
Avatar
Benjamin Zembrodt

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?

0

why my program is error

git4idea.commands.GitStandardProgressAnalyzer$1.onLineAvailable(GitStandardProgressAnalyzer.java:46) 
2022-05-24 20:40:07,112 [ 453727]  ERROR - intellij.openapi.progress.Task - object is not an instance of declaring class 
java.lang.IllegalArgumentException: object is not an instance of declaring class
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at com.intellij.util.messages.impl.MessageBusImpl.invokeListener(MessageBusImpl.java:652)
    at com.intellij.util.messages.impl.MessageBusImpl.deliverMessage(MessageBusImpl.java:426)
    at com.intellij.util.messages.impl.MessageBusImpl.pumpWaitingBuses(MessageBusImpl.java:401)
    at com.intellij.util.messages.impl.MessageBusImpl.pumpMessages(MessageBusImpl.java:383)
    at com.intellij.util.messages.impl.MessageBusImpl.access$100(MessageBusImpl.java:33)
    at com.intellij.util.messages.impl.MessageBusImpl$MessagePublisher.invoke(MessageBusImpl.java:189)
    at com.sun.proxy.$Proxy173.authenticationSucceeded(Unknown Source)
    at git4idea.push.GitPushOperation.doPush(GitPushOperation.java:381)
    at git4idea.push.GitPushOperation.push(GitPushOperation.java:286)
    at git4idea.push.GitPushOperation.execute(GitPushOperation.java:137)
    at git4idea.push.GitPusher.pushAndNotify(GitPusher.java:68)
    at git4idea.push.GitPusher.push(GitPusher.java:64)
    at com.intellij.dvcs.push.PushController.doPushSynchronously(PushController.java:463)
    at com.intellij.dvcs.push.PushController.push(PushController.java:453)
    at com.intellij.dvcs.push.ui.VcsPushDialog$2.run(VcsPushDialog.java:243)
    at com.intellij.openapi.progress.impl.CoreProgressManager$TaskRunnable.run(CoreProgressManager.java:962)
    at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$runProcessWithProgressAsync$5(CoreProgressManager.java:472)
    at com.intellij.openapi.progress.impl.ProgressRunner.lambda$submit$3(ProgressRunner.java:235)
    at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$runProcess$2(CoreProgressManager.java:178)
    at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:658)
    at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:610)
    at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:65)
    at com.intellij.openapi.progress.impl.CoreProgressManager.runProcess(CoreProgressManager.java:165)
    at com.intellij.openapi.progress.impl.ProgressRunner.lambda$submit$4(ProgressRunner.java:235)
    at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1700)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:668)
    at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:665)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1.run(Executors.java:665)
    at java.base/java.lang.Thread.run(Thread.java:834)
2022-05-24 20:40:07,113 [ 453728]  ERROR - intellij.openapi.progress.Task - IntelliJ IDEA 2020.3.1  Build #IU-203.6682.168 
2022-05-24 20:40:07,116 [ 453731]  ERROR - intellij.openapi.progress.Task - JDK: 11; VM: OpenJDK 64-Bit Server VM; Vendor: Oracle Corporation 
2022-05-24 20:40:07,116 [ 453731]  ERROR - intellij.openapi.progress.Task - OS: Windows 10 
2022-05-24 20:40:07,117 [ 453732]  ERROR - intellij.openapi.progress.Task - Last Action: CheckinProject 
2022-05-24 20:40:07,555 [ 454170]   WARN - arketplace.MarketplaceRequests - Can not get JetBrains plugins' IDs from Marketplace:Received fatal alert: handshake_failure 
0

>why my program is error

Hard to tell without any relevant source code, but likely an incorrectly registered GitAuthenticationListener.

0

Please sign in to leave a comment.