Search in sources :

Example 76 with VcsException

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

the class GitRepoOperationsImpl method detectGitInternal.

@NotNull
private GitExec detectGitInternal() throws VcsException {
    final String gitPath = myConfig.getPathToGit();
    if (StringUtil.isEmpty(gitPath)) {
        throw new VcsException("No path to git provided: please specify path to git executable using \"teamcity.server.git.executable.path\" server startup property");
    }
    GitVersion gitVersion;
    try {
        gitVersion = IOGuard.allowCommandLine(() -> new GitFacadeImpl(new File("."), new StubContext(gitPath)).version().call());
    } catch (VcsException e) {
        throw new VcsException("Unable to run git at path \"" + gitPath + "\": please specify correct path to git executable using \"teamcity.server.git.executable.path\" server startup property, error: " + e.getMessage(), e);
    }
    if (gitVersion.isSupported()) {
        return new GitExec(gitPath, gitVersion, null);
    }
    throw new VcsException("TeamCity supports git version " + GitVersion.DEPRECATED + " or higher, detected git (path \"" + gitPath + "\") has version " + gitVersion + ".\n" + "Please install the latest git version");
}
Also used : VcsException(jetbrains.buildServer.vcs.VcsException) GitExec(jetbrains.buildServer.buildTriggers.vcs.git.command.GitExec) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull)

Example 77 with VcsException

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

the class GitRepoOperationsImpl method pushJGit.

@NotNull
private CommitResult pushJGit(@NotNull Repository db, @NotNull GitVcsRoot gitRoot, @NotNull String ref, @NotNull String commit, @NotNull String lastCommit) throws VcsException {
    ref = GitUtils.expandRef(ref);
    try (Transport tn = myTransportFactory.createTransport(db, gitRoot.getRepositoryPushURL().get(), gitRoot.getAuthSettings(), myConfig.getPushTimeoutSeconds())) {
        final ObjectId commitId = ObjectId.fromString(commit);
        final ObjectId lastCommitId = ObjectId.fromString(lastCommit);
        final RemoteRefUpdate ru = new RemoteRefUpdate(db, null, commitId, ref, false, null, lastCommitId);
        tn.push(NullProgressMonitor.INSTANCE, Collections.singletonList(ru));
        switch(ru.getStatus()) {
            case UP_TO_DATE:
            case OK:
                return CommitResult.createSuccessResult(commitId.name());
            default:
                {
                    StringBuilder error = new StringBuilder();
                    error.append("Push failed, status: ").append(ru.getStatus());
                    if (ru.getMessage() != null)
                        error.append(", message: ").append(ru.getMessage());
                    throw new VcsException(error.toString());
                }
        }
    } catch (VcsException e) {
        throw e;
    } catch (Exception e) {
        throw new VcsException("Error while pushing a commit, root " + gitRoot + ", revision " + commit + ", destination " + ref + ": " + e.getMessage(), e);
    }
}
Also used : RemoteRefUpdate(org.eclipse.jgit.transport.RemoteRefUpdate) ObjectId(org.eclipse.jgit.lib.ObjectId) VcsException(jetbrains.buildServer.vcs.VcsException) Transport(org.eclipse.jgit.transport.Transport) TransportException(org.eclipse.jgit.errors.TransportException) GitServerUtil.friendlyNotSupportedException(jetbrains.buildServer.buildTriggers.vcs.git.GitServerUtil.friendlyNotSupportedException) GitServerUtil.friendlyTransportException(jetbrains.buildServer.buildTriggers.vcs.git.GitServerUtil.friendlyTransportException) VcsException(jetbrains.buildServer.vcs.VcsException) NotSupportedException(org.eclipse.jgit.errors.NotSupportedException) NotNull(org.jetbrains.annotations.NotNull)

Example 78 with VcsException

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

the class BulkPatchBuilderImpl method buildPatches.

public void buildPatches(@NotNull final VcsRoot root, @NotNull final CheckoutRules rules, @NotNull final List<BulkPatchBuilderRequest> requests, @NotNull final BulkPatchBuilder patch) throws VcsException, IOException {
    final OperationContext ctx = myVcs.createContext(root, "bulk patch " + requests.size() + " commits");
    GitVcsRoot gitRoot = ctx.getGitRoot();
    myVcs.getRepositoryManager().runWithDisabledRemove(gitRoot.getRepositoryDir(), () -> {
        try {
            final Repository myRepo = ctx.getRepository();
            final ObjectReader contentsReader = myRepo.getObjectDatabase().newReader();
            final ObjectReader treesReader = myRepo.getObjectDatabase().newReader();
            for (BulkPatchBuilderRequest request : requests) {
                final PatchBuilder patchBuilder = patch.startPatch(request);
                final String prevBase = request.getFromVersion();
                final String toBase = request.getToVersion();
                try {
                    new GitPatchBuilder(ctx, patchBuilder, prevBase, toBase, rules, myConfig.verboseTreeWalkLog(), mySshMetaFactory) {

                        @NotNull
                        @Override
                        protected ObjectReader newObjectReaderForTree() {
                            return treesReader;
                        }

                        @NotNull
                        @Override
                        protected ContentLoaderFactory contentLoaderFactory() {
                            return new ContentLoaderFactory() {

                                @Nullable
                                public ObjectLoader open(@NotNull final Repository repo, @NotNull final ObjectId id) throws IOException {
                                    assert repo == myRepo;
                                    return contentsReader.open(id);
                                }
                            };
                        }
                    }.buildPatch();
                } catch (Throwable e) {
                    throw new VcsException("Failed to build patch " + prevBase + " -> " + toBase + ". " + e.getMessage(), e);
                } finally {
                    patch.endPatch(request, patchBuilder);
                }
            }
        } catch (Throwable e) {
            throw new VcsException("Failed to complete bulk patch." + e.getMessage(), e);
        } finally {
            ctx.close();
        }
    });
}
Also used : ObjectId(org.eclipse.jgit.lib.ObjectId) IOException(java.io.IOException) NotNull(org.jetbrains.annotations.NotNull) Repository(org.eclipse.jgit.lib.Repository) PatchBuilder(jetbrains.buildServer.vcs.patches.PatchBuilder) VcsException(jetbrains.buildServer.vcs.VcsException) ObjectReader(org.eclipse.jgit.lib.ObjectReader) ObjectLoader(org.eclipse.jgit.lib.ObjectLoader) Nullable(org.jetbrains.annotations.Nullable)

Example 79 with VcsException

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

the class GitPatchBuilder method addToCommitTree.

private void addToCommitTree() throws IOException, VcsException {
    RevCommit toCommit = myContext.findCommit(myRepository, myToRevision);
    if (toCommit == null)
        throw new VcsException("Cannot find commit " + myToRevision + " in repository " + myRepository.getDirectory().getAbsolutePath());
    myContext.addTree(myGitRoot, myTreeWalk, myRepository, toCommit, false, true, myRules);
}
Also used : VcsException(jetbrains.buildServer.vcs.VcsException) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

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