IDEA插件:如何打开git窗口并通过commit id关注特殊的commit?

3z6pesqy  于 12个月前  发布在  Git
关注(0)|答案(1)|浏览(117)

我正在开发一个与Git一起工作的插件。我想打开Git窗口,并通过提交ID关注一个特殊的提交。
我发现我可以用以下代码打开Git窗口:

ProjectLevelVcsManager.getInstance(project).showConsole();

字符串
但我不知道如何专注于一个特殊的承诺。

jogvjijk

jogvjijk1#

我解决了这个问题,下面是代码:

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);
          }
        }
      });
    }
 }

字符串
参见IDEA Community

相关问题