Search in sources :

Example 1 with GitRepoOperationsImpl

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

the class GitMergeSupportTest method setUp.

@BeforeMethod
public void setUp() throws Exception {
    super.setUp();
    myPaths = new ServerPaths(myTempFiles.createTempDir().getAbsolutePath());
    GitSupportBuilder builder = gitSupport().withServerPaths(myPaths);
    myGit = builder.build();
    myRepoOperations = new GitRepoOperationsImpl(builder.getPluginConfig(), builder.getTransportFactory(), r -> null, (a, b, c) -> {
    });
    myMergeSupport = new GitMergeSupport(myGit, builder.getCommitLoader(), builder.getRepositoryManager(), builder.getPluginConfig(), myRepoOperations);
    myRoot = vcsRoot().withFetchUrl(getRemoteRepositoryDir("merge")).build();
}
Also used : GitSupportBuilder.gitSupport(jetbrains.buildServer.buildTriggers.vcs.git.tests.GitSupportBuilder.gitSupport) TestFor(jetbrains.buildServer.util.TestFor) BeforeMethod(org.testng.annotations.BeforeMethod) VcsRootBuilder.vcsRoot(jetbrains.buildServer.buildTriggers.vcs.git.tests.VcsRootBuilder.vcsRoot) Test(org.testng.annotations.Test) Util.map(jetbrains.buildServer.util.Util.map) BDDAssertions.then(org.assertj.core.api.BDDAssertions.then) ServerPaths(jetbrains.buildServer.serverSide.ServerPaths) jetbrains.buildServer.vcs(jetbrains.buildServer.vcs) AfterMethod(org.testng.annotations.AfterMethod) AtomicReference(java.util.concurrent.atomic.AtomicReference) GitMergeSupport(jetbrains.buildServer.buildTriggers.vcs.git.GitMergeSupport) AssertJUnit.assertTrue(org.testng.AssertJUnit.assertTrue) GitRepoOperationsImpl(jetbrains.buildServer.buildTriggers.vcs.git.command.impl.GitRepoOperationsImpl) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) Arrays.asList(java.util.Arrays.asList) PluginConfigBuilder.pluginConfig(jetbrains.buildServer.buildTriggers.vcs.git.tests.PluginConfigBuilder.pluginConfig) AssertJUnit.assertEquals(org.testng.AssertJUnit.assertEquals) GitVcsSupport(jetbrains.buildServer.buildTriggers.vcs.git.GitVcsSupport) GitMergeSupport(jetbrains.buildServer.buildTriggers.vcs.git.GitMergeSupport) GitRepoOperationsImpl(jetbrains.buildServer.buildTriggers.vcs.git.command.impl.GitRepoOperationsImpl) ServerPaths(jetbrains.buildServer.serverSide.ServerPaths) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 2 with GitRepoOperationsImpl

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

the class GitPatchProcess method main.

public static void main(String... args) throws Exception {
    Map<String, String> properties = VcsUtil.stringToProperties(GitServerUtil.readInput());
    GitPatchProcessSettings settings = new GitPatchProcessSettings(properties);
    GitServerUtil.configureInternalProperties(settings.getInternalProperties());
    GitServerUtil.configureStreamFileThreshold(Integer.MAX_VALUE);
    GitServerUtil.configureExternalProcessLogger(settings.isDebugEnabled());
    GitServerUtil.setupMemoryMappedIndexReading();
    JSchConfigInitializer.initJSchConfig(JSch.class);
    PluginConfigImpl config = new PluginConfigImpl(new ConstantCachePaths(settings.getGitCachesDir()));
    RepositoryManager repositoryManager = new RepositoryManagerImpl(config, new MirrorManagerImpl(config, new HashCalculatorImpl(), new RemoteRepositoryUrlInvestigatorImpl()));
    GitMapFullPath mapFullPath = new GitMapFullPath(config, new RevisionsCache(config));
    VcsRootSshKeyManager sshKeyManager = new ConstantSshKeyManager(settings.getKeyBytes());
    TransportFactory transportFactory = new TransportFactoryImpl(config, sshKeyManager, settings.getGitTrustStoreProvider());
    FetcherProperties fetcherProperties = new FetcherProperties(config);
    FetchCommand fetchCommand = new FetchCommandImpl(config, transportFactory, fetcherProperties, sshKeyManager, settings.getGitTrustStoreProvider());
    GitRepoOperations repoOperations = new GitRepoOperationsImpl(config, transportFactory, sshKeyManager, fetchCommand);
    CommitLoader commitLoader = new CommitLoaderImpl(repositoryManager, repoOperations, mapFullPath, config);
    OperationContext context = new OperationContext(commitLoader, repositoryManager, settings.getRoot(), "build patch", GitProgress.NO_OP, config, null);
    OutputStream fos = new BufferedOutputStream(new FileOutputStream(settings.getPatchFile()));
    try {
        PatchBuilderImpl patchBuilder = new PatchBuilderImpl(fos);
        new GitPatchBuilder(context, patchBuilder, settings.getFromRevision(), settings.getToRevision(), settings.getCheckoutRules(), settings.isVerboseTreeWalkLog(), new PrintFile(), transportFactory).buildPatch();
        patchBuilder.close();
    } catch (Throwable t) {
        if (settings.isDebugEnabled() || isImportant(t)) {
            System.err.println(t.getMessage());
            t.printStackTrace(System.err);
        } else {
            String msg = t.getMessage();
            boolean printStackTrace = false;
            if (t instanceof SubmoduleFetchException) {
                Throwable cause = t.getCause();
                printStackTrace = cause != null && isImportant(cause);
            }
            System.err.println(msg);
            if (printStackTrace)
                t.printStackTrace(System.err);
        }
        System.exit(1);
    } finally {
        fos.close();
    }
}
Also used : SubmoduleFetchException(jetbrains.buildServer.buildTriggers.vcs.git.submodules.SubmoduleFetchException) PatchBuilderImpl(jetbrains.buildServer.vcs.patches.PatchBuilderImpl) GitRepoOperationsImpl(jetbrains.buildServer.buildTriggers.vcs.git.command.impl.GitRepoOperationsImpl) VcsRootSshKeyManager(jetbrains.buildServer.ssh.VcsRootSshKeyManager)

