Search in sources :

Example 1 with GitExec

use of jetbrains.buildServer.buildTriggers.vcs.git.command.GitExec in project teamcity-git by JetBrains.

the class GitServerVersionHealthPage method isAvailable.

@Override
public boolean isAvailable(@NotNull HttpServletRequest request) {
    if (!super.isAvailable(request))
        return false;
    if (!SessionUser.getUser(request).isPermissionGrantedGlobally(Permission.MANAGE_SERVER_INSTALLATION))
        return false;
    if (!myGitOperations.isNativeGitOperationsEnabled())
        return false;
    final HealthStatusItem item = getStatusItem(request);
    final Object gitExec = item.getAdditionalData().get("gitExec");
    return gitExec == null || gitExec instanceof GitExec && ((GitExec) gitExec).getVersion().equals(getCurrentGitVersion());
}
Also used : HealthStatusItem(jetbrains.buildServer.serverSide.healthStatus.HealthStatusItem) GitExec(jetbrains.buildServer.buildTriggers.vcs.git.command.GitExec)

Example 2 with GitExec

use of jetbrains.buildServer.buildTriggers.vcs.git.command.GitExec in project teamcity-git by JetBrains.

the class AutoCheckoutTest method should_respect_root_settings_when_checking_multi_root_constraints2.

@TestFor(issues = "TW-49786")
public void should_respect_root_settings_when_checking_multi_root_constraints2() throws Exception {
    VcsRoot root1 = vcsRoot().withId(1).withFetchUrl("http://some.org/repo1.git").build();
    VcsRoot root2 = vcsRoot().withId(2).withFetchUrl("http://some.org/repo2.git").build();
    AgentRunningBuild build = runningBuild().addRootEntry(root1, "+:dir1").addRootEntry(root2, "+:dir2").build();
    // both roots require sparse checkout and mapped into the same directory, but the second
    // root uses git version which doesn't support sparse checkout; we shouldn't take it into
    // account during canCheckout() check for the first root
    GitDetector detector = new GitDetector() {

        @NotNull
        public GitExec getGitPathAndVersion(@NotNull VcsRoot root, @NotNull BuildAgentConfiguration config, @NotNull AgentRunningBuild build) throws VcsException {
            if (root.equals(root1)) {
                return new GitExec("git1", GIT_WITH_SPARSE_CHECKOUT);
            }
            if (root.equals(root2)) {
                return new GitExec("git2", GIT_WITH_SPARSE_CHECKOUT.previousVersion());
            }
            throw new VcsException("Unexpected VCS root");
        }

        @NotNull
        @Override
        public GitExec getGitPathAndVersion(@NotNull AgentRunningBuild build) throws VcsException {
            throw new UnsupportedOperationException();
        }
    };
    myVcsSupport = createVcsSupport(detector);
    AgentCheckoutAbility canCheckout1 = myVcsSupport.canCheckout(root1, new CheckoutRules("+:dir1"), build);
    AgentCheckoutAbility canCheckout2 = myVcsSupport.canCheckout(root2, new CheckoutRules("+:dir2"), build);
    then(canCheckout1.getCanNotCheckoutReason()).isNull();
    then(canCheckout2.getCanNotCheckoutReason().getType()).isEqualTo(AgentCanNotCheckoutReason.NOT_SUPPORTED_CHECKOUT_RULES);
    then(canCheckout2.getCanNotCheckoutReason().getDetails()).contains("Cannot perform sparse checkout using git " + GIT_WITH_SPARSE_CHECKOUT.previousVersion());
}
Also used : AgentRunningBuild(jetbrains.buildServer.agent.AgentRunningBuild) AgentCheckoutAbility(jetbrains.buildServer.agent.vcs.AgentCheckoutAbility) VcsException(jetbrains.buildServer.vcs.VcsException) GitExec(jetbrains.buildServer.buildTriggers.vcs.git.command.GitExec) CheckoutRules(jetbrains.buildServer.vcs.CheckoutRules) VcsRoot(jetbrains.buildServer.vcs.VcsRoot) GitDetector(jetbrains.buildServer.buildTriggers.vcs.git.agent.GitDetector) NotNull(org.jetbrains.annotations.NotNull) BuildAgentConfiguration(jetbrains.buildServer.agent.BuildAgentConfiguration) TestFor(jetbrains.buildServer.util.TestFor)

Example 3 with GitExec

use of jetbrains.buildServer.buildTriggers.vcs.git.command.GitExec in project teamcity-git by JetBrains.

the class SSLInvestigatorTest method createFactory.

private GitFactory createFactory() {
    final GitAgentSSHService ssh = myMockery.mock(GitAgentSSHService.class);
    final GitProgressLogger logger = myMockery.mock(GitProgressLogger.class);
    final Context context = myMockery.mock(Context.class);
    myMockery.checking(new Expectations() {

        {
            atLeast(1).of(context).getGitVersion();
            will(returnValue(GitVersion.MIN));
            atLeast(1).of(context).isDeleteTempFiles();
            will(returnValue(false));
            atLeast(1).of(context).getGitExec();
            will(returnValue(new GitExec("git", GitVersion.MIN)));
            atLeast(1).of(context).getCustomConfig();
            will(returnValue(Collections.emptyList()));
            atLeast(1).of(context).getLogger();
            will(returnValue(logger));
            atLeast(1).of(context).getTempDir();
            will(returnValue(myTempDirectory));
            atLeast(1).of(context).getEnv();
            will(returnValue(Collections.emptyMap()));
        }
    });
    return myLoggingFactory.createFactory(ssh, context);
}
Also used : Context(jetbrains.buildServer.buildTriggers.vcs.git.command.Context) Expectations(org.jmock.Expectations) GitAgentSSHService(jetbrains.buildServer.buildTriggers.vcs.git.agent.GitAgentSSHService) GitExec(jetbrains.buildServer.buildTriggers.vcs.git.command.GitExec) GitProgressLogger(jetbrains.buildServer.buildTriggers.vcs.git.GitProgressLogger)

