How to open the git windows and focuse on special brance and commit?

Answered

I developing a plugin work with git.And I want to open the git windows and focuse on special brance and commit by branch name and the commit id.

I found I can open the git window by code blew :

ProjectLevelVcsManager.getInstance(project).showConsole();

But I have no idea how to focuse on special branch and commit. I'll appreciate it if anyone give me a solution.

1
2 comments

Hi,

Please check git4idea.log.GitShowCommitInLogAction.

1

Thanks,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);
          }
        }
      });
    }
 }
0

Please sign in to leave a comment.