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