コード例 #1
0
  @Override
  public void doCheckout(@NotNull final Project project, @Nullable final Listener listener) {
    if (!GerritUtil.testGitExecutable(project)) {
      return;
    }
    BasicAction.saveAll();
    List<ProjectInfo> availableProjects = null;
    try {
      availableProjects = GerritUtil.getAvailableProjects(project);
    } catch (IOException e) {
      LOG.info(e);
      GerritUtil.notifyError(
          project,
          "Couldn't get the list of Gerrit repositories",
          GerritUtil.getErrorTextFromException(e));
    }
    if (availableProjects == null) {
      return;
    }
    Collections.sort(
        availableProjects,
        new Comparator<ProjectInfo>() {
          @Override
          public int compare(final ProjectInfo p1, final ProjectInfo p2) {
            return p1.getId().compareTo(p2.getId());
          }
        });

    final GitCloneDialog dialog = new GitCloneDialog(project);
    // Add predefined repositories to history
    for (int i = availableProjects.size() - 1; i >= 0; i--) {
      dialog.prependToHistory(
          GerritSettings.getInstance().getHost() + '/' + availableProjects.get(i).getId());
    }
    dialog.show();
    if (!dialog.isOK()) {
      return;
    }
    dialog.rememberSettings();
    final VirtualFile destinationParent =
        LocalFileSystem.getInstance().findFileByIoFile(new File(dialog.getParentDirectory()));
    if (destinationParent == null) {
      return;
    }
    final String sourceRepositoryURL = dialog.getSourceRepositoryURL();
    final String directoryName = dialog.getDirectoryName();
    final String parentDirectory = dialog.getParentDirectory();

    Git git = ServiceManager.getService(Git.class);
    GitCheckoutProvider.clone(
        project,
        git,
        listener,
        destinationParent,
        sourceRepositoryURL,
        directoryName,
        parentDirectory);
  }