Search in sources :

Example 36 with VcsRootImpl

use of jetbrains.buildServer.vcs.impl.VcsRootImpl in project teamcity-git by JetBrains.

the class HttpUrlWithUsernameTest method should_include_username_into_url_when_asked.

@Test(dataProvider = "mirrorModes")
public void should_include_username_into_url_when_asked(@NotNull MirrorMode mirrorMode) throws Exception {
    // need that in order to be able to disable new logic in case of any problems
    File repo = copyRepository(myTempFiles, dataFile("repo_for_fetch.1"), "repo.git");
    startGitServer(repo);
    VcsRootImpl root = createRoot();
    AgentRunningBuild build = createBuild(configParams(mirrorMode, PluginConfigImpl.EXCLUDE_USERNAME_FROM_HTTP_URL, "false"));
    checkout(root, build, "add81050184d3c818560bdd8839f50024c188586");
    if (mirrorMode != MirrorMode.DISABLED) {
        StoredConfig config = getMirrorConfig(root);
        then(config.getString("remote", "origin", "url")).contains(USER + "@");
    }
    StoredConfig config = getWorkingDirConfig();
    then(config.getString("remote", "origin", "url")).contains(USER + "@");
}
Also used : StoredConfig(org.eclipse.jgit.lib.StoredConfig) AgentRunningBuild(jetbrains.buildServer.agent.AgentRunningBuild) VcsRootImpl(jetbrains.buildServer.vcs.impl.VcsRootImpl) GitTestUtil.dataFile(jetbrains.buildServer.buildTriggers.vcs.git.tests.GitTestUtil.dataFile) File(java.io.File) Test(org.testng.annotations.Test)

Example 37 with VcsRootImpl

use of jetbrains.buildServer.vcs.impl.VcsRootImpl in project teamcity-git by JetBrains.

the class GitPerformanceTests method toCleanCheckoutTest.

@Test
public void toCleanCheckoutTest() throws Exception {
    final VcsRootImpl root = VcsRootBuilder.vcsRoot().withFetchUrl("E:\\Work\\idea-ultimate").build();
    final ServerPaths sp = new ServerPaths(createTempDir().getPath());
    final GitSupportBuilder builder = GitSupportBuilder.gitSupport().withServerPaths(sp).withPluginConfig(new PluginConfigBuilder(sp).build());
    GitVcsSupport support = builder.build();
    RepositoryStateData s = support.getCurrentState(root);
    final String state = s.getBranchRevisions().get(s.getDefaultBranchName());
    System.out.println("Current state: " + state);
    final long startTime = new Date().getTime();
    System.out.println("Fetching repository...");
    // make sure repository is cloned
    final OperationContext ctx = support.createContext(root, "fetch");
    try {
        builder.getCommitLoader().loadCommit(ctx, ctx.getGitRoot(), state);
    } finally {
        ctx.close();
    }
    final long totalTime = new Date().getTime() - startTime;
    System.out.println("Clone time: " + totalTime + "ms");
    runCleanCheckout(root, support, state);
    // some older state
    runCleanCheckout(root, support, "395c1639ee346816048b1b74cec83ab4dd162451");
}
Also used : VcsRootImpl(jetbrains.buildServer.vcs.impl.VcsRootImpl) RepositoryStateData(jetbrains.buildServer.vcs.RepositoryStateData) ServerPaths(jetbrains.buildServer.serverSide.ServerPaths) Date(java.util.Date) Test(org.testng.annotations.Test)

Example 38 with VcsRootImpl

use of jetbrains.buildServer.vcs.impl.VcsRootImpl 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)

Example 39 with VcsRootImpl

use of jetbrains.buildServer.vcs.impl.VcsRootImpl in project teamcity-git by JetBrains.

the class GitUrlSupportTest method setUp.

