Search in sources :

Example 11 with VcsRootImpl

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

the class AgentVcsSupportTest method build_on_pull_request.

@TestFor(issues = "TW-31039")
@Test(dataProvider = "mirrors")
public void build_on_pull_request(Boolean useMirrors) throws Exception {
    // Remote repo contains a pull request branch refs/changes/2/1 which is not under refs/heads/*,
    // this branch points to a commit which is not reachable from the default branch in vcs root
    // and from any other branches under refs/heads/.
    // Ensure that once we pass a pull request branch name, checkout it successful
    VcsRootImpl root = createRoot(myMainRepo, "master");
    String pullRequestCommit = "ea5e05051fbfaa7d8da97586807b009cbfebae9d";
    AgentRunningBuild build = createRunningBuild(map(PluginConfigImpl.USE_MIRRORS, String.valueOf(useMirrors), GitUtils.getGitRootBranchParamName(root), "refs/changes/2/1"));
    myVcsSupport.updateSources(root, CheckoutRules.DEFAULT, pullRequestCommit, myCheckoutDir, build, false);
}
Also used : VcsRootImpl(jetbrains.buildServer.vcs.impl.VcsRootImpl) Test(org.testng.annotations.Test) TestFor(jetbrains.buildServer.util.TestFor)

Example 12 with VcsRootImpl

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

the class AgentVcsSupportTest method fetch_interrupted.

@TestFor(issues = "TW-65373")
public void fetch_interrupted() throws Exception {
    MockFS fs = new MockFS();
    LoggingGitMetaFactory loggingFactory = new LoggingGitMetaFactory();
    myVcsSupport = myBuilder.setGitMetaFactory(loggingFactory).setFS(fs).build();
    File repo = dataFile("repo_for_fetch.1");
    File remoteRepo = myTempFiles.createTempDir();
    copyRepository(repo, remoteRepo);
    // run build to prepare mirror
    VcsRootImpl root = vcsRoot().withAgentGitPath(getGitPath()).withFetchUrl(GitUtils.toURL(remoteRepo)).build();
    myVcsSupport.updateSources(root, CheckoutRules.DEFAULT, "add81050184d3c818560bdd8839f50024c188586", myCheckoutDir, createRunningBuild(true), false);
    // update remote repo: add personal branch
    delete(remoteRepo);
    File updatedRepo = dataFile("repo_for_fetch.2.personal");
    copyRepository(updatedRepo, remoteRepo);
    AtomicInteger invocationCount = new AtomicInteger(0);
    loggingFactory.addCallback(FetchCommand.class.getName() + ".call", new GitCommandProxyCallback() {

        @Override
        public Optional<Object> call(final Method method, final Object[] args) throws VcsException {
            if (invocationCount.getAndIncrement() == 0)
                throw new VcsException(new InterruptedException());
            return Optional.empty();
        }
    });
    File mirror = myBuilder.getMirrorManager().getMirrorDir(GitUtils.toURL(remoteRepo));
    VcsRootImpl root2 = vcsRoot().withAgentGitPath(getGitPath()).withBranch("refs/heads/personal").withFetchUrl(GitUtils.toURL(remoteRepo)).build();
    fs.makeDeleteFail(mirror);
    try {
        AgentRunningBuild build = runningBuild().useLocalMirrors(true).withAgentConfiguration(myBuilder.getAgentConfiguration()).build();
        myVcsSupport.updateSources(root2, CheckoutRules.DEFAULT, "d47dda159b27b9a8c4cee4ce98e4435eb5b17168", myCheckoutDir, build, false);
        fail("Should fail");
    } catch (VcsException e) {
        File mirrorAfterBuild = myBuilder.getMirrorManager().getMirrorDir(GitUtils.toURL(remoteRepo));
        // should fail on first fetch attempt and not remap or delete the mirror
        then(mirrorAfterBuild).isEqualTo(mirror);
        then(invocationCount.get()).isEqualTo(1);
    }
}
Also used : AfterMethod(org.testng.annotations.AfterMethod) Method(java.lang.reflect.Method) BeforeMethod(org.testng.annotations.BeforeMethod) VcsRootImpl(jetbrains.buildServer.vcs.impl.VcsRootImpl) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) VcsException(jetbrains.buildServer.vcs.VcsException) GitTestUtil.dataFile(jetbrains.buildServer.buildTriggers.vcs.git.tests.GitTestUtil.dataFile) File(java.io.File) TestFor(jetbrains.buildServer.util.TestFor)

Example 13 with VcsRootImpl

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

the class TestConnectionTest method testConnection_should_validate_branchSpec.

