Search in sources :

Example 36 with VcsException

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

the class RetryTest method retryable.

@NotNull
private Retry.Retryable<Void> retryable(@NotNull final StringBuilder result, int failAttempts) {
    final Ref<Integer> attemptNum = new Ref(1);
    return new Retry.Retryable<Void>() {

        @Override
        public boolean requiresRetry(@NotNull final Exception e, int attempt, int maxAttempts) {
            return attempt < maxAttempts;
        }

        @Nullable
        @Override
        public Void call() throws VcsException {
            int num = attemptNum.get();
            try {
                if (num <= failAttempts)
                    throw new VcsException("the exception");
                return null;
            } finally {
                attemptNum.set(num + 1);
            }
        }

        @NotNull
        @Override
        public Logger getLogger() {
            return new DefaultLogger() {

                @Override
                public void debug(final String message) {
                    throw new UnsupportedOperationException();
                }

                @Override
                public void debug(final Throwable t) {
                    throw new UnsupportedOperationException();
                }

                @Override
                public void debug(final String message, final Throwable t) {
                    append("DEBUG", message, t);
                }

                private void append(final String category, final String message, final Throwable t) {
                    result.append(category).append(" ").append(message);
                    if (t != null) {
                        result.append(": ").append(t.getMessage());
                    }
                    result.append("\n");
                }

                @Override
                public void error(final String message, final Throwable t, final String... details) {
                    throw new UnsupportedOperationException();
                }

                @Override
                public void info(final String message) {
                    append("INFO", message, null);
                }

                @Override
                public void info(final String message, final Throwable t) {
                    append("INFO", message, t);
                }

                @Override
                public void warn(final String message, final Throwable t) {
                    append("WARN", message, t);
                }

                @Override
                public boolean isDebugEnabled() {
                    return true;
                }
            };
        }
    };
}
Also used : Ref(com.intellij.openapi.util.Ref) VcsException(jetbrains.buildServer.vcs.VcsException) NotNull(org.jetbrains.annotations.NotNull) DefaultLogger(com.intellij.openapi.diagnostic.DefaultLogger) VcsException(jetbrains.buildServer.vcs.VcsException) NotNull(org.jetbrains.annotations.NotNull)

Example 37 with VcsException

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

the class GitLabelingSupportTest method fail_labeling_when_heuristics_fails.

public void fail_labeling_when_heuristics_fails() throws Exception {
    myConfig.setUsePackHeuristic(true);
    myConfig.setFailLabelingWhenPackHeuristicsFail(true);
    GitVcsSupport git = buildGit();
    File remoteRepoDir = getRemoteRepositoryDir("repo_for_fetch.2");
    VcsRoot root = vcsRoot().withFetchUrl(remoteRepoDir).build();
    makeCloneOnServer(git, root);
    // erase commit in the remote repository
    FileUtil.delete(remoteRepoDir);
    remoteRepoDir.mkdirs();
    FileUtil.copyDir(getRemoteRepositoryDir("repo_for_fetch.1"), remoteRepoDir);
    try {
        // label erased commit
        String erasedCommit = "d47dda159b27b9a8c4cee4ce98e4435eb5b17168";
        git.getLabelingSupport().label("label", erasedCommit, root, CheckoutRules.DEFAULT);
        fail("Should fail labeling since heuristics fails");
    } catch (VcsException e) {
        assertTrue(true);
    }
}
Also used : GitVcsSupport(jetbrains.buildServer.buildTriggers.vcs.git.GitVcsSupport) VcsException(jetbrains.buildServer.vcs.VcsException) VcsRoot(jetbrains.buildServer.vcs.VcsRoot) File(java.io.File)

Example 38 with VcsException

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

the class RepositoryManagerTest method should_not_keep_repo_opened_in_case_of_error.

public void should_not_keep_repo_opened_in_case_of_error() throws Exception {
    File customDir = myTempFiles.createTempDir();
    FileUtil.delete(customDir);
    RepositoryManager repositoryManager = getRepositoryManager();
    Repository r1 = repositoryManager.openRepository(customDir, new URIish("git://some.org/repo.git"));
    try {
        repositoryManager.openRepository(customDir, new URIish("git://some.org/other-repo.git"));
        fail("Expect error, dir is used for another url");
    } catch (VcsException e) {
        assertTrue(true);
    }
    repositoryManager.closeRepository(r1);
    Repository r2 = repositoryManager.openRepository(customDir, new URIish("git://some.org/repo.git"));
    assertNotSame(r1, r2);
}
Also used : URIish(org.eclipse.jgit.transport.URIish) Repository(org.eclipse.jgit.lib.Repository) VcsException(jetbrains.buildServer.vcs.VcsException) File(java.io.File)

Example 39 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__custom_dir_case.

public void should_throw_exception_when_repository_configured_for_different_url__custom_dir_case() throws Exception {
    RepositoryManager repositoryManager = getRepositoryManager();
    File customDir = myTempFiles.createTempDir();
    repositoryManager.openRepository(customDir, new URIish("git://some.org/repo.git"));
    try {
        repositoryManager.openRepository(customDir, 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 40 with VcsException

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

the class ShowRefCommandImpl method call.

@NotNull
public ShowRefResult call() {
    GitCommandLine cmd = getCmd();
    cmd.addParameter("show-ref");
    if (myPattern != null)
        cmd.addParameters(myPattern);
    if (myShowTags)
        cmd.addParameter("--tags");
    try {
        ExecResult result = CommandUtil.runCommand(cmd);
        return new ShowRefResult(parseValidRefs(result.getStdout()), parseInvalidRefs(result.getStderr()), result.getExitCode());
    } catch (VcsException e) {
        getCmd().getContext().getLogger().warning("show-ref command failed, empty result will be returned: " + e.getMessage());
        return new ShowRefResult();
    }
}
Also used : ShowRefResult(jetbrains.buildServer.buildTriggers.vcs.git.agent.command.ShowRefResult) GitCommandLine(jetbrains.buildServer.buildTriggers.vcs.git.command.GitCommandLine) VcsException(jetbrains.buildServer.vcs.VcsException) ExecResult(jetbrains.buildServer.ExecResult) NotNull(org.jetbrains.annotations.NotNull)

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