Search in sources :

Example 1 with NativeGitCommands

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

Example 2 with NativeGitCommands

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

the class GitPerformanceTests method incrementalIntellijFetch.

@Test
public // @Test(invocationCount = 100)
void incrementalIntellijFetch() throws Exception {
    final VcsRootImpl root = VcsRootBuilder.vcsRoot().withBranchSpec("+:refs/heads/*").withFetchUrl("ssh://git@git.jetbrains.team/intellij.git").withAuthMethod(AuthenticationMethod.PRIVATE_KEY_DEFAULT).build();
    final ServerPaths sp = new ServerPaths("/Users/victory/Tests/server_paths");
    final ServerPluginConfig config = new PluginConfigBuilder(sp).setSeparateProcessForFetch(true).build();
    final GitSupportBuilder builder = GitSupportBuilder.gitSupport().withServerPaths(sp).withPluginConfig(config).withFetchCommand(new NativeGitCommands(config, () -> new GitExec("git", new GitVersion(2, 34, 0)), new VcsRootSshKeyManager() {

        @Nullable
        @Override
        public TeamCitySshKey getKey(@NotNull VcsRoot root) {
            return null;
        }
    }));
    GitVcsSupport support = builder.build();
    final RepositoryStateData currentState = support.getCurrentState(root);
    final long startTime = new Date().getTime();
    System.out.println("Fetching repository...");
    final OperationContext ctx = support.createContext(root, "fetch");
    try {
        support.getCollectChangesPolicy().ensureRepositoryStateLoadedFor(ctx, currentState, true);
    } finally {
        ctx.close();
    }
    final long totalTime = new Date().getTime() - startTime;
    System.out.println("Fetch time: " + totalTime + "ms");
}
Also used : NativeGitCommands(jetbrains.buildServer.buildTriggers.vcs.git.command.NativeGitCommands) GitExec(jetbrains.buildServer.buildTriggers.vcs.git.command.GitExec) VcsRoot(jetbrains.buildServer.vcs.VcsRoot) NotNull(org.jetbrains.annotations.NotNull) Date(java.util.Date) VcsRootImpl(jetbrains.buildServer.vcs.impl.VcsRootImpl) RepositoryStateData(jetbrains.buildServer.vcs.RepositoryStateData) VcsRootSshKeyManager(jetbrains.buildServer.ssh.VcsRootSshKeyManager) ServerPaths(jetbrains.buildServer.serverSide.ServerPaths) Test(org.testng.annotations.Test)

Aggregations

NativeGitCommands (jetbrains.buildServer.buildTriggers.vcs.git.command.NativeGitCommands)2 NotNull (org.jetbrains.annotations.NotNull)2 Test (org.testng.annotations.Test)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 Date (java.util.Date)1 Context (jetbrains.buildServer.buildTriggers.vcs.git.command.Context)1 GitExec (jetbrains.buildServer.buildTriggers.vcs.git.command.GitExec)1 GitRepoOperationsImpl (jetbrains.buildServer.buildTriggers.vcs.git.command.impl.GitRepoOperationsImpl)1 ServerPaths (jetbrains.buildServer.serverSide.ServerPaths)1 VcsRootSshKeyManager (jetbrains.buildServer.ssh.VcsRootSshKeyManager)1 FuncThrow (jetbrains.buildServer.util.FuncThrow)1 RepositoryStateData (jetbrains.buildServer.vcs.RepositoryStateData)1 VcsRoot (jetbrains.buildServer.vcs.VcsRoot)1 VcsRootImpl (jetbrains.buildServer.vcs.impl.VcsRootImpl)1