Search in sources :

Example 1 with Context

use of jetbrains.buildServer.buildTriggers.vcs.git.command.Context 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 2 with Context

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

the class GitCommitSupportTest method local_state_restored_if_push_fails.

@Test
public void local_state_restored_if_push_fails() throws Exception {
    // perform successfull commit to make local repo not empty
    CommitPatchBuilder patchBuilder = myCommitSupport.getCommitPatchBuilder(myRoot);
    byte[] bytes = "test-content".getBytes();
    patchBuilder.createFile("file-to-commit", new ByteArrayInputStream(bytes));
    patchBuilder.commit(new CommitSettingsImpl("user", "Commit description"));
    patchBuilder.dispose();
    GitSupportBuilder builder = gitSupport().withServerPaths(myPaths);
    builder.build();
    final ServerPluginConfig config = builder.getPluginConfig();
    final RepositoryManager repositoryManager = builder.getRepositoryManager();
    myCommitSupport = new GitCommitSupport(myGit, builder.getCommitLoader(), repositoryManager, new GitRepoOperationsImpl(config, builder.getTransportFactory(), r -> null, (a, b, c) -> {
    }) {

        @NotNull
        @Override
        public PushCommand pushCommand(@NotNull String repoUrl) {
            return new NativeGitCommands(config, GitCommitSupportTest::detectGitStub, r -> null) {

                @Override
                protected <R> R executeCommand(@NotNull Context ctx, @NotNull String action, @NotNull String debugInfo, @NotNull FuncThrow<R, VcsException> cmd) throws VcsException {
                    throw new VcsException("Always fails");
                }
            };
        }
    });
    final File mirror = repositoryManager.getMirrorDir(getRemoteRepositoryDir("merge").getAbsolutePath());
    final String before = showRef(mirror, "refs/heads/master");
    final RepositoryStateData state1 = myGit.getCurrentState(myRoot);
    patchBuilder = myCommitSupport.getCommitPatchBuilder(myRoot);
    bytes = "new-test-content".getBytes();
    patchBuilder.createFile("new-file-to-commit", new ByteArrayInputStream(bytes));
    try {
        patchBuilder.commit(new CommitSettingsImpl("user", "New commit description"));
    } catch (VcsException e) {
    // expected
    }
    patchBuilder.dispose();
    assertEquals(state1, myGit.getCurrentState(myRoot));
    assertEquals(before, showRef(mirror, "refs/heads/master"));
}
Also used : Context(jetbrains.buildServer.buildTriggers.vcs.git.command.Context) NativeGitCommands(jetbrains.buildServer.buildTriggers.vcs.git.command.NativeGitCommands) GitRepoOperationsImpl(jetbrains.buildServer.buildTriggers.vcs.git.command.impl.GitRepoOperationsImpl) NotNull(org.jetbrains.annotations.NotNull) FuncThrow(jetbrains.buildServer.util.FuncThrow) ByteArrayInputStream(java.io.ByteArrayInputStream) File(java.io.File) Test(org.testng.annotations.Test)

Aggregations

Context (jetbrains.buildServer.buildTriggers.vcs.git.command.Context)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 GitProgressLogger (jetbrains.buildServer.buildTriggers.vcs.git.GitProgressLogger)1 GitAgentSSHService (jetbrains.buildServer.buildTriggers.vcs.git.agent.GitAgentSSHService)1 GitExec (jetbrains.buildServer.buildTriggers.vcs.git.command.GitExec)1 NativeGitCommands (jetbrains.buildServer.buildTriggers.vcs.git.command.NativeGitCommands)1 GitRepoOperationsImpl (jetbrains.buildServer.buildTriggers.vcs.git.command.impl.GitRepoOperationsImpl)1 FuncThrow (jetbrains.buildServer.util.FuncThrow)1 NotNull (org.jetbrains.annotations.NotNull)1 Expectations (org.jmock.Expectations)1 Test (org.testng.annotations.Test)1