Search in sources :

Example 71 with VcsException

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

the class AgentVcsSupportTest method do_not_delete_mirror_on_timeout.

public void do_not_delete_mirror_on_timeout() throws Exception {
    MockFS fs = new MockFS();
    myVcsSupport = myBuilder.setFS(fs).build();
    String unreachableRepository = "git://some.org/unreachable.git";
    File mirror = myBuilder.getMirrorManager().getMirrorDir(unreachableRepository);
    // if plugin will remove mirror it will fail and try to remap
    fs.makeDeleteFail(mirror);
    myRoot = vcsRoot().withAgentGitPath(getGitPath()).withFetchUrl(unreachableRepository).build();
    try {
        String revision = "abababababababababababababababababababab";
        AgentRunningBuild build = runningBuild().useLocalMirrors(true).withAgentConfiguration(myBuilder.getAgentConfiguration()).sharedConfigParams("teamcity.git.idle.timeout.seconds", "1").build();
        myVcsSupport.updateSources(myRoot, CheckoutRules.DEFAULT, revision, myCheckoutDir, build, false);
        fail("update on unreachable repository should fail");
    } catch (VcsException e) {
        if (e instanceof GitExecTimeout) {
            File mirrorAfterFailure = myBuilder.getMirrorManager().getMirrorDir(unreachableRepository);
            then(mirrorAfterFailure).overridingErrorMessage("Mirror changed after error " + e.toString()).isEqualTo(// failure should not cause delete or remap
            mirror);
        } else {
            // on some platforms fetch from unknown host doesn't result in timeout error
            throw new SkipException("Not a timeout error: " + e.toString());
        }
    }
}
Also used : GitExecTimeout(jetbrains.buildServer.buildTriggers.vcs.git.command.errors.GitExecTimeout) VcsException(jetbrains.buildServer.vcs.VcsException) SkipException(org.testng.SkipException) GitTestUtil.dataFile(jetbrains.buildServer.buildTriggers.vcs.git.tests.GitTestUtil.dataFile) File(java.io.File)

Example 72 with VcsException

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

the class AgentVcsSupportTest method shallow_fetch_tag.

@Test
public void shallow_fetch_tag() throws Exception {
    final File remote = dataFile("repo_for_shallow_fetch.git");
    final LoggingGitMetaFactory loggingFactory = new LoggingGitMetaFactory();
    loggingFactory.addCallback(FetchCommand.class.getName() + ".setRefspec", new GitCommandProxyCallback() {

        @Override
        public Optional<Object> call(final Method method, final Object[] args) throws VcsException {
            if (args.length == 1 && "+refs/tags/tag1:refs/tags/tag1".equals(args[0]))
                return null;
            fail("Unexpected fetch refspec " + Arrays.toString(args));
            return null;
        }
    });
    loggingFactory.addCallback(FetchCommand.class.getName() + ".setDepth", new GitCommandProxyCallback() {

        @Override
        public Optional<Object> call(final Method method, final Object[] args) throws VcsException {
            if (args.length == 1 && Integer.valueOf(1).equals(args[0]))
                return null;
            fail("Unexpected fetch depth " + Arrays.toString(args));
            return null;
        }
    });
    myVcsSupport = myBuilder.setGitMetaFactory(loggingFactory).setFS(new MockFS()).build();
    final AgentRunningBuild build = createRunningBuild(CollectionsUtil.asMap(PluginConfigImpl.USE_SHALLOW_CLONE_INTERNAL, "true"));
    myVcsSupport.updateSources(createRoot(remote, "refs/tags/tag1"), new CheckoutRules(""), "fd1eb9776b5fad5cc433586f7933811c6853917d", myCheckoutDir, build, false);
    assertEquals(1, loggingFactory.getNumberOfCalls(FetchCommand.class));
    final Repository checkout = new RepositoryBuilder().setWorkTree(myCheckoutDir).build();
    final Ref main = checkout.getRefDatabase().findRef("refs/tags/tag1");
    assertNotNull(main);
    assertEquals("fd1eb9776b5fad5cc433586f7933811c6853917d", main.getObjectId().getName());
    assertNull(checkout.getRefDatabase().findRef("refs/tags/tag2"));
    assertFalse(checkout.getObjectDatabase().has(ObjectId.fromString("a1d6299597f8d6f6d8316577c46cc8fffd657d5e")));
}
Also used : CheckoutRules(jetbrains.buildServer.vcs.CheckoutRules) AfterMethod(org.testng.annotations.AfterMethod) Method(java.lang.reflect.Method) BeforeMethod(org.testng.annotations.BeforeMethod) FetchCommand(jetbrains.buildServer.buildTriggers.vcs.git.command.FetchCommand) VcsException(jetbrains.buildServer.vcs.VcsException) GitTestUtil.dataFile(jetbrains.buildServer.buildTriggers.vcs.git.tests.GitTestUtil.dataFile) File(java.io.File) Test(org.testng.annotations.Test)

Example 73 with VcsException

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

the class AgentVcsSupportTest method shallow_fetch.

