use of jetbrains.buildServer.vcs.VcsException in project teamcity-git by JetBrains.
the class GitNotFoundHealthPage method isAvailable.
@Override
public boolean isAvailable(@NotNull HttpServletRequest request) {
if (!super.isAvailable(request))
return false;
if (!SessionUser.getUser(request).isPermissionGrantedGlobally(Permission.CHANGE_SERVER_SETTINGS))
return false;
HealthStatusItem item = getStatusItem(request);
Object path = item.getAdditionalData().get(GitNotFoundHealthReport.PATH_KEY);
Object error = item.getAdditionalData().get(GitNotFoundHealthReport.ERROR_KEY);
return path instanceof String && error instanceof VcsException;
}
use of jetbrains.buildServer.vcs.VcsException in project teamcity-git by JetBrains.
the class GitLabelingSupport method tag.
@Override
@NotNull
public String tag(@NotNull OperationContext context, @NotNull String label, @NotNull String version) throws VcsException {
GitVcsRoot gitRoot = context.getGitRoot();
RevisionsInfo revisionsInfo = new RevisionsInfo();
if (myConfig.useTagPackHeuristics()) {
LOG.debug("Update repository before labeling " + gitRoot.debugInfo());
RepositoryStateData currentState = myVcs.getCurrentState(gitRoot);
if (!myConfig.analyzeTagsInPackHeuristics())
currentState = excludeTags(currentState);
try {
myVcs.getCollectChangesPolicy().ensureRepositoryStateLoadedFor(context, currentState, false);
} catch (Exception e) {
LOG.debug("Error while updating repository " + gitRoot.debugInfo(), e);
}
revisionsInfo = new RevisionsInfo(currentState);
}
try {
long start = System.currentTimeMillis();
Repository r = context.getRepository();
String commitSHA = GitUtils.versionRevision(version);
RevCommit commit = myCommitLoader.loadCommit(context, gitRoot, commitSHA);
Git git = new Git(r);
Ref tagRef = git.tag().setTagger(PersonIdentFactory.getTagger(gitRoot, r)).setName(label).setObjectId(commit).setForceUpdate(true).call();
if (tagRef.getObjectId() == null || resolve(r, tagRef) == null) {
LOG.warn("Tag's " + tagRef.getName() + " objectId " + (tagRef.getObjectId() != null ? tagRef.getObjectId().name() + " " : "") + "cannot be resolved");
} else if (LOG.isDebugEnabled()) {
LOG.debug("Tag created " + label + "=" + version + " for " + gitRoot.debugInfo() + " in " + (System.currentTimeMillis() - start) + "ms");
}
return push(label, version, gitRoot, r, tagRef, revisionsInfo);
} catch (Exception e) {
throw context.wrapException(e);
}
}
use of jetbrains.buildServer.vcs.VcsException in project teamcity-git by JetBrains.
the class LsRemoteCommandImpl method parse.
private List<Ref> parse(@NotNull final String str) throws VcsException {
final Map<String, Ref> refs = new HashMap<>();
for (String line : splitByLines(str)) {
final String objectId = line.substring(0, 40);
String name = line.substring(40).trim();
if (myPeelRefs && name.endsWith("^{}")) {
name = name.substring(0, name.length() - 3);
final Ref prior = refs.get(name);
if (prior == null)
throw new VcsException(String.format("Advertisement of %s^'{}' came before %s", name, name));
}
refs.put(name, new RefImpl(name, objectId));
}
return new ArrayList<>(refs.values());
}
use of jetbrains.buildServer.vcs.VcsException in project teamcity-git by JetBrains.
the class Cleanup method isNativeGitInstalled.
private boolean isNativeGitInstalled() {
String pathToGit = myConfig.getPathToGit();
GeneralCommandLine cmd = new GeneralCommandLine();
cmd.setWorkingDirectory(myRepositoryManager.getBaseMirrorsDir());
cmd.setExePath(pathToGit);
cmd.addParameter("version");
ExecResult result = SimpleCommandLineProcessRunner.runCommand(cmd, null);
VcsException commandError = CommandLineUtil.getCommandLineError("git version", result);
if (commandError != null) {
myNativeGitError.set(new RunGitError(pathToGit, commandError));
CLEANUP.warnAndDebugDetails("Failed to run git", commandError);
return false;
} else {
myNativeGitError.set(null);
}
return true;
}
use of jetbrains.buildServer.vcs.VcsException in project teamcity-git by JetBrains.
the class GitCommandLine method configureGitSshCommand.
private void configureGitSshCommand(@NotNull GitCommandSettings settings) throws VcsException {
final AuthSettings authSettings = settings.getAuthSettings();
if (authSettings == null)
return;
// Git has 2 environment variables related to ssh: GIT_SSH and GIT_SSH_COMMAND.
// We use GIT_SSH_COMMAND because git resolves the executable specified in it,
// i.e. it finds the 'ssh' executable which is not in the PATH on windows by default.
// We specify the following command:
//
// GIT_SSH_COMMAND=ssh -i "<path to decrypted key>" (-o "StrictHostKeyChecking=no" -vvv)
//
// The key is decrypted by us because on MacOS ssh seems to ignore the SSH_ASKPASS and
// runs the MacOS graphical keychain helper. Disabling it via the -o "KeychainIntegration=no"
// option results in the 'Bad configuration option: keychainintegration' error.
final boolean ignoreKnownHosts = isIgnoreKnownHosts(authSettings);
final String sendEnv = getSshRequestToken();
File privateKey = null;
try {
privateKey = getPrivateKey(authSettings);
if (privateKey != null || ignoreKnownHosts || StringUtil.isNotEmpty(sendEnv)) {
final StringBuilder gitSshCommand = new StringBuilder("ssh");
if (privateKey != null) {
gitSshCommand.append(" -i \"").append(privateKey.getAbsolutePath().replace('\\', '/')).append("\"");
}
if (ignoreKnownHosts) {
gitSshCommand.append(" -o \"StrictHostKeyChecking=no\" -o \"UserKnownHostsFile=/dev/null\" -o \"GlobalKnownHostsFile=/dev/null\"");
} else {
myLogger.warning("\"Ignore known hosts database\" setting is disabled, please make sure that per-user or global known host key database contains remote host key, otherwise git operations may hang or fail in unexpected way");
}
if (authSettings.getAuthMethod().isKeyAuth()) {
gitSshCommand.append(" -o \"PreferredAuthentications=publickey\" -o \"PasswordAuthentication=no\" -o \"KbdInteractiveAuthentication=no\"");
} else {
gitSshCommand.append(" -o \"PreferredAuthentications=password,keyboard-interactive\" -o \"PubkeyAuthentication=no\"");
}
gitSshCommand.append(" -o \"IdentitiesOnly=yes\"");
if (StringUtil.isNotEmpty(sendEnv)) {
gitSshCommand.append(" -o \"SetEnv TEAMCITY_SSH_REQUEST_TOKEN").append("=").append(sendEnv).append("\"");
}
final String sshCommandOptions = myCtx.getSshCommandOptions();
if (StringUtil.isNotEmpty(sshCommandOptions)) {
gitSshCommand.append(" ").append(sshCommandOptions);
}
if (myCtx.isDebugSsh() || settings.isTrace()) {
gitSshCommand.append(" -vvv");
}
addEnvParam("GIT_SSH_COMMAND", gitSshCommand.toString());
}
} catch (Exception e) {
if (privateKey != null)
FileUtil.delete(privateKey);
if (e instanceof VcsException)
throw (VcsException) e;
throw new VcsException(e);
}
}
Aggregations