public void testConnection_should_validate_branchSpec() throws Exception {
    VcsRootImpl root = vcsRoot().withFetchUrl(getRemoteRepositoryUrl("repo.git")).withBranch("master").withBranchSpec("+:/refs/heads/*").build();
    try {
        myGit.testConnection(root);
        fail("Test connection should validate branchSpec");
    } catch (VcsException e) {
        assertTrue(e.getMessage().contains("pattern should not start with /"));
    }
}
Also used : VcsRootImpl(jetbrains.buildServer.vcs.impl.VcsRootImpl) VcsException(jetbrains.buildServer.vcs.VcsException)

Example 14 with VcsRootImpl

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

the class TestConnectionTest method testConnection_should_throw_exception_for_anonymous_git_url_with_username.

public void testConnection_should_throw_exception_for_anonymous_git_url_with_username() throws Exception {
    ServerPluginConfig config = pluginConfig().withDotBuildServerDir(myTempFiles.createTempDir()).setIdleTimeoutSeconds(2).setFetchTimeout(2).setCurrentStateTimeoutSeconds(2).build();
    myGit = gitSupport().withServerPaths(myPaths).withPluginConfig(config).build();
    String url = "git://git@some.org/repository";
    VcsRootImpl root = vcsRoot().withFetchUrl(url).build();
    try {
        myGit.testConnection(root);
        fail("should fail, because native git fails for such url");
    } catch (VcsException e) {
        assertTrue(e.getMessage().contains("Incorrect url " + url + ": anonymous git url should not contain a username"));
    }
    // that means old roots that have such urls and use server-side checkout will still work
    try {
        myGit.collectChanges(root, "f3f826ce85d6dad25156b2d7550cedeb1a422f4c", "ce6044093939bb47283439d97a1c80f759669ff5", CheckoutRules.DEFAULT);
        fail("should fail, because no such root exists");
    } catch (VcsException e) {
        assertFalse(e.getMessage().contains("Incorrect url " + url + ": anonymous git url should not contain a username"));
    }
}
Also used : VcsRootImpl(jetbrains.buildServer.vcs.impl.VcsRootImpl) VcsException(jetbrains.buildServer.vcs.VcsException)

Example 15 with VcsRootImpl

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

the class TransportFactoryTest method createTransport.

private Transport createTransport(TransportFactory factory) throws Exception {
    File original = dataFile("repo.git");
    File copy = myTempFiles.createTempDir();
    FileUtil.copyDir(original, copy);
    VcsRootImpl root = getVcsRoot(copy);
    MirrorManager mirrorManager = new MirrorManagerImpl(myConfigBuilder.build(), new HashCalculatorImpl(), new RemoteRepositoryUrlInvestigatorImpl());
    GitVcsRoot gitRoot = new GitVcsRoot(mirrorManager, root, new URIishHelperImpl());
    Repository repository = new RepositoryBuilder().setGitDir(copy).setBare().build();
    return factory.createTransport(repository, new URIish(GitUtils.toURL(original)), gitRoot.getAuthSettings());
}
Also used : URIish(org.eclipse.jgit.transport.URIish) Repository(org.eclipse.jgit.lib.Repository) VcsRootImpl(jetbrains.buildServer.vcs.impl.VcsRootImpl) RepositoryBuilder(org.eclipse.jgit.lib.RepositoryBuilder) GitTestUtil.dataFile(jetbrains.buildServer.buildTriggers.vcs.git.tests.GitTestUtil.dataFile) File(java.io.File)

Aggregations

VcsRootImpl (jetbrains.buildServer.vcs.impl.VcsRootImpl)51 File (java.io.File)35 GitTestUtil.dataFile (jetbrains.buildServer.buildTriggers.vcs.git.tests.GitTestUtil.dataFile)34 TestFor (jetbrains.buildServer.util.TestFor)26 Test (org.testng.annotations.Test)25 VcsException (jetbrains.buildServer.vcs.VcsException)10 FileUtil.writeFile (jetbrains.buildServer.util.FileUtil.writeFile)9 LockFile (org.eclipse.jgit.internal.storage.file.LockFile)9 StoredConfig (org.eclipse.jgit.lib.StoredConfig)7 BeforeMethod (org.testng.annotations.BeforeMethod)7 Method (java.lang.reflect.Method)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 AgentRunningBuild (jetbrains.buildServer.agent.AgentRunningBuild)6 AfterMethod (org.testng.annotations.AfterMethod)6 CheckoutRules (jetbrains.buildServer.vcs.CheckoutRules)5 NotNull (org.jetbrains.annotations.NotNull)5 JSchException (com.jcraft.jsch.JSchException)4 Repository (org.eclipse.jgit.lib.Repository)4 ServerPaths (jetbrains.buildServer.serverSide.ServerPaths)3 VcsRootSshKeyManager (jetbrains.buildServer.ssh.VcsRootSshKeyManager)3