Search in sources :

Example 1 with GitVcsRoot

use of jetbrains.buildServer.buildTriggers.vcs.git.GitVcsRoot in project teamcity-git by JetBrains.

the class GitAgentVcsSupport method canCheckout.

@NotNull
@Override
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());
        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) {
                    // appropriate reason will be returned during otherRoot check
                    continue;
                }
                Pair<CheckoutMode, String> otherPathAndMode = getTargetPathAndMode(entry.getCheckoutRules());
                if (otherPathAndMode.first == CheckoutMode.SPARSE_CHECKOUT && !canUseSparseCheckout(otherConfig)) {
                    // appropriate reason will be returned during otherRoot check
                    continue;
                }
                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();
}
Also used : GitVcsRoot(jetbrains.buildServer.buildTriggers.vcs.git.GitVcsRoot) GitVcsRoot(jetbrains.buildServer.buildTriggers.vcs.git.GitVcsRoot) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with GitVcsRoot

use of jetbrains.buildServer.buildTriggers.vcs.git.GitVcsRoot in project teamcity-git by JetBrains.

the class AgentMirrorCleaner method getRunningBuildRepositories.

private Set<String> getRunningBuildRepositories(@NotNull DirectoryCleanersProviderContext context) {
    Set<String> repositories = new HashSet<String>();
    for (VcsRootEntry entry : context.getRunningBuild().getVcsRootEntries()) {
        VcsRoot root = entry.getVcsRoot();
        if (!Constants.VCS_NAME.equals(root.getVcsName()))
            continue;
        try {
            GitVcsRoot gitRoot = new AgentGitVcsRoot(myMirrorManager, root, myTokenStorage);
            String repositoryUrl = gitRoot.getRepositoryFetchURL().toString();
            LOG.debug("Repository " + repositoryUrl + " is used in the build, its mirror won't be cleaned");
            addRepositoryWithSubmodules(repositories, gitRoot.getRepositoryFetchURL().toString());
        } catch (VcsException e) {
            LOG.warn("Error while creating git root " + root.getName() + ". If the root has a mirror on agent, the mirror might be cleaned", e);
        }
    }
    return repositories;
}
Also used : VcsException(jetbrains.buildServer.vcs.VcsException) VcsRootEntry(jetbrains.buildServer.vcs.VcsRootEntry) GitVcsRoot(jetbrains.buildServer.buildTriggers.vcs.git.GitVcsRoot) VcsRoot(jetbrains.buildServer.vcs.VcsRoot) GitVcsRoot(jetbrains.buildServer.buildTriggers.vcs.git.GitVcsRoot)

Example 3 with GitVcsRoot

use of jetbrains.buildServer.buildTriggers.vcs.git.GitVcsRoot in project teamcity-git by JetBrains.

the class HttpUrlWithUsernameTest method getMirrorConfig.

@NotNull
private StoredConfig getMirrorConfig(@NotNull VcsRootImpl root) throws IOException, VcsException {
    GitVcsRoot gitRoot = new GitVcsRoot(myMirrorManager, root, new URIishHelperImpl());
    File mirrorDir = myMirrorManager.getMirrorDir(gitRoot.getRepositoryFetchURL().toString());
    Repository r = new RepositoryBuilder().setGitDir(mirrorDir).build();
    return r.getConfig();
}
Also used : GitTestUtil.copyRepository(jetbrains.buildServer.buildTriggers.vcs.git.tests.GitTestUtil.copyRepository) Repository(org.eclipse.jgit.lib.Repository) RepositoryBuilder(org.eclipse.jgit.lib.RepositoryBuilder) URIishHelperImpl(jetbrains.buildServer.buildTriggers.vcs.git.agent.URIishHelperImpl) GitVcsRoot(jetbrains.buildServer.buildTriggers.vcs.git.GitVcsRoot) GitTestUtil.dataFile(jetbrains.buildServer.buildTriggers.vcs.git.tests.GitTestUtil.dataFile) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

GitVcsRoot (jetbrains.buildServer.buildTriggers.vcs.git.GitVcsRoot)3 NotNull (org.jetbrains.annotations.NotNull)2 File (java.io.File)1 URIishHelperImpl (jetbrains.buildServer.buildTriggers.vcs.git.agent.URIishHelperImpl)1 GitTestUtil.copyRepository (jetbrains.buildServer.buildTriggers.vcs.git.tests.GitTestUtil.copyRepository)1 GitTestUtil.dataFile (jetbrains.buildServer.buildTriggers.vcs.git.tests.GitTestUtil.dataFile)1 VcsException (jetbrains.buildServer.vcs.VcsException)1 VcsRoot (jetbrains.buildServer.vcs.VcsRoot)1 VcsRootEntry (jetbrains.buildServer.vcs.VcsRootEntry)1 Repository (org.eclipse.jgit.lib.Repository)1 RepositoryBuilder (org.eclipse.jgit.lib.RepositoryBuilder)1