Example 3 with GitRepoOperationsImpl

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

the class SshAuthenticationTest method do_ssh_test.

private void do_ssh_test(boolean nativeOperationsEnabled, boolean useSshAskPass, @NotNull String urlFormat, @NotNull String sshdConfig, @Nullable TeamCitySshKey tcKey, @Nullable String publicKey, @NotNull VcsRootConfigurator builder, boolean ignoreKnownHosts) throws Exception {
    if (!nativeOperationsEnabled) {
        JSchConfigInitializer.initJSchConfig(JSch.class);
    }
    final File pub_key = publicKey == null ? null : dataFile(publicKey);
    ssh_test(pub_key, sshdConfig, container -> {
        setInternalProperty("teamcity.git.nativeOperationsEnabled", String.valueOf(nativeOperationsEnabled));
        setInternalProperty("teamcity.git.useSshAskPas", String.valueOf(useSshAskPass));
        setInternalProperty("teamcity.git.debugNativeGit", "true");
        final ServerPaths serverPaths = new ServerPaths(myTempFiles.createTempDir().getAbsolutePath());
        final ServerPluginConfig config = new PluginConfigBuilder(serverPaths).build();
        final VcsRootSshKeyManager keyManager = r -> tcKey;
        final TransportFactoryImpl transportFactory = new TransportFactoryImpl(config, keyManager);
        final GitRepoOperationsImpl repoOperations = new GitRepoOperationsImpl(config, transportFactory, keyManager, new FetchCommandImpl(config, transportFactory, new FetcherProperties(config), keyManager));
        final MirrorManagerImpl mirrorManager = new MirrorManagerImpl(config, new HashCalculatorImpl(), new RemoteRepositoryUrlInvestigatorImpl());
        final RepositoryManagerImpl repositoryManager = new RepositoryManagerImpl(config, mirrorManager);
        final String repoUrl = String.format(urlFormat, container.getContainerIpAddress(), container.getMappedPort(22));
        final GitVcsRoot gitRoot = new GitVcsRoot(mirrorManager, builder.config(VcsRootBuilder.vcsRoot().withFetchUrl(repoUrl).withIgnoreKnownHosts(ignoreKnownHosts)).build(), new URIishHelperImpl());
        JSch.setLogger(JSchLoggers.STD_DEBUG_JSCH_LOGGER);
        // here we test some git operations
        final URIish fetchUrl = new URIish(repoUrl);
        final Repository db = repositoryManager.openRepository(fetchUrl);
        final Map<String, Ref> refs = repoOperations.lsRemoteCommand(repoUrl).lsRemote(db, gitRoot, new FetchSettings(gitRoot.getAuthSettings()));
        assertContains(refs.keySet(), "refs/pull/1");
        final StringBuilder progress = new StringBuilder();
        final List<RefSpec> refSpecs = refs.keySet().stream().map(r -> new RefSpec().setSourceDestination(r, r).setForceUpdate(true)).collect(Collectors.toList());
        repoOperations.fetchCommand(repoUrl).fetch(db, fetchUrl, new FetchSettings(gitRoot.getAuthSettings(), new GitProgress() {

            @Override
            public void reportProgress(@NotNull final String p) {
                progress.append(p).append("\n");
            }

            @Override
            public void reportProgress(final float p, @NotNull final String stage) {
                if (p < 0) {
                    progress.append(stage).append("\n");
                } else {
                    int percents = (int) Math.floor(p * 100);
                    progress.append(stage).append(" ").append(percents).append("%");
                }
            }
        }, refSpecs));
        if (nativeOperationsEnabled) {
            assertContains(progress.toString(), "* [new ref]         refs/pull/1               -> refs/pull/1");
        } else {
            assertContains(progress.toString(), "update ref remote name: refs/pull/1, local name: refs/pull/1, old object id: 0000000000000000000000000000000000000000, new object id: b896070465af79121c9a4eb5300ecff29453c164, result: NEW");
        }
        final GitVcsSupport vcsSupport = GitSupportBuilder.gitSupport().withServerPaths(serverPaths).withPluginConfig(config).withTransportFactory(transportFactory).build();
        repoOperations.tagCommand(vcsSupport, repoUrl).tag(vcsSupport.createContext(gitRoot.getOriginalRoot(), "tag"), "test_tag", "b896070465af79121c9a4eb5300ecff29453c164");
        assertContains(repoOperations.lsRemoteCommand(repoUrl).lsRemote(db, gitRoot, new FetchSettings(gitRoot.getAuthSettings())).keySet(), "refs/tags/test_tag");
    });
}
Also used : SkipException(org.testng.SkipException) GitTestUtil.dataFile(jetbrains.buildServer.buildTriggers.vcs.git.tests.GitTestUtil.dataFile) BindMode(org.testcontainers.containers.BindMode) ImageFromDockerfile(org.testcontainers.images.builder.ImageFromDockerfile) JSch(com.jcraft.jsch.JSch) jetbrains.buildServer.buildTriggers.vcs.git(jetbrains.buildServer.buildTriggers.vcs.git) TestFor(jetbrains.buildServer.util.TestFor) TempFiles(jetbrains.buildServer.TempFiles) Callable(java.util.concurrent.Callable) Test(org.testng.annotations.Test) GitRepoOperationsImpl(jetbrains.buildServer.buildTriggers.vcs.git.command.impl.GitRepoOperationsImpl) FileUtil(jetbrains.buildServer.util.FileUtil) BaseTestCase(jetbrains.buildServer.BaseTestCase) Map(java.util.Map) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) URIish(org.eclipse.jgit.transport.URIish) GenericContainer(org.testcontainers.containers.GenericContainer) JSchConfigInitializer(jetbrains.buildServer.util.jsch.JSchConfigInitializer) Files(java.nio.file.Files) RefSpec(org.eclipse.jgit.transport.RefSpec) BeforeMethod(org.testng.annotations.BeforeMethod) IOException(java.io.IOException) ServerPaths(jetbrains.buildServer.serverSide.ServerPaths) Collectors(java.util.stream.Collectors) SystemInfo(com.intellij.openapi.util.SystemInfo) File(java.io.File) TeamCitySshKey(jetbrains.buildServer.ssh.TeamCitySshKey) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) ExecResult(jetbrains.buildServer.ExecResult) SimpleCommandLineProcessRunner(jetbrains.buildServer.SimpleCommandLineProcessRunner) Ref(org.eclipse.jgit.lib.Ref) VcsRootSshKeyManager(jetbrains.buildServer.ssh.VcsRootSshKeyManager) NotNull(org.jetbrains.annotations.NotNull) Repository(org.eclipse.jgit.lib.Repository) URIish(org.eclipse.jgit.transport.URIish) GitRepoOperationsImpl(jetbrains.buildServer.buildTriggers.vcs.git.command.impl.GitRepoOperationsImpl) NotNull(org.jetbrains.annotations.NotNull) RefSpec(org.eclipse.jgit.transport.RefSpec) ServerPaths(jetbrains.buildServer.serverSide.ServerPaths) Repository(org.eclipse.jgit.lib.Repository) Ref(org.eclipse.jgit.lib.Ref) VcsRootSshKeyManager(jetbrains.buildServer.ssh.VcsRootSshKeyManager) GitTestUtil.dataFile(jetbrains.buildServer.buildTriggers.vcs.git.tests.GitTestUtil.dataFile) File(java.io.File)

