use of jetbrains.buildServer.buildTriggers.vcs.git.command.impl.GitFacadeImpl 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.buildTriggers.vcs.git.command.impl.GitFacadeImpl 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.buildTriggers.vcs.git.command.impl.GitFacadeImpl 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.buildTriggers.vcs.git.command.impl.GitFacadeImpl in project teamcity-git by JetBrains.
the class NativeGitCommands method lsRemote.
@NotNull
@Override
public Map<String, Ref> lsRemote(@NotNull Repository db, @NotNull GitVcsRoot gitRoot, @NotNull FetchSettings settings) throws VcsException {
final Context ctx = new ContextImpl(gitRoot, myConfig, myGitDetector.detectGit(), settings.getProgress());
final GitFacadeImpl gitFacade = new GitFacadeImpl(db.getDirectory(), ctx);
gitFacade.setSshKeyManager(mySshKeyManager);
final jetbrains.buildServer.buildTriggers.vcs.git.command.LsRemoteCommand lsRemote = gitFacade.lsRemote().peelRefs().setAuthSettings(gitRoot.getAuthSettings()).setUseNativeSsh(true).setTimeout(myConfig.getRepositoryStateTimeoutSeconds()).setRetryAttempts(myConfig.getConnectionRetryAttempts()).trace(myConfig.getGitTraceEnv());
return executeCommand(ctx, "ls-remote", LogUtil.describe(gitRoot), () -> {
return lsRemote.call().stream().collect(Collectors.toMap(Ref::getName, ref -> ref));
});
}
Aggregations