Search in sources :

Example 51 with VcsException

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

the class TestConnectionTest method testConnection_should_not_be_blocked_by_long_fetch.

public void testConnection_should_not_be_blocked_by_long_fetch() throws Exception {
    PluginConfigBuilder config = pluginConfig().withDotBuildServerDir(myTempFiles.createTempDir()).setSeparateProcessForFetch(false);
    final Semaphore fetchStarted = new Semaphore(1);
    final Semaphore fetchCanFinish = new Semaphore(1);
    final GitVcsSupport git = gitSupport().withBeforeFetchHook(new Runnable() {

        public void run() {
            fetchStarted.release();
            fetchCanFinish.acquireUninterruptibly();
        }
    }).withPluginConfig(config).build();
    final VcsRoot root = vcsRoot().withFetchUrl(getRemoteRepositoryUrl("repo.git")).build();
    // don't allow fetch to start
    fetchStarted.acquireUninterruptibly();
    // don't allow fetch to finish
    fetchCanFinish.acquireUninterruptibly();
    Thread longFetch = new Thread(new Runnable() {

        public void run() {
            try {
                git.collectChanges(root, "2276eaf76a658f96b5cf3eb25f3e1fda90f6b653", "ad4528ed5c84092fdbe9e0502163cf8d6e6141e7", CheckoutRules.DEFAULT);
            } catch (VcsException e) {
                e.printStackTrace();
            }
        }
    });
    longFetch.start();
    Assert.assertTrue(fetchStarted.tryAcquire(10, TimeUnit.SECONDS));
    // test connection during long fetch
    git.testConnection(root);
    // allow fetch to finish
    fetchCanFinish.release();
}
Also used : VcsException(jetbrains.buildServer.vcs.VcsException) Semaphore(java.util.concurrent.Semaphore) VcsRoot(jetbrains.buildServer.vcs.VcsRoot)

Example 52 with VcsException

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

the class TestConnectionTest method wrong_github_username.

@TestFor(issues = "TW-24074")
@Test(dataProvider = "common-github-auth-errors")
public void wrong_github_username(@NotNull final String error) {
    TransportFactory factoryWithGivenError = new TransportFactory() {

        public Transport createTransport(@NotNull Repository r, @NotNull URIish url, @NotNull AuthSettings authSettings) throws NotSupportedException, VcsException, TransportException {
            return createTransport(r, url, authSettings, 60);
        }

        public Transport createTransport(@NotNull Repository r, @NotNull URIish url, @NotNull AuthSettings authSettings, int timeoutSeconds) throws NotSupportedException, VcsException, TransportException {
            throw new TransportException(url.toString() + ": " + error, new JSchException(error));
        }

        @NotNull
        @Override
        public SshSessionFactory getSshSessionFactory(@NotNull URIish url, @NotNull AuthSettings authSettings) throws VcsException {
            throw new UnsupportedOperationException();
        }
    };
    myGit = gitSupport().withTransportFactory(factoryWithGivenError).withServerPaths(myPaths).build();
    String wrongUsername = "user";
    VcsRootImpl root = vcsRoot().withFetchUrl("git@github.com:user/repo.git").withBranch("master").withAuthMethod(AuthenticationMethod.PRIVATE_KEY_DEFAULT).withUsername(wrongUsername).build();
    try {
        myGit.testConnection(root);
        fail("should fail during transport creation");
    } catch (VcsException e) {
        assertTrue(e.getMessage(), e.getMessage().contains("Wrong username: '" + wrongUsername + "', GitHub expects the 'git' username"));
    }
}
Also used : URIish(org.eclipse.jgit.transport.URIish) JSchException(com.jcraft.jsch.JSchException) Repository(org.eclipse.jgit.lib.Repository) VcsRootImpl(jetbrains.buildServer.vcs.impl.VcsRootImpl) VcsException(jetbrains.buildServer.vcs.VcsException) NotNull(org.jetbrains.annotations.NotNull) TransportException(org.eclipse.jgit.errors.TransportException) Test(org.testng.annotations.Test) TestFor(jetbrains.buildServer.util.TestFor)

Example 53 with VcsException

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

the class FetchCommandImplTest method should_throw_special_exception_when_stderr_mentions_broken_index.