Example 4 with GitRepoOperationsImpl

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

the class GitSupportBuilder method build.

@NotNull
public GitVcsSupport build() {
    if (myPluginConfigBuilder == null && myServerPaths == null && myPluginConfig == null)
        throw new IllegalStateException("Plugin config or server paths should be set");
    if (myPluginConfig == null)
        myPluginConfig = myPluginConfigBuilder != null ? myPluginConfigBuilder.build() : new PluginConfigImpl(myServerPaths);
    if (myTransportFactory == null)
        myTransportFactory = new TransportFactoryImpl(myPluginConfig, myVcsRootSSHKeyManager);
    Mockery context = new Mockery();
    if (myFetchCommand == null) {
        if (myBeforeFetchHook == null) {
            myFetchCommand = new FetchCommandImpl(myPluginConfig, myTransportFactory, new FetcherProperties(myPluginConfig), myVcsRootSSHKeyManager);
        } else {
            final FetchCommand originalCommand = new FetchCommandImpl(myPluginConfig, myTransportFactory, new FetcherProperties(myPluginConfig), myVcsRootSSHKeyManager);
            myFetchCommand = (db, fetchURI, settings) -> {
                myBeforeFetchHook.run();
                originalCommand.fetch(db, fetchURI, settings);
            };
        }
    }
    MirrorManager mirrorManager = new MirrorManagerImpl(myPluginConfig, new HashCalculatorImpl(), new RemoteRepositoryUrlInvestigatorImpl());
    myRepositoryManager = new RepositoryManagerImpl(myPluginConfig, mirrorManager);
    final ResetCacheRegister resetCacheManager;
    if (myResetCacheManager == null) {
        context.setImposteriser(ClassImposteriser.INSTANCE);
        resetCacheManager = context.mock(ResetCacheRegister.class);
        context.checking(new Expectations() {

            {
                allowing(resetCacheManager).registerHandler(with(any(ResetCacheHandler.class)));
            }
        });
    } else {
        resetCacheManager = myResetCacheManager;
    }
    RevisionsCache revisionsCache = new RevisionsCache(myPluginConfig);
    myMapFullPath = new GitMapFullPath(myPluginConfig, revisionsCache);
    final GitRepoOperationsImpl gitRepoOperations = new GitRepoOperationsImpl(myPluginConfig, myTransportFactory, myVcsRootSSHKeyManager, myFetchCommand);
    myCommitLoader = new CommitLoaderImpl(myRepositoryManager, gitRepoOperations, myMapFullPath, myPluginConfig);
    GitResetCacheHandler resetCacheHandler = new GitResetCacheHandler(myRepositoryManager, new GcErrors());
    ResetRevisionsCacheHandler resetRevisionsCacheHandler = new ResetRevisionsCacheHandler(revisionsCache);
    TokenRefresher tokenRefresher = new TokenRefresher() {

        @Nullable
        @Override
        public OAuthToken getRefreshableToken(@NotNull String vcsRootExtId, @NotNull String tokenFullId) {
            return null;
        }

        @Nullable
        @Override
        public OAuthToken getRefreshableToken(@NotNull SProject project, @NotNull String tokenFullId) {
            return null;
        }
    };
    GitVcsSupport git = new GitVcsSupport(gitRepoOperations, myPluginConfig, resetCacheManager, myTransportFactory, myRepositoryManager, myMapFullPath, myCommitLoader, myVcsRootSSHKeyManager, new MockVcsOperationProgressProvider(), resetCacheHandler, resetRevisionsCacheHandler, tokenRefresher, myTestConnectionSupport);
    git.addExtensions(myExtensions);
    git.setExtensionHolder(myExtensionHolder);
    return git;
}
Also used : TokenRefresher(jetbrains.buildServer.serverSide.oauth.TokenRefresher) GitRepoOperationsImpl(jetbrains.buildServer.buildTriggers.vcs.git.command.impl.GitRepoOperationsImpl) SProject(jetbrains.buildServer.serverSide.SProject) Mockery(org.jmock.Mockery) NotNull(org.jetbrains.annotations.NotNull) Expectations(org.jmock.Expectations) MockVcsOperationProgressProvider(jetbrains.buildServer.vcs.MockVcsOperationProgressProvider) ResetCacheHandler(jetbrains.buildServer.util.cache.ResetCacheHandler) ResetCacheRegister(jetbrains.buildServer.util.cache.ResetCacheRegister) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with GitRepoOperationsImpl

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

the class GitCommitSupportTest method setUp.

@BeforeMethod
@Override
public void setUp() throws Exception {
    super.setUp();
    myPaths = new ServerPaths(myTempFiles.createTempDir().getAbsolutePath());
    GitSupportBuilder builder = gitSupport().withServerPaths(myPaths);
    myGit = builder.build();
    myCommitSupport = new GitCommitSupport(myGit, builder.getCommitLoader(), builder.getRepositoryManager(), new GitRepoOperationsImpl(builder.getPluginConfig(), builder.getTransportFactory(), r -> null, (a, b, c) -> {
    }));
    myRoot = vcsRoot().withFetchUrl(getRemoteRepositoryDir("merge")).build();
}
Also used : GitRepoOperationsImpl(jetbrains.buildServer.buildTriggers.vcs.git.command.impl.GitRepoOperationsImpl) ServerPaths(jetbrains.buildServer.serverSide.ServerPaths) BeforeMethod(org.testng.annotations.BeforeMethod)

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