Diff of two git files Follow sreehari vadakkan Created June 18, 2015 13:19 I need to write a plugin which can show the diff of a branch and master given the repository link in diff window. How shall i proceed?
It seems that this functionality is already available in IntelliJ IDEA: select a file and invoke Git | Compare with Branch. Doesn't it suit well for you?
Is it possible to bind exactly this functionality to a self-written action? "Compare with branch" is a nice feature, but in my case i know the branch in every case and i dont want to select them first. i tried macros for example, but Macros arent suitable thatfore... macros are the badest feature in intellij by the way, you can not really do much with it.... however... is there a way to do this programatically?
It is possible to write a simple plugin which would provide your custom action with the specific logic you need. If you want to try, I can give you some directions on where to start from.
I`m writing currently a plugin to do code reviews within phpstorm based on bitbucket pullrequests. Some code snippets could help :-)
Here are some useful links (in case you didn't see them yet):
* Root SDK documentation page: http://www.jetbrains.org/intellij/sdk/docs/
* How to create AnAction: http://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/creating_an_action.html
Once you've got your AnAction, take a look at `GitCompareWithBranchAction` and its parent `DvcsCompareWithBranchAction`. Since you know the branch you want to compare, I guess, you don't need the popup there, so you can take the code from `showDiffWithBranchUnderModalProgress` directly (btw, the name method is incorrect: it is not modal anymore, I'll rename it).
Do i need a Action explicit? I Have a Toolwindow. Sorry I`m Java beginner!It looks like the following is what i need:
If you need to compare whole branches, not just the given file, the situation is even simpler: just use GitBrancher.compare(). It will compare branches in the background and show the dialog once ready.
GitBrancher is a Service, so you can call ServiceManager.getService(myProject, GitBrancher.class) to the the instance of it.
That sounds simple. But i dont have GitBrancher. Its part of git4idea, right? And thatfor i need to include as described by vikash kumar here https://intellij-support.jetbrains.com/hc/en-us/community/posts/207100489-How-to-get-current-git-branch-inside-StartActivity ... sorry again, its maybe too late :-)
Yes, vikash kumar has described everything correctly.
Hmmm i dont get it :-(
...but GitBrancher and GitCompareWithBranchAction is not available (https://github.com/JetBrains/intellij-community/blob/master/plugins/git4idea/src/git4idea/branch/GitBrancher.java)
So, where is my mistake :-/ ? Thank you
Your mistake is that you use some 3-party git4idea library which has nothing to do with the official git4idea plugin by JetBrains which is included in every IDEA installation (<IDEA install dir>/plugins/)
Aah i can take it directly from the sources of Intellij... i have assumed if i include the SDK sources that i include all in once. But there are plugin-sources which i can include seperatly.. OK...
Now it works basically. Thanks
Ah youre the author of that stuff :-) nice that you have time to help me :-)
OK.. back to the topic. I do not quite understand the call .compare() .
With this code i get the following result:
but i want the more simple version of it (the same as "compare with branch"):
...thanks for help again :-)
Then you can either look inside the implementation of "compare" and take the stuff you need, either look back at the GitCompareWithBranchAction and use the Git repository root folder as the FilePath.
sorry i dont get it! at least i tried
It depends on where do you want to invoke this action from, and which items do you want to compare.
At any case you can create a `GitFileRevision` object manually.
See also `GitCompareWithBranchAction`.
Thank you. Here is my Solution: