Search in sources :

Example 6 with GitRepoOperationsImpl

use of jetbrains.buildServer.buildTriggers.vcs.git.command.impl.GitRepoOperationsImpl 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

GitRepoOperationsImpl (jetbrains.buildServer.buildTriggers.vcs.git.command.impl.GitRepoOperationsImpl)6 ServerPaths (jetbrains.buildServer.serverSide.ServerPaths)3 NotNull (org.jetbrains.annotations.NotNull)3 BeforeMethod (org.testng.annotations.BeforeMethod)3 Test (org.testng.annotations.Test)3 File (java.io.File)2 List (java.util.List)2 VcsRootSshKeyManager (jetbrains.buildServer.ssh.VcsRootSshKeyManager)2 TestFor (jetbrains.buildServer.util.TestFor)2 GeneralCommandLine (com.intellij.execution.configurations.GeneralCommandLine)1 SystemInfo (com.intellij.openapi.util.SystemInfo)1 JSch (com.jcraft.jsch.JSch)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 Files (java.nio.file.Files)1 Arrays.asList (java.util.Arrays.asList)1 Map (java.util.Map)1 Callable (java.util.concurrent.Callable)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1