Search in sources :

Example 46 with VcsException

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

the class NativeGitCommands method lsRemote.

@NotNull
@Override
public Map<String, Ref> lsRemote(@NotNull Repository db, @NotNull GitVcsRoot gitRoot, @NotNull FetchSettings settings) throws VcsException {
    final Context ctx = new ContextImpl(gitRoot, myConfig, myGitDetector.detectGit(), settings.getProgress());
    final GitFacadeImpl gitFacade = new GitFacadeImpl(db.getDirectory(), ctx);
    gitFacade.setSshKeyManager(mySshKeyManager);
    final jetbrains.buildServer.buildTriggers.vcs.git.command.LsRemoteCommand lsRemote = gitFacade.lsRemote().peelRefs().setAuthSettings(gitRoot.getAuthSettings()).setUseNativeSsh(true).setTimeout(myConfig.getRepositoryStateTimeoutSeconds()).setRetryAttempts(myConfig.getConnectionRetryAttempts()).trace(myConfig.getGitTraceEnv());
    return executeCommand(ctx, "ls-remote", LogUtil.describe(gitRoot), () -> {
        return lsRemote.call().stream().collect(Collectors.toMap(Ref::getName, ref -> ref));
    });
}
Also used : CommitResult(jetbrains.buildServer.vcs.CommitResult) jetbrains.buildServer.buildTriggers.vcs.git(jetbrains.buildServer.buildTriggers.vcs.git) Loggers(jetbrains.buildServer.log.Loggers) RefSpec(org.eclipse.jgit.transport.RefSpec) Collection(java.util.Collection) TagCommand(jetbrains.buildServer.buildTriggers.vcs.git.TagCommand) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) HashSet(java.util.HashSet) LsRemoteCommand(jetbrains.buildServer.buildTriggers.vcs.git.LsRemoteCommand) GitFacadeImpl(jetbrains.buildServer.buildTriggers.vcs.git.command.impl.GitFacadeImpl) PersonIdent(org.eclipse.jgit.lib.PersonIdent) FetchCommand(jetbrains.buildServer.buildTriggers.vcs.git.FetchCommand) NamedThreadFactory(jetbrains.buildServer.util.NamedThreadFactory) Map(java.util.Map) Ref(org.eclipse.jgit.lib.Ref) URIish(org.eclipse.jgit.transport.URIish) VcsException(jetbrains.buildServer.vcs.VcsException) VcsRootSshKeyManager(jetbrains.buildServer.ssh.VcsRootSshKeyManager) Logger(com.intellij.openapi.diagnostic.Logger) PushCommand(jetbrains.buildServer.buildTriggers.vcs.git.PushCommand) NotNull(org.jetbrains.annotations.NotNull) FuncThrow(jetbrains.buildServer.util.FuncThrow) Repository(org.eclipse.jgit.lib.Repository) GitFacadeImpl(jetbrains.buildServer.buildTriggers.vcs.git.command.impl.GitFacadeImpl) NotNull(org.jetbrains.annotations.NotNull)

Example 47 with VcsException

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

the class CommitLoaderImpl method getRefSpecForCurrentState.

@NotNull
private Collection<RefSpec> getRefSpecForCurrentState(@NotNull OperationContext context, @NotNull Collection<RefCommit> revisions, @NotNull Collection<String> remoteRefs) throws VcsException {
    final Set<RefSpec> result = new HashSet<>();
    final Set<String> missingTips = new HashSet<>();
    for (RefCommit r : revisions) {
        final String ref = r.getRef();
        final boolean existsRemotely = remoteRefs.contains(ref);
        if (existsRemotely) {
            result.add(new RefSpec(ref + ":" + ref).setForceUpdate(true));
            continue;
        }
        if (r.isRefTip()) {
            missingTips.add(ref);
        } else {
            LOG.debug(String.format(REF_MISSING_FORMAT, ref) + " for " + context.getGitRoot().debugInfo());
        }
    }
    final int remotelyMissingRefsNum = missingTips.size();
    if (remotelyMissingRefsNum > 0) {
        final String message = remotelyMissingRefsNum == 1 ? String.format(REF_MISSING_FORMAT, missingTips.iterator().next()) : String.format(REFS_MISSING_FORMAT, StringUtil.join(", ", missingTips));
        final VcsException exception = new VcsException(message);
        exception.setRecoverable(context.getPluginConfig().treatMissingBranchTipAsRecoverableError());
        throw exception;
    }
    return result;
}
Also used : RefSpec(org.eclipse.jgit.transport.RefSpec) VcsException(jetbrains.buildServer.vcs.VcsException) NotNull(org.jetbrains.annotations.NotNull)

Example 48 with VcsException

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

the class FetcherProperties method getPropertiesFile.

@NotNull
public File getPropertiesFile() throws VcsException {
    try {
        File props = FileUtil.createTempFile("git", "props");
        GitServerUtil.writeAsProperties(props, myConfig.getFetcherProperties());
        return props;
    } catch (IOException e) {
        throw new VcsException("Cannot create properties file for git fetch process: " + e.getMessage(), e);
    }
}
Also used : VcsException(jetbrains.buildServer.vcs.VcsException) IOException(java.io.IOException) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull)

Example 49 with VcsException

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

the class TestConnectionTest method should_failed_when_branch_not_found.

public void should_failed_when_branch_not_found() throws Exception {
    try {
        VcsRoot root = vcsRoot().withFetchUrl(getRemoteRepositoryUrl("repo.git")).withBranch("no-such-branch").build();
        myGit.testConnection(root);
        fail("Test connection should fail for unknown branch");
    } catch (VcsException ex) {
        assertTrue(true);
    }
}
Also used : VcsException(jetbrains.buildServer.vcs.VcsException) VcsRoot(jetbrains.buildServer.vcs.VcsRoot)

Example 50 with VcsException

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

the class TestConnectionTest method test_not_existing_local_repository.

@TestFor(issues = "TW-9933")
public void test_not_existing_local_repository() throws Exception {
    File notExisting = new File(myTempFiles.createTempDir(), "not-existing");
    String url = GitUtils.toURL(notExisting);
    VcsRootImpl root = vcsRoot().withFetchUrl(url).build();
    try {
        myGit.testConnection(root);
        fail("Should throw an exception for not-existing repository");
    } catch (VcsException e) {
        TeamCityAsserts.assertContainsAny(e.getMessage(), "Cannot access the '" + url + "' repository", "Please make sure you have the correct access rights and the repository exists");
        assertFalse(e.getMessage().endsWith("\n"));
    }
}
Also used : VcsRootImpl(jetbrains.buildServer.vcs.impl.VcsRootImpl) VcsException(jetbrains.buildServer.vcs.VcsException) File(java.io.File) TestFor(jetbrains.buildServer.util.TestFor)

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