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");
}
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);
}
}
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();
}
});
}
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);
}
Aggregations