@Test
public void shallow_fetch() throws Exception {
    final File remote = dataFile("repo_for_shallow_fetch.git");
    final LoggingGitMetaFactory loggingFactory = new LoggingGitMetaFactory();
    loggingFactory.addCallback(FetchCommand.class.getName() + ".setRefspec", new GitCommandProxyCallback() {

        @Override
        public Optional<Object> call(final Method method, final Object[] args) throws VcsException {
            if (args.length == 1 && "+fd1eb9776b5fad5cc433586f7933811c6853917d:refs/remotes/origin/main".equals(args[0]))
                return null;
            fail("Unexpected fetch refspec " + Arrays.toString(args));
            return null;
        }
    });
    loggingFactory.addCallback(FetchCommand.class.getName() + ".setDepth", new GitCommandProxyCallback() {

        @Override
        public Optional<Object> call(final Method method, final Object[] args) throws VcsException {
            if (args.length == 1 && Integer.valueOf(1).equals(args[0]))
                return null;
            fail("Unexpected fetch depth " + Arrays.toString(args));
            return null;
        }
    });
    myVcsSupport = myBuilder.setGitMetaFactory(loggingFactory).setFS(new MockFS()).build();
    final AgentRunningBuild build = createRunningBuild(CollectionsUtil.asMap(PluginConfigImpl.USE_SHALLOW_CLONE_INTERNAL, "true"));
    myVcsSupport.updateSources(createRoot(remote, "refs/heads/main"), new CheckoutRules(""), "fd1eb9776b5fad5cc433586f7933811c6853917d", myCheckoutDir, build, false);
    assertEquals(1, loggingFactory.getNumberOfCalls(FetchCommand.class));
    final Repository checkout = new RepositoryBuilder().setWorkTree(myCheckoutDir).build();
    assertEquals("main", checkout.getBranch());
    final Ref main = checkout.getRefDatabase().findRef("main");
    assertNotNull(main);
    assertEquals("fd1eb9776b5fad5cc433586f7933811c6853917d", main.getObjectId().getName());
    assertNotNull(checkout.getRefDatabase().findRef("refs/remotes/origin/main"));
    assertNotNull(checkout.getRefDatabase().findRef("refs/tags/tag1"));
    assertNull(checkout.getRefDatabase().findRef("refs/tags/tag2"));
    assertFalse(checkout.getObjectDatabase().has(ObjectId.fromString("a1d6299597f8d6f6d8316577c46cc8fffd657d5e")));
}
Also used : CheckoutRules(jetbrains.buildServer.vcs.CheckoutRules) AfterMethod(org.testng.annotations.AfterMethod) Method(java.lang.reflect.Method) BeforeMethod(org.testng.annotations.BeforeMethod) FetchCommand(jetbrains.buildServer.buildTriggers.vcs.git.command.FetchCommand) VcsException(jetbrains.buildServer.vcs.VcsException) GitTestUtil.dataFile(jetbrains.buildServer.buildTriggers.vcs.git.tests.GitTestUtil.dataFile) File(java.io.File) Test(org.testng.annotations.Test)

Example 74 with VcsException

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

the class AgentVcsSupportTest method should_retry_fetch_mirror.

@TestFor(issues = "TW-56415")
public void should_retry_fetch_mirror() 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);
    // make first two fetches in local mirror to fail:
    AtomicInteger invocationCount = new AtomicInteger(0);
    loggingFactory.addCallback(BaseAuthCommandImpl.class.getName() + ".doRunCmd", new GitCommandProxyCallback() {

        @Override
        public Optional<Object> call(final Method method, final Object[] args) throws VcsException {
            if (invocationCount.getAndIncrement() <= 1)
                throw new VcsException("TEST ERROR");
            return null;
        }
    });
    File mirror = myBuilder.getMirrorManager().getMirrorDir(GitUtils.toURL(remoteRepo));
    // try to fetch unknown branch, first fetch fails, second succeeds. If it's not ensure that delete of the mirror also fails
    // build should succeed anyway
    fs.makeDeleteFail(mirror);
    VcsRootImpl root2 = vcsRoot().withAgentGitPath(getGitPath()).withBranch("refs/heads/personal").withFetchUrl(GitUtils.toURL(remoteRepo)).build();
    AgentRunningBuild build = runningBuild().useLocalMirrors(true).withAgentConfiguration(myBuilder.getAgentConfiguration()).sharedConfigParams("teamcity.internal.git.remoteOperationAttempts", "3").build();
    myVcsSupport.updateSources(root2, CheckoutRules.DEFAULT, "d47dda159b27b9a8c4cee4ce98e4435eb5b17168", myCheckoutDir, build, false);
    File mirrorAfterBuild = myBuilder.getMirrorManager().getMirrorDir(GitUtils.toURL(remoteRepo));
    // repository was not remapped to another dir
    then(mirrorAfterBuild).isEqualTo(mirror);
}
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 75 with VcsException

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

the class AgentVcsSupportTest method do_not_delete_mirror_if_remote_ref_not_found.

public void do_not_delete_mirror_if_remote_ref_not_found() throws Exception {
    MockFS fs = new MockFS();
    myVcsSupport = myBuilder.setFS(fs).build();
    File mirror = myBuilder.getMirrorManager().getMirrorDir(GitUtils.toURL(myMainRepo));
    // if plugin will remove mirror it will fail and try to remap
    fs.makeDeleteFail(mirror);
    myRoot = vcsRoot().withBranch("refs/heads/unknown").withAgentGitPath(getGitPath()).withFetchUrl(GitUtils.toURL(myMainRepo)).build();
    try {
        String unknownRevision = "abababababababababababababababababababab";
        myVcsSupport.updateSources(myRoot, CheckoutRules.DEFAULT, unknownRevision, myCheckoutDir, createRunningBuild(true), false);
        fail("update on unknown branch should fail");
    } catch (VcsException e) {
        File mirrorAfterFailure = myBuilder.getMirrorManager().getMirrorDir(GitUtils.toURL(myMainRepo));
        // failure should not cause delete or remap
        then(mirrorAfterFailure).isEqualTo(mirror);
    }
}
Also used : VcsException(jetbrains.buildServer.vcs.VcsException) GitTestUtil.dataFile(jetbrains.buildServer.buildTriggers.vcs.git.tests.GitTestUtil.dataFile) File(java.io.File)

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