Get a list of pushed git commits in a plugin

Hi fellow coders,

I'm looking for a programmatic way to retrieve a list of pushed commits after a user makes the git push (git4idea plugin). So far I have connected to project message bus and registered GitRepositoryChangeListener. It receives GitRepository as an argument. But how do I get a list of commits now? Or is there a better way to do that?

4 comments
Comment actions Permalink

Hi,

To get pushed commits, say, from master to origin/master, you have to:
1. check where does origin/master point to BEFORE push: hash1
2. check where does it point to AFTER push: hash2
And invoke 'git log hash1..hash2'

But there are several problems with this task:
a. GitRepositoryChangeListener doesn't tell you the previous state of the Git repository, in particular where did its branches point to.
b. You can't be sure that this event was about the push. Although git plugin tries to merge VFS events about changes in .git, it is still not guaranteed that the event you receive will be about push and only push.
c. (actually a special case of #b) IDEA is capable to perform automatic pull before push, which means that origin/master will change not only by pushed commits, but by pulled ones as well.

So currently Git plugin doesn't provide the API to perform the requested task. Probably the best place to insert such capabitilities would be the GitPusher: it already shows a notification after successful push, it could provide 3rd-party plugins with this information as well.

And which task in general are you trying to solve?

0
Comment actions Permalink

In general I'm trying to hook up into different git4idea events to make a nice visualization of what actions were performed on a local repo.

How can I contribute changes to git4idea code base? Do you accept and merge github pull requests? Or is github just a read-only clone of your other repo?

0
Comment actions Permalink

We do accept pull requests: github.com is a read-only mirror indeed, but we use its pull request UI & accept them manually.

But please note that even if you embed into every command executed from IDEA, you won't be able to track changes which were made from the command line.

Maybe reflog visualization can be valuable.

0
Comment actions Permalink

Has this change been ever made?

0

Please sign in to leave a comment.