Search in sources :

Example 6 with VcsException

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

the class FetchCommandImpl method getFetchProcessInputBytes.

private byte[] getFetchProcessInputBytes(@NotNull AuthSettings authSettings, @NotNull File repositoryDir, @NotNull URIish uri, @NotNull Collection<RefSpec> specs, @NotNull File threadDump, @NotNull File gcDump, @NotNull File gitProperties) throws VcsException {
    try {
        Map<String, String> properties = new HashMap<String, String>(authSettings.toMap());
        properties.put(Constants.REPOSITORY_DIR_PROPERTY_NAME, repositoryDir.getCanonicalPath());
        properties.put(Constants.FETCH_URL, uri.toString());
        properties.put(Constants.REFSPEC, serializeSpecs(specs));
        properties.put(Constants.VCS_DEBUG_ENABLED, String.valueOf(Loggers.VCS.isDebugEnabled()));
        properties.put(Constants.THREAD_DUMP_FILE, threadDump.getAbsolutePath());
        properties.put(Constants.GC_DUMP_FILE, gcDump.getAbsolutePath());
        properties.put(Constants.FETCHER_INTERNAL_PROPERTIES_FILE, gitProperties.getAbsolutePath());
        final File trustedCertificatesDir = myGitTrustStoreProvider.getTrustedCertificatesDir();
        if (trustedCertificatesDir != null) {
            properties.put(Constants.GIT_TRUST_STORE_PROVIDER, trustedCertificatesDir.getAbsolutePath());
        }
        return VcsUtil.propertiesToStringSecure(properties).getBytes(StandardCharsets.UTF_8);
    } catch (IOException e) {
        throw new VcsException("Error while generating fetch process input: " + e.getMessage(), e);
    }
}
Also used : VcsException(jetbrains.buildServer.vcs.VcsException) IOException(java.io.IOException) File(java.io.File)

Example 7 with VcsException

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

the class Cleanup method runJGitGC.

private void runJGitGC(final File bareGitDir) throws IOException, VcsException {
    GeneralCommandLine cmd = new GeneralCommandLine();
    cmd.setWorkingDirectory(bareGitDir);
    cmd.setExePath(myConfig.getFetchProcessJavaPath());
    cmd.addParameters("-Xmx" + myConfig.getGcProcessMaxMemory(), "-cp", myConfig.getFetchClasspath(), GitGcProcess.class.getName(), bareGitDir.getCanonicalPath());
    ExecResult result = SimpleCommandLineProcessRunner.runCommand(cmd, null, new SimpleCommandLineProcessRunner.RunCommandEventsAdapter() {

        @Nullable
        @Override
        public Integer getOutputIdleSecondsTimeout() {
            return 60 * myConfig.getNativeGCQuotaMinutes();
        }
    });
    VcsException commandError = CommandLineUtil.getCommandLineError("git gc", result, false, true);
    if (commandError != null)
        throw commandError;
}
Also used : SimpleCommandLineProcessRunner(jetbrains.buildServer.SimpleCommandLineProcessRunner) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) VcsException(jetbrains.buildServer.vcs.VcsException) Nullable(org.jetbrains.annotations.Nullable) ExecResult(jetbrains.buildServer.ExecResult)

Example 8 with VcsException

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

the class GitLabelingSupport method push.

@NotNull
private String push(@NotNull String label, @NotNull String version, @NotNull GitVcsRoot gitRoot, @NotNull Repository r, @NotNull Ref tagRef, @NotNull RevisionsInfo revisionsInfo) throws VcsException, IOException {
    long pushStart = System.currentTimeMillis();
    final Transport tn = myTransportFactory.createTransport(r, gitRoot.getRepositoryPushURL().get(), gitRoot.getAuthSettings(), myConfig.getPushTimeoutSeconds());
    PushConnection c = null;
    try {
        c = tn.openPush();
        RemoteRefUpdate ru = new RemoteRefUpdate(r, tagRef.getName(), tagRef.getObjectId(), tagRef.getName(), false, null, null);
        PreparePackFunction preparePack = null;
        if (c instanceof BasePackPushConnection) {
            final RevTag tagObject = getTagObject(r, tagRef);
            if (tagObject != null) {
                preparePack = new PreparePackFunction(tagObject, revisionsInfo);
                ((BasePackPushConnection) c).setPreparePack(preparePack);
            } else {
                LOG.debug("Cannot locate the " + tagRef.getName() + " tag object, don't use pack heuristic");
            }
        }
        c.push(NullProgressMonitor.INSTANCE, Collections.singletonMap(tagRef.getName(), ru));
        LOG.info("Tag  " + label + "=" + version + " was pushed with status " + ru.getStatus() + " for " + gitRoot.debugInfo() + " in " + (System.currentTimeMillis() - pushStart) + "ms" + (preparePack != null ? " (prepare pack " + preparePack.getPreparePackDurationMillis() + "ms)" : ""));
        switch(ru.getStatus()) {
            case UP_TO_DATE:
            case OK:
                break;
            default:
                String msg = ru.getMessage();
                throw new VcsException("The remote '" + label + "' tag was not created" + ", status: " + ru.getStatus() + (!isEmpty(msg) ? ", message: " + msg : ""));
        }
        return label;
    } finally {
        if (c != null)
            c.close();
        tn.close();
    }
}
Also used : RevTag(org.eclipse.jgit.revwalk.RevTag) VcsException(jetbrains.buildServer.vcs.VcsException) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with VcsException

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

the class CommitLoaderImpl method findLocallyMissingRevisions.

@NotNull
private Collection<RefCommit> findLocallyMissingRevisions(@NotNull OperationContext context, @NotNull Repository db, @NotNull Collection<RefCommit> revisions, boolean throwErrors) throws VcsException {
    final Set<RefCommit> locallyMissing = new HashSet<>();
    try (RevWalk walk = new RevWalk(db)) {
        for (RefCommit r : revisions) {
            final String ref = GitUtils.expandRef(r.getRef());
            final String rev = r.getCommit();
            final String revNumber = GitUtils.versionRevision(rev);
            try {
                walk.parseCommit(ObjectId.fromString(revNumber));
            } catch (IncorrectObjectTypeException e) {
                LOG.warn("Ref " + ref + " points to a non-commit " + revNumber + " for " + context.getGitRoot().debugInfo());
            } catch (MissingObjectException e) {
                locallyMissing.add(r);
            } catch (Exception e) {
                LOG.warnAndDebugDetails("Unexpected exception while trying to parse commit " + revNumber, e);
                locallyMissing.add(r);
            }
        }
        if (locallyMissing.isEmpty()) {
            return locallyMissing;
        }
        LOG.debug("Revisions missing in the local repository: " + locallyMissing.stream().map(e -> e.getRef() + ": " + e.getCommit()).collect(Collectors.joining(", ")) + " for " + context.getGitRoot().debugInfo());
        if (throwErrors) {
            final Set<String> missingTips = locallyMissing.stream().filter(RefCommit::isRefTip).map(e -> e.getRef() + ": " + e.getCommit()).collect(Collectors.toSet());
            if (missingTips.size() > 0) {
                final VcsException error = new VcsException("Revisions missing in the local repository: " + StringUtil.join(missingTips, ", "));
                error.setRecoverable(context.getPluginConfig().treatMissingBranchTipAsRecoverableError());
                throw error;
            }
        }
        return locallyMissing;
    }
}
Also used : java.util(java.util) RevCommit(org.eclipse.jgit.revwalk.RevCommit) ReentrantLock(java.util.concurrent.locks.ReentrantLock) IncorrectObjectTypeException(org.eclipse.jgit.errors.IncorrectObjectTypeException) RefSpec(org.eclipse.jgit.transport.RefSpec) MissingObjectException(org.eclipse.jgit.errors.MissingObjectException) IOException(java.io.IOException) VcsOperationRejectedException(jetbrains.buildServer.vcs.VcsOperationRejectedException) Collectors(java.util.stream.Collectors) File(java.io.File) ObjectId(org.eclipse.jgit.lib.ObjectId) TimeUnit(java.util.concurrent.TimeUnit) RevWalk(org.eclipse.jgit.revwalk.RevWalk) Nullable(org.jetbrains.annotations.Nullable) RevisionNotFoundException(jetbrains.buildServer.vcs.RevisionNotFoundException) Arrays.asList(java.util.Arrays.asList) Ref(org.eclipse.jgit.lib.Ref) URIish(org.eclipse.jgit.transport.URIish) VcsException(jetbrains.buildServer.vcs.VcsException) StringUtil(jetbrains.buildServer.util.StringUtil) Logger(com.intellij.openapi.diagnostic.Logger) NotNull(org.jetbrains.annotations.NotNull) Repository(org.eclipse.jgit.lib.Repository) VcsException(jetbrains.buildServer.vcs.VcsException) IncorrectObjectTypeException(org.eclipse.jgit.errors.IncorrectObjectTypeException) RevWalk(org.eclipse.jgit.revwalk.RevWalk) MissingObjectException(org.eclipse.jgit.errors.MissingObjectException) IncorrectObjectTypeException(org.eclipse.jgit.errors.IncorrectObjectTypeException) MissingObjectException(org.eclipse.jgit.errors.MissingObjectException) IOException(java.io.IOException) VcsOperationRejectedException(jetbrains.buildServer.vcs.VcsOperationRejectedException) RevisionNotFoundException(jetbrains.buildServer.vcs.RevisionNotFoundException) VcsException(jetbrains.buildServer.vcs.VcsException) NotNull(org.jetbrains.annotations.NotNull)