@TestFor(issues = "TW-18853")
public void should_throw_special_exception_when_stderr_mentions_broken_index() throws VcsException {
    AgentGitCommandLine failedCmd = new AgentGitCommandLine(null, getFakeGen(), new StubContext()) {

        @Override
        public ExecResult run(@NotNull GitCommandSettings settings) throws VcsException {
            throw new VcsException("fatal: index file smaller than expected");
        }
    };
    FetchCommand fetch = new FetchCommandImpl(failedCmd).setRefspec("+refs/heads/*:refs/remotes/origin/*").setTimeout(3600).setAuthSettings(getEmptyAuthSettings());
    try {
        fetch.call();
    } catch (GitIndexCorruptedException e) {
    // expected
    } catch (VcsException e) {
        fail("GitIndexCorruptedException should be thrown");
    }
}
Also used : GitCommandSettings(jetbrains.buildServer.buildTriggers.vcs.git.command.GitCommandSettings) FetchCommandImpl(jetbrains.buildServer.buildTriggers.vcs.git.command.impl.FetchCommandImpl) GitIndexCorruptedException(jetbrains.buildServer.buildTriggers.vcs.git.command.errors.GitIndexCorruptedException) FetchCommand(jetbrains.buildServer.buildTriggers.vcs.git.command.FetchCommand) StubContext(jetbrains.buildServer.buildTriggers.vcs.git.command.impl.StubContext) VcsException(jetbrains.buildServer.vcs.VcsException) AgentGitCommandLine(jetbrains.buildServer.buildTriggers.vcs.git.agent.AgentGitCommandLine) NotNull(org.jetbrains.annotations.NotNull) TestFor(jetbrains.buildServer.util.TestFor)

Example 54 with VcsException

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

the class RepositoryManagerTest method should_throw_exception_when_repository_configured_for_different_url.

public void should_throw_exception_when_repository_configured_for_different_url() throws Exception {
    RepositoryManager repositoryManager = getRepositoryManager();
    File dir = repositoryManager.getMirrorDir("git://some.org/repo.git");
    repositoryManager.openRepository(new URIish("git://some.org/repo.git"));
    try {
        repositoryManager.openRepository(dir, new URIish("git://some.org/other-repo.git"));
        fail("Expect error, dir is used for another url");
    } catch (VcsException e) {
        assertTrue(true);
    }
}
Also used : URIish(org.eclipse.jgit.transport.URIish) VcsException(jetbrains.buildServer.vcs.VcsException) File(java.io.File)

Example 55 with VcsException

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

the class AgentStartupGitDetector method afterAgentConfigurationLoaded.

@Override
public void afterAgentConfigurationLoaded(@NotNull BuildAgent agent) {
    if (pathToGitConfigured(agent)) {
        LOG.debug("Path to git configured, will not try to detect git");
        return;
    }
    for (String path : getCandidatePaths()) {
        try {
            final GitVersion version = new AgentGitFacadeImpl(path).version().call();
            agent.getConfiguration().addEnvironmentVariable(Constants.TEAMCITY_AGENT_GIT_VERSION, version.toString());
            if (version.isSupported()) {
                LOG.info("Detect git at " + path);
                setPathToGit(agent, path);
                break;
            } else {
                LOG.debug("TeamCity supports Git version " + GitVersion.MIN + " or higher, git at " + path + " has version " + version + " and will not be used");
            }
        } catch (VcsException e) {
            LOG.debug("Cannot run git at " + path, e);
        }
    }
    detectGitLfs(agent);
    detectSSH(agent);
}
Also used : GitVersion(jetbrains.buildServer.buildTriggers.vcs.git.GitVersion) VcsException(jetbrains.buildServer.vcs.VcsException)

Aggregations

VcsException (jetbrains.buildServer.vcs.VcsException)79 File (java.io.File)34 NotNull (org.jetbrains.annotations.NotNull)22 GitTestUtil.dataFile (jetbrains.buildServer.buildTriggers.vcs.git.tests.GitTestUtil.dataFile)13 IOException (java.io.IOException)12 TestFor (jetbrains.buildServer.util.TestFor)11 GeneralCommandLine (com.intellij.execution.configurations.GeneralCommandLine)10 Method (java.lang.reflect.Method)10 ExecResult (jetbrains.buildServer.ExecResult)10 VcsRootImpl (jetbrains.buildServer.vcs.impl.VcsRootImpl)10 AfterMethod (org.testng.annotations.AfterMethod)10 BeforeMethod (org.testng.annotations.BeforeMethod)10 VcsRoot (jetbrains.buildServer.vcs.VcsRoot)9 Repository (org.eclipse.jgit.lib.Repository)9 URIish (org.eclipse.jgit.transport.URIish)9 Nullable (org.jetbrains.annotations.Nullable)8 SimpleCommandLineProcessRunner (jetbrains.buildServer.SimpleCommandLineProcessRunner)5 GitExec (jetbrains.buildServer.buildTriggers.vcs.git.command.GitExec)5 CheckoutRules (jetbrains.buildServer.vcs.CheckoutRules)5 RefSpec (org.eclipse.jgit.transport.RefSpec)5