public AgentCheckoutAbility canCheckout()

in git-agent/src/main/java/jetbrains/buildServer/buildTriggers/vcs/git/agent/GitAgentVcsSupport.java [139:194]


  public AgentCheckoutAbility canCheckout(@NotNull final VcsRoot vcsRoot, @NotNull CheckoutRules checkoutRules, @NotNull final AgentRunningBuild build) {
    AgentPluginConfig config;
    try {
      config = getAndCacheConfig(build, vcsRoot);
    } catch (VcsException e) {
      return AgentCheckoutAbility.noVcsClientOnAgent(e.getMessage());
    }

    Pair<CheckoutMode, String> pathAndMode = getTargetPathAndMode(checkoutRules);
    String targetDir = pathAndMode.second;
    if (targetDir == null) {
      return AgentCheckoutAbility.notSupportedCheckoutRules("Unsupported rules for agent-side checkout: " + checkoutRules.getAsString());
    }

    if (pathAndMode.first == CheckoutMode.SPARSE_CHECKOUT && !canUseSparseCheckout(config)) {
      return AgentCheckoutAbility.notSupportedCheckoutRules("Cannot perform sparse checkout using git " + config.getGitExec().getVersion());
    }

    try {
      GitVcsRoot gitRoot = new GitVcsRoot(myMirrorManager, vcsRoot, new URIishHelperImpl(), detectExtraHTTPCredentialsInBuild(build));
      UpdaterImpl.checkAuthMethodIsSupported(gitRoot, config);
    } catch (VcsException e) {
      return AgentCheckoutAbility.canNotCheckout(e.getMessage());
    }

    final List<VcsRootEntry> rootEntries = build.getVcsRootEntries();
    if (rootEntries.size() > 1) {
      for (VcsRootEntry entry : rootEntries) {
        VcsRoot otherRoot = entry.getVcsRoot();
        if (vcsRoot.equals(otherRoot))
          continue;

        if (isGitVcsRoot(entry)) {
          AgentPluginConfig otherConfig;
          try {
            otherConfig = getAndCacheConfig(build, otherRoot);
          } catch (VcsException e) {
            continue;//appropriate reason will be returned during otherRoot check
          }
          Pair<CheckoutMode, String> otherPathAndMode = getTargetPathAndMode(entry.getCheckoutRules());
          if (otherPathAndMode.first == CheckoutMode.SPARSE_CHECKOUT && !canUseSparseCheckout(otherConfig)) {
            continue;//appropriate reason will be returned during otherRoot check
          }
          String entryPath = otherPathAndMode.second;
          if (targetDir.equals(entryPath))
            return AgentCheckoutAbility.canNotCheckout("Cannot checkout VCS root '" + vcsRoot.getName() + "' into the same directory as VCS root '" + otherRoot.getName() + "'");

        } else if (CleanCommandUtil.isCleanEnabled(vcsRoot) && CleanCommandUtil.isClashingTargetPath(targetDir, entry, config.getGitVersion())) {
          // in this case git clean command may remove files which belong to the other root
          return AgentCheckoutAbility.canNotCheckout("Cannot checkout VCS root '" + vcsRoot.getName() + "' into the same directory as VCS root '" + otherRoot.getName() + "'");
        }
      }
    }

    return AgentCheckoutAbility.canCheckout();
  }