Search in sources :

Example 61 with VcsException

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;
}
Also used : HealthStatusItem(jetbrains.buildServer.serverSide.healthStatus.HealthStatusItem) VcsException(jetbrains.buildServer.vcs.VcsException)

Example 62 with 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);
    }
}
Also used : Git(org.eclipse.jgit.api.Git) RepositoryStateData(jetbrains.buildServer.vcs.RepositoryStateData) IOException(java.io.IOException) VcsException(jetbrains.buildServer.vcs.VcsException) RevCommit(org.eclipse.jgit.revwalk.RevCommit) NotNull(org.jetbrains.annotations.NotNull)

Example 63 with VcsException

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());
}
Also used : Ref(org.eclipse.jgit.lib.Ref) VcsException(jetbrains.buildServer.vcs.VcsException)

Example 64 with VcsException

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;
}
Also used : GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) VcsException(jetbrains.buildServer.vcs.VcsException) ExecResult(jetbrains.buildServer.ExecResult)

Example 65 with VcsException

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);
    }
}
Also used : VcsException(jetbrains.buildServer.vcs.VcsException) CheckoutCanceledException(jetbrains.buildServer.buildTriggers.vcs.git.command.errors.CheckoutCanceledException) VcsException(jetbrains.buildServer.vcs.VcsException)

Aggregations

VcsException (jetbrains.buildServer.vcs.VcsException)79 File (java.io.File)34 NotNull (org.jetbrains.annotations.NotNull)22 GitTestUtil.dataFile (jetbrains.buildServer.buildTriggers.vcs.git.tests.GitTestUtil.dataFile)13 IOException (java.io.IOException)12 TestFor (jetbrains.buildServer.util.TestFor)11 GeneralCommandLine (com.intellij.execution.configurations.GeneralCommandLine)10 Method (java.lang.reflect.Method)10 ExecResult (jetbrains.buildServer.ExecResult)10 VcsRootImpl (jetbrains.buildServer.vcs.impl.VcsRootImpl)10 AfterMethod (org.testng.annotations.AfterMethod)10 BeforeMethod (org.testng.annotations.BeforeMethod)10 VcsRoot (jetbrains.buildServer.vcs.VcsRoot)9 Repository (org.eclipse.jgit.lib.Repository)9 URIish (org.eclipse.jgit.transport.URIish)9 Nullable (org.jetbrains.annotations.Nullable)8 SimpleCommandLineProcessRunner (jetbrains.buildServer.SimpleCommandLineProcessRunner)5 GitExec (jetbrains.buildServer.buildTriggers.vcs.git.command.GitExec)5 CheckoutRules (jetbrains.buildServer.vcs.CheckoutRules)5 RefSpec (org.eclipse.jgit.transport.RefSpec)5