Example 10 with VcsException

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

the class SubmoduleResolverImpl method getSubmoduleCommit.

/**
 * Resolve the commit for submodule
 *
 * @param parentRepositoryUrl url of the parent repository
 * @param path   the within repository path
 * @param commit the commit identifier
 * @return the the resoled commit in other repository
 * @throws VcsAuthenticationException if there are authentication problems
 * @throws URISyntaxException if there are errors in submodule repository URI
 */
@NotNull
public RevCommit getSubmoduleCommit(@NotNull String parentRepositoryUrl, @NotNull String path, @NotNull ObjectId commit) throws CorruptObjectException, VcsException, URISyntaxException {
    ensureConfigLoaded();
    if (myConfig == null)
        throw new MissingSubmoduleConfigException(parentRepositoryUrl, myCommit.name(), path);
    final Submodule submodule = myConfig.findSubmodule(path);
    if (submodule == null)
        throw new MissingSubmoduleEntryException(parentRepositoryUrl, myCommit.name(), path);
    URIish submoduleUri = resolveSubmoduleUrl(submodule.getUrl());
    File repositoryDir = myContext.getRepositoryDir(submoduleUri);
    try {
        return myContext.getRepositoryManager().runWithDisabledRemove(repositoryDir, () -> {
            try {
                Repository r = resolveRepository(submodule.getUrl());
                String submoduleUrl = myContext.getConfig(r).getString("teamcity", null, "remote");
                if (!isCommitExist(r, commit)) {
                    try {
                        fetch(r, path, submodule.getUrl());
                    } catch (Exception e) {
                        throw new SubmoduleFetchException(parentRepositoryUrl, path, submoduleUrl, myCommit, e);
                    }
                }
                try {
                    return myCommitLoader.getCommit(r, commit);
                } catch (Exception e) {
                    throw new MissingSubmoduleCommitException(parentRepositoryUrl, myCommit.name(), path, submodule.getUrl(), commit.name());
                }
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        });
    } catch (RuntimeException e) {
        Throwable cause = e.getCause();
        if (cause instanceof CorruptObjectException) {
            throw (CorruptObjectException) cause;
        }
        if (cause instanceof VcsException) {
            throw (VcsException) cause;
        }
        if (cause instanceof URISyntaxException) {
            throw (URISyntaxException) cause;
        }
        throw new VcsException(e);
    }
}
Also used : URIish(org.eclipse.jgit.transport.URIish) CorruptObjectException(org.eclipse.jgit.errors.CorruptObjectException) URISyntaxException(java.net.URISyntaxException) CorruptObjectException(org.eclipse.jgit.errors.CorruptObjectException) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) VcsException(jetbrains.buildServer.vcs.VcsException) Repository(org.eclipse.jgit.lib.Repository) VcsException(jetbrains.buildServer.vcs.VcsException) File(java.io.File) 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