Example 4 with GitExec

use of jetbrains.buildServer.buildTriggers.vcs.git.command.GitExec in project teamcity-git by JetBrains.

the class AgentGitFacadeImpl method resolvePath.

@NotNull
public String resolvePath(@NotNull File f) throws VcsException {
    try {
        final GitExec gitExec = getCtx().getGitExec();
        if (gitExec.isCygwin()) {
            String cygwinBin = gitExec.getCygwinBinPath();
            GeneralCommandLine cmd = new GeneralCommandLine();
            cmd.setWorkDirectory(cygwinBin);
            cmd.setExePath(new File(cygwinBin, "cygpath.exe").getCanonicalPath());
            cmd.addParameter(f.getCanonicalPath());
            ExecResult res = SimpleCommandLineProcessRunner.runCommandSecure(cmd, cmd.getCommandLineString(), null, new ProcessTimeoutCallback(30));
            Throwable error = res.getException();
            if (error != null)
                throw error;
            return res.getStdout().trim();
        } else {
            return f.getCanonicalPath();
        }
    } catch (Throwable e) {
        throw new VcsException("Error while resolving path " + f.getAbsolutePath() + ": " + e.getMessage(), e);
    }
}
Also used : ProcessTimeoutCallback(jetbrains.buildServer.buildTriggers.vcs.git.command.impl.ProcessTimeoutCallback) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) VcsException(jetbrains.buildServer.vcs.VcsException) GitExec(jetbrains.buildServer.buildTriggers.vcs.git.command.GitExec) File(java.io.File) ExecResult(jetbrains.buildServer.ExecResult) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with GitExec

use of jetbrains.buildServer.buildTriggers.vcs.git.command.GitExec in project teamcity-git by JetBrains.

the class GitDetectorImpl method getGitPathAndVersionInternal.

@NotNull
private GitExec getGitPathAndVersionInternal(@Nullable VcsRoot root, @Nullable BuildAgentConfiguration config, @NotNull AgentRunningBuild build) throws VcsException {
    String path = getPathFromRoot(root, config);
    if (path != null) {
        Loggers.VCS.info("Using vcs root's git: " + path);
    } else {
        path = build.getSharedBuildParameters().getEnvironmentVariables().get(Constants.TEAMCITY_AGENT_GIT_PATH);
        if (path != null) {
            Loggers.VCS.info("Using git specified by " + Constants.TEAMCITY_AGENT_GIT_PATH + ": " + path);
        } else {
            path = defaultGit();
            Loggers.VCS.info("Using default git: " + path);
        }
    }
    GitVersion version = getGitVersion(path);
    checkVersionIsSupported(path, version);
    return new GitExec(path, version, getCygwinBinPath(path));
}
Also used : GitVersion(jetbrains.buildServer.buildTriggers.vcs.git.GitVersion) GitExec(jetbrains.buildServer.buildTriggers.vcs.git.command.GitExec) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

GitExec (jetbrains.buildServer.buildTriggers.vcs.git.command.GitExec)11 NotNull (org.jetbrains.annotations.NotNull)5 VcsException (jetbrains.buildServer.vcs.VcsException)4 File (java.io.File)2 GitVersion (jetbrains.buildServer.buildTriggers.vcs.git.GitVersion)2 VcsRoot (jetbrains.buildServer.vcs.VcsRoot)2 GeneralCommandLine (com.intellij.execution.configurations.GeneralCommandLine)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 ExecResult (jetbrains.buildServer.ExecResult)1 AgentRunningBuild (jetbrains.buildServer.agent.AgentRunningBuild)1 BuildAgentConfiguration (jetbrains.buildServer.agent.BuildAgentConfiguration)1 AgentCheckoutAbility (jetbrains.buildServer.agent.vcs.AgentCheckoutAbility)1 GitProgressLogger (jetbrains.buildServer.buildTriggers.vcs.git.GitProgressLogger)1 AgentGitFacadeImpl (jetbrains.buildServer.buildTriggers.vcs.git.agent.AgentGitFacadeImpl)1 GitAgentSSHService (jetbrains.buildServer.buildTriggers.vcs.git.agent.GitAgentSSHService)1 GitDetector (jetbrains.buildServer.buildTriggers.vcs.git.agent.GitDetector)1 PluginConfigImpl (jetbrains.buildServer.buildTriggers.vcs.git.agent.PluginConfigImpl)1 Context (jetbrains.buildServer.buildTriggers.vcs.git.command.Context)1 NativeGitCommands (jetbrains.buildServer.buildTriggers.vcs.git.command.NativeGitCommands)1