@BeforeMethod
public void setUp() throws Exception {
    super.setUp();
    ServerPaths paths = new ServerPaths(myTempFiles.createTempDir().getAbsolutePath());
    PluginConfig config = new PluginConfigBuilder(paths).build();
    myMirrorManager = new MirrorManagerImpl(config, new HashCalculatorImpl(), new RemoteRepositoryUrlInvestigatorImpl());
    myProjectMock = mock(SProject.class);
    final Mock pmMock = mock(ProjectManager.class);
    final SProject project = (SProject) myProjectMock.proxy();
    pmMock.stubs().method("findProjectById").will(returnValue(project));
    ProjectManager pm = (ProjectManager) pmMock.proxy();
    final Mock sshMock = mock(ServerSshKeyManager.class);
    sshMock.stubs().method("getKeys").with(eq(project)).will(returnValue(myTestKeys));
    ServerSshKeyManager ssh = (ServerSshKeyManager) sshMock.proxy();
    Mock epMock = mock(ExtensionsProvider.class);
    epMock.stubs().method("getExtensions").with(eq(ServerSshKeyManager.class)).will(returnValue(Collections.singleton(ssh)));
    myGitVcsSupport = gitSupport().withServerPaths(paths).withTestConnectionSupport(vcsRoot -> {
        if (myTestConnectionMocked != null && myTestConnectionMocked)
            return null;
        return myGitVcsSupport.testConnection(vcsRoot);
    }).build();
    myUrlSupport = new GitUrlSupport(myGitVcsSupport) {

        @NotNull
        @Override
        protected VcsRoot createDummyRoot(@NotNull final Map<String, String> props, @Nullable final SProject curProject) {
            return new VcsRootImpl(-1, Constants.VCS_NAME, props);
        }
    };
    myUrlSupport.setProjectManager(pm);
    myUrlSupport.setExtensionsProvider((ExtensionsProvider) epMock.proxy());
}
Also used : SProject(jetbrains.buildServer.serverSide.SProject) NotNull(org.jetbrains.annotations.NotNull) Mock(org.jmock.Mock) ProjectManager(jetbrains.buildServer.serverSide.ProjectManager) VcsRootImpl(jetbrains.buildServer.vcs.impl.VcsRootImpl) ServerSshKeyManager(jetbrains.buildServer.ssh.ServerSshKeyManager) ServerPaths(jetbrains.buildServer.serverSide.ServerPaths) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 40 with VcsRootImpl

use of jetbrains.buildServer.vcs.impl.VcsRootImpl in project teamcity-git by JetBrains.

the class AgentVcsSupportTest method short_lived_agent_auto_clone_existing_mirror.

@TestFor(issues = "TW-71416")
public void short_lived_agent_auto_clone_existing_mirror() throws Exception {
    final File remote = dataFile("repo_for_shallow_fetch.git");
    final VcsRootImpl root1 = createRoot(remote, "refs/heads/main");
    root1.addProperty(Constants.CHECKOUT_POLICY, AgentCheckoutPolicy.USE_MIRRORS.name());
    myVcsSupport.updateSources(root1, new CheckoutRules(""), "64195c330d99c467a142f682bc23d4de3a68551d", myTempFiles.createTempDir(), myBuild, false);
    final File mirror = myBuilder.getMirrorManager().getMirrorDir(GitUtils.toURL(remote));
    // mirror initialized
    assertFalse(FileUtil.isEmptyDir(mirror));
    myBuild.getAgentConfiguration().addConfigurationParameter(AgentMiscConstants.IS_EPHEMERAL_AGENT_PROP, "true");
    final File testFile = new File(myCheckoutDir, "test_file");
    final File shallowMarker = new File(myCheckoutDir, ".git/shallow");
    final VcsRootImpl root2 = createRoot(remote, "refs/heads/main");
    root2.addProperty(Constants.CHECKOUT_POLICY, AgentCheckoutPolicy.AUTO.name());
    myVcsSupport.updateSources(root2, new CheckoutRules(""), "64195c330d99c467a142f682bc23d4de3a68551d", myCheckoutDir, myBuild, false);
    assertFalse(shallowMarker.exists());
}
Also used : VcsRootImpl(jetbrains.buildServer.vcs.impl.VcsRootImpl) CheckoutRules(jetbrains.buildServer.vcs.CheckoutRules) GitTestUtil.dataFile(jetbrains.buildServer.buildTriggers.vcs.git.tests.GitTestUtil.dataFile) File(java.io.File) TestFor(jetbrains.buildServer.util.TestFor)

Aggregations

VcsRootImpl (jetbrains.buildServer.vcs.impl.VcsRootImpl)51 File (java.io.File)35 GitTestUtil.dataFile (jetbrains.buildServer.buildTriggers.vcs.git.tests.GitTestUtil.dataFile)34 TestFor (jetbrains.buildServer.util.TestFor)26 Test (org.testng.annotations.Test)25 VcsException (jetbrains.buildServer.vcs.VcsException)10 FileUtil.writeFile (jetbrains.buildServer.util.FileUtil.writeFile)9 LockFile (org.eclipse.jgit.internal.storage.file.LockFile)9 StoredConfig (org.eclipse.jgit.lib.StoredConfig)7 BeforeMethod (org.testng.annotations.BeforeMethod)7 Method (java.lang.reflect.Method)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 AgentRunningBuild (jetbrains.buildServer.agent.AgentRunningBuild)6 AfterMethod (org.testng.annotations.AfterMethod)6 CheckoutRules (jetbrains.buildServer.vcs.CheckoutRules)5 NotNull (org.jetbrains.annotations.NotNull)5 JSchException (com.jcraft.jsch.JSchException)4 Repository (org.eclipse.jgit.lib.Repository)4 ServerPaths (jetbrains.buildServer.serverSide.ServerPaths)3 VcsRootSshKeyManager (jetbrains.buildServer.ssh.VcsRootSshKeyManager)3