Search in sources :

Example 6 with GitCommandLine

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

the class FetchCommandImplTest method negative_refspec_for_tags.

@Test
public void negative_refspec_for_tags() throws Exception {
    final String gitPath = getGitPath();
    final GitVersion version = new AgentGitFacadeImpl(gitPath).version().call();
    if (!GitVersion.negativeRefSpecSupported(version))
        throw new SkipException("Git version is too old to run this test");
    final File remote = GitTestUtil.dataFile("fetch_multiple_refspecs");
    new File(remote, "refs" + File.separator + "heads").mkdirs();
    final File work = createTempDir();
    runCommand(false, gitPath, work, "init", "--bare");
    final StringBuilder log = new StringBuilder();
    final StubContext context = new StubContext("git", version);
    context.setLogger(createLogger(log));
    final GitCommandLine cmd = new GitCommandLine(context, getFakeGen());
    cmd.setExePath(gitPath);
    cmd.setWorkingDirectory(work);
    final FetchCommandImpl fetch = new FetchCommandImpl(cmd);
    fetch.setRemote(remote.getAbsolutePath());
    fetch.setAuthSettings(getEmptyAuthSettings());
    fetch.setRefspec("+refs/*:refs/*");
    fetch.setRefspec("^refs/tags/*");
    fetch.setFetchTags(false);
    fetch.call();
    // master + 6000 branches
    assertEquals(6001, FileUtil.listFiles(new File(work, "refs/heads"), (d, n) -> true).length);
    assertFalse(new File(work, "refs/tags/my_tag").exists());
    final String logStr = log.toString();
    assertFalse(logStr.contains("my_tag"));
}
Also used : AgentGitCommandLine(jetbrains.buildServer.buildTriggers.vcs.git.agent.AgentGitCommandLine) GitCommandLine(jetbrains.buildServer.buildTriggers.vcs.git.command.GitCommandLine) AgentGitFacadeImpl(jetbrains.buildServer.buildTriggers.vcs.git.agent.AgentGitFacadeImpl) GitVersion(jetbrains.buildServer.buildTriggers.vcs.git.GitVersion) FetchCommandImpl(jetbrains.buildServer.buildTriggers.vcs.git.command.impl.FetchCommandImpl) StubContext(jetbrains.buildServer.buildTriggers.vcs.git.command.impl.StubContext) SkipException(org.testng.SkipException) File(java.io.File) Test(org.testng.annotations.Test)

Example 7 with GitCommandLine

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

the class FetchCommandImplTest method fetch_multiple_refspecs.

@Test
public void fetch_multiple_refspecs() throws Exception {
    final String gitPath = getGitPath();
    final GitVersion version = new AgentGitFacadeImpl(gitPath).version().call();
    if (!GitVersion.fetchSupportsStdin(version))
        throw new SkipException("Git version is too old to run this test");
    final File remote = GitTestUtil.dataFile("fetch_multiple_refspecs");
    new File(remote, "refs" + File.separator + "heads").mkdirs();
    final File work = createTempDir();
    runCommand(false, gitPath, work, "init");
    final GitCommandLine cmd = new GitCommandLine(new StubContext("git", version), getFakeGen());
    cmd.setExePath(gitPath);
    cmd.setWorkingDirectory(work);
    final FetchCommandImpl fetch = new FetchCommandImpl(cmd);
    fetch.setRemote(remote.getAbsolutePath());
    fetch.setAuthSettings(getEmptyAuthSettings());
    for (int i = 0; i < 6000; ++i) {
        fetch.setRefspec("+refs/heads/branch" + i + ":refs/remotes/origin/branch" + i);
    }
    fetch.call();
    assertEquals(6000, FileUtil.listFiles(new File(work, ".git/refs/remotes/origin"), (d, n) -> true).length);
}
Also used : AgentGitCommandLine(jetbrains.buildServer.buildTriggers.vcs.git.agent.AgentGitCommandLine) GitCommandLine(jetbrains.buildServer.buildTriggers.vcs.git.command.GitCommandLine) AgentGitFacadeImpl(jetbrains.buildServer.buildTriggers.vcs.git.agent.AgentGitFacadeImpl) GitVersion(jetbrains.buildServer.buildTriggers.vcs.git.GitVersion) FetchCommandImpl(jetbrains.buildServer.buildTriggers.vcs.git.command.impl.FetchCommandImpl) StubContext(jetbrains.buildServer.buildTriggers.vcs.git.command.impl.StubContext) SkipException(org.testng.SkipException) File(java.io.File) Test(org.testng.annotations.Test)

Example 8 with GitCommandLine

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

the class LogCommandImpl method call.

@Nullable
public String call() {
    try {
        GitCommandLine cmd = getCmd();
        cmd.addParameters("log");
        if (myCommitsNumber != 0)
            cmd.addParameter("-n" + myCommitsNumber);
        if (myFormat != null)
            cmd.addParameter("--pretty=format:" + myFormat);
        cmd.addParameter(myStartPoint);
        cmd.addParameter("--");
        return CommandUtil.runCommand(cmd.stdErrExpected(false)).getStdout().trim();
    } catch (VcsException e) {
        return null;
    }
}
Also used : GitCommandLine(jetbrains.buildServer.buildTriggers.vcs.git.command.GitCommandLine) VcsException(jetbrains.buildServer.vcs.VcsException) Nullable(org.jetbrains.annotations.Nullable)

Example 9 with GitCommandLine

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

the class MergeCommandImpl method call.

@Override
public void call() throws VcsException {
    GitCommandLine cmd = getCmd();
    cmd.addParameter("merge");
    if (myQuiet) {
        cmd.addParameter("-q");
    }
    if (myAbort) {
        cmd.addParameter("--abort");
    }
    cmd.addParameters(myMergeBranches);
    CommandUtil.runCommand(cmd.stdErrExpected(false));
}
Also used : GitCommandLine(jetbrains.buildServer.buildTriggers.vcs.git.command.GitCommandLine)

Example 10 with GitCommandLine

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

the class RepackCommandImpl method call.

public void call() throws VcsException {
    GitCommandLine cmd = getCmd();
    cmd.addParameters("repack", "-a", "-d");
    CommandUtil.runCommand(cmd);
}
Also used : GitCommandLine(jetbrains.buildServer.buildTriggers.vcs.git.command.GitCommandLine)

Aggregations

GitCommandLine (jetbrains.buildServer.buildTriggers.vcs.git.command.GitCommandLine)36 NotNull (org.jetbrains.annotations.NotNull)6 GitVersion (jetbrains.buildServer.buildTriggers.vcs.git.GitVersion)5 ExecResult (jetbrains.buildServer.ExecResult)4 File (java.io.File)3 VcsException (jetbrains.buildServer.vcs.VcsException)3 AgentGitCommandLine (jetbrains.buildServer.buildTriggers.vcs.git.agent.AgentGitCommandLine)2 AgentGitFacadeImpl (jetbrains.buildServer.buildTriggers.vcs.git.agent.AgentGitFacadeImpl)2 FetchCommandImpl (jetbrains.buildServer.buildTriggers.vcs.git.command.impl.FetchCommandImpl)2 StubContext (jetbrains.buildServer.buildTriggers.vcs.git.command.impl.StubContext)2 SkipException (org.testng.SkipException)2 Test (org.testng.annotations.Test)2 ShowRefResult (jetbrains.buildServer.buildTriggers.vcs.git.agent.command.ShowRefResult)1 Nullable (org.jetbrains.annotations.Nullable)1