I am developing a plugin to work with Git. I want to open the Git windows and focus on a special commit by the commit id.
I found I can open the Git window with this code:
ProjectLevelVcsManager.getInstance(project).showConsole();
But I have no idea how to focus on a special commit.
I solve the problem,Here is the code :
String commitId = "123456"; //suppose it is commit id
VcsLogContentUtil.runInMainLog(project,(logUi) -> jumpToRevisionUnderProgress(project,logUi,commitId));
private void jumpToRevisionUnderProgress(Project project,VcsLogUiEx logUi,String commitId){
//some null check
//....
Future<Boolean> future = VcsLogNavigationUtil.jumpToHash(logUi, commitId, false, true);
if (!future.isDone()) {
ProgressManager.getInstance().run(new Task.Backgroundable(project,
"my title", false,PerformInBackgroundOption.ALWAYS_BACKGROUND) {
@Override
public void run(@NotNull ProgressIndicator indicator) {
try {
future.get();
}
catch (CancellationException | InterruptedException ignored) {
}
catch (ExecutionException e) {
LOG.error(e);
}
}
});
}
}
Also see IDEA Community