Detecing VCS checkout, even for a local (=never pushed) branch?

Answered

Hi. 

I'm trying to write a plugin that listens to VCS checkout. I've tried several extensions but none of them seem to do anything when I checkout a branch (using the IDE UI of course).

The extensions I tried are checkoutCompletedListener, vcsAwareCheckoutListener and checkoutListener. 

In plugin.xml I'm registering the extensions as

<extensions defaultExtensionNs="com.intellij">
<checkoutCompletedListener implementation="com.intellij.openapi.vcs.checkout.MyCheckoutListener"/>
<vcsAwareCheckoutListener implementation="com.intellij.openapi.vcs.checkout.MyVcsAwareCheckoutListener"/>
<checkoutListener implementation="com.intellij.openapi.vcs.checkout.MyCheckoutListener"/>
</extensions>

And when ctrl+clicking the class names the IDE finds their implementations so that is not the issue.

Are these extensions even do what I expect them to do?

0
3 comments

Such checkout listeners are triggered on the repository checkout - so in case you clone a new project. This is also why the methods provided by these interfaces are called processCheckedOutDirectory and processOpenedProject - you're dealing with a new directory/opening new project.

You should try with the BranchChangeListener instead:

<projectListeners>
<listener class="com.example.MyBranchChangeListener" topic="com.intellij.openapi.vcs.BranchChangeListener"/>
</projectListeners>

Besides that - do you keep your implementations in the com.intellij.openapi.vcs.checkout package? If so - please create your own namespace instead.

1

Works perfectly. Thanks!

0

Note, that this listener will only be triggered on "checkout" action from IDE.

As an alternative, you can subscribe to 'git4idea.repo.GitRepositoryChangeListener' and check if 'GitRepository.getCurrentBranch' was changed since the last time.
This method should work with checkouts, performed via command line (or another GUI).


> checkoutCompletedListener, vcsAwareCheckoutListener and checkoutListener. 
These listeners are for "git clone" commands (naming is confusing due to clash with SVN-era terminology).

1

Please sign in to leave a comment.