use of jetbrains.buildServer.vcs.VcsException in project teamcity-git by JetBrains.
the class GitPatchBuilderDispatcher method buildPatchInSeparateProcess.
private void buildPatchInSeparateProcess() throws Exception {
final String rootStr = LogUtil.describe(myGitRoot);
final ProcessXmxProvider xmxProvider = new ProcessXmxProvider(new RepositoryXmxStorage(myContext.getRepository(), "patch"), myConfig, "patch", "(root: " + rootStr + ")");
Integer xmx = xmxProvider.getNextXmx();
while (xmx != null) {
final GeneralCommandLine patchCmd = createPatchCommandLine(xmx);
final File patchFile = FileUtil.createTempFile("git", "patch");
final File internalProperties = getPatchPropertiesFile();
try {
final ByteArrayOutputStream stdout = new LineAwareByteArrayOutputStream(Charset.forName("UTF-8"), new NoOpLineListener(), false);
final ByteArrayOutputStream stderr = new ByteArrayOutputStream();
final GitProcessExecutor.GitExecResult gitResult = new GitProcessExecutor(patchCmd).runProcess(getInput(patchFile, internalProperties), myConfig.getPatchProcessIdleTimeoutSeconds(), stdout, stderr, new GitProcessExecutor.ProcessExecutorAdapter());
VcsException patchError = CommandLineUtil.getCommandLineError("build patch", gitResult.getExecResult());
if (patchError != null) {
if (gitResult.isOutOfMemoryError()) {
final Integer nextXmx = xmxProvider.getNextXmx();
if (nextXmx != null) {
xmx = nextXmx;
FileUtil.delete(patchFile);
continue;
}
throw new VcsException("There is not enough memory for git patch (last attempted -Xmx" + xmx + "M). Please contact your system administrator", patchError);
} else if (gitResult.isTimeout()) {
throw new VcsException("git patch for root " + rootStr + " was idle for more than " + myConfig.getFetchTimeout() + " second(s), try increasing the timeout using the " + PluginConfigImpl.TEAMCITY_GIT_IDLE_TIMEOUT_SECONDS + " property", patchError);
}
throw patchError;
}
new LowLevelPatcher(new FileInputStream(patchFile)).applyPatch(new NoExitLowLevelPatchTranslator(((PatchBuilderEx) myBuilder).getLowLevelBuilder()));
break;
} finally {
FileUtil.delete(patchFile);
FileUtil.delete(internalProperties);
}
}
}
use of jetbrains.buildServer.vcs.VcsException in project teamcity-git by JetBrains.
the class NativeGitCommands method push.
@NotNull
@Override
public CommitResult push(@NotNull Repository db, @NotNull GitVcsRoot gitRoot, @NotNull String ref, @NotNull String commit, @NotNull String lastCommit) throws VcsException {
final String fullRef = GitUtils.expandRef(ref);
final Context ctx = new ContextImpl(gitRoot, myConfig, myGitDetector.detectGit());
final GitFacadeImpl gitFacade = new GitFacadeImpl(db.getDirectory(), ctx);
gitFacade.setSshKeyManager(mySshKeyManager);
gitFacade.updateRef().setRef(fullRef).setRevision(commit).setOldValue(lastCommit).call();
final String debugInfo = LogUtil.describe(gitRoot);
try {
return executeCommand(ctx, "push", debugInfo, () -> {
gitFacade.push().setRemote(gitRoot.getRepositoryPushURL().toString()).setRefspec(fullRef).setAuthSettings(gitRoot.getAuthSettings()).setUseNativeSsh(true).setTimeout(myConfig.getPushTimeoutSeconds()).trace(myConfig.getGitTraceEnv()).call();
return CommitResult.createSuccessResult(commit);
});
} catch (VcsException e) {
// restore local ref
try {
gitFacade.updateRef().setRef(fullRef).setRevision(lastCommit).setOldValue(commit).call();
} catch (VcsException v) {
Loggers.VCS.warn("Failed to restore initial revision " + lastCommit + " of " + fullRef + " after unssuccessful push of revision " + commit + " for " + debugInfo, v);
}
throw e;
}
}
use of jetbrains.buildServer.vcs.VcsException in project teamcity-git by JetBrains.
the class NativeGitCommands method fetch.
@Override
public void fetch(@NotNull Repository db, @NotNull URIish fetchURI, @NotNull FetchSettings settings) throws IOException, VcsException {
final GitExec gitExec = myGitDetector.detectGit();
final Context ctx = new ContextImpl(null, myConfig, gitExec, settings.getProgress());
final GitFacadeImpl gitFacade = new GitFacadeImpl(db.getDirectory(), ctx);
gitFacade.setSshKeyManager(mySshKeyManager);
// otherwise git fails to update local branches which were e.g. renamed.
try {
gitFacade.remote().setCommand("prune").setRemote("origin").setAuthSettings(settings.getAuthSettings()).setUseNativeSsh(true).trace(myConfig.getGitTraceEnv()).call();
} catch (VcsException e) {
Loggers.VCS.warnAndDebugDetails("Error while pruning removed branches in " + db, e);
}
final jetbrains.buildServer.buildTriggers.vcs.git.command.FetchCommand fetch = gitFacade.fetch().setRemote(fetchURI.toString()).setFetchTags(false).setAuthSettings(settings.getAuthSettings()).setUseNativeSsh(true).setTimeout(myConfig.getFetchTimeout()).setRetryAttempts(myConfig.getConnectionRetryAttempts()).trace(myConfig.getGitTraceEnv()).addPreAction(() -> GitServerUtil.removeRefLocks(db.getDirectory()));
final Collection<String> resultRefSpecs = new HashSet<>();
switch(settings.getFetchMode()) {
case FETCH_ALL_REFS:
fetch.setRefspec(ALL_REF_SPEC);
resultRefSpecs.add(ALL_REF_SPEC);
break;
case FETCH_ALL_REFS_EXCEPT_TAGS:
fetch.setRefspec(ALL_REF_SPEC);
resultRefSpecs.add(ALL_REF_SPEC);
fetch.setRefspec(EXCLUDE_TAGS_REF_SPEC);
resultRefSpecs.add(EXCLUDE_TAGS_REF_SPEC);
break;
case FETCH_REF_SPECS:
default:
for (RefSpec refSpec : settings.getRefSpecs()) {
final String refSpecStr = refSpec.toString();
fetch.setRefspec(refSpecStr);
resultRefSpecs.add(refSpecStr);
}
break;
}
if (isSilentFetch(ctx))
fetch.setQuite(true);
else
fetch.setShowProgress(true);
executeCommand(ctx, "fetch", getDebugInfo(db, fetchURI, resultRefSpecs), () -> {
fetch.call();
return true;
});
}
use of jetbrains.buildServer.vcs.VcsException in project teamcity-git by JetBrains.
the class NativeGitCommands method tag.
@Override
@NotNull
public String tag(@NotNull OperationContext context, @NotNull String tag, @NotNull String commit) throws VcsException {
final Context ctx = new ContextImpl(context.getGitRoot(), myConfig, myGitDetector.detectGit());
final Repository db = context.getRepository();
final GitFacadeImpl gitFacade = new GitFacadeImpl(db.getDirectory(), ctx);
gitFacade.setSshKeyManager(mySshKeyManager);
final GitVcsRoot gitRoot = context.getGitRoot();
final PersonIdent tagger = PersonIdentFactory.getTagger(gitRoot, db);
gitFacade.tag().setName(tag).setCommit(commit).force(true).annotate(true).setTagger(tagger.getName(), tagger.getEmailAddress()).setMessage("automatically created by TeamCity VCS labeling build feature").call();
final String debugInfo = LogUtil.describe(gitRoot);
try {
return executeCommand(ctx, "push", debugInfo, () -> {
gitFacade.push().setRemote(gitRoot.getRepositoryPushURL().toString()).setRefspec(tag).setAuthSettings(gitRoot.getAuthSettings()).setUseNativeSsh(true).setTimeout(myConfig.getPushTimeoutSeconds()).trace(myConfig.getGitTraceEnv()).call();
Loggers.VCS.info("Tag '" + tag + "' was successfully pushed for " + debugInfo);
return tag;
});
} catch (VcsException e) {
// remove local tag
try {
gitFacade.tag().delete(true).setName(tag).call();
} catch (VcsException v) {
Loggers.VCS.warn("Failed to delete local tag " + tag + " of " + commit + " after unssuccessful push for " + debugInfo, v);
}
throw e;
}
}
use of jetbrains.buildServer.vcs.VcsException in project teamcity-git by JetBrains.
the class TransportFactoryImpl method createTransport.
public Transport createTransport(@NotNull final Repository r, @NotNull final URIish url, @NotNull final AuthSettings authSettings, final int timeoutSeconds) throws NotSupportedException, VcsException {
try {
checkUrl(url);
URIish preparedURI = prepareURI(url);
final Transport t = Transport.open(r, preparedURI);
t.setCredentialsProvider(new AuthCredentialsProvider(authSettings));
if (t instanceof SshTransport) {
SshTransport ssh = (SshTransport) t;
ssh.setSshSessionFactory(getSshSessionFactory(url, authSettings));
}
t.setTimeout(timeoutSeconds);
return t;
} catch (TransportException e) {
throw new VcsException("Cannot create transport: " + e.getMessage(), e);
}
}
Aggregations