Search in sources :

Example 61 with CheckoutRules

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

the class AgentVcsSupportTest method stop_use_any_mirror_if_agent_property_changed_to_false.

public void stop_use_any_mirror_if_agent_property_changed_to_false() throws Exception {
    AgentRunningBuild build2 = createRunningBuild(false);
    GitVcsRoot root = new AgentGitVcsRoot(myBuilder.getMirrorManager(), myRoot, myTookenStorage);
    myVcsSupport.updateSources(myRoot, new CheckoutRules(""), GitVcsSupportTest.VERSION_TEST_HEAD, myCheckoutDir, build2, false);
    // add some mirror
    Repository r = new RepositoryBuilder().setWorkTree(myCheckoutDir).build();
    StoredConfig config = r.getConfig();
    config.setString("url", "/some/path", "insteadOf", root.getRepositoryFetchURL().toString());
    config.save();
    myVcsSupport.updateSources(myRoot, new CheckoutRules(""), GitVcsSupportTest.VERSION_TEST_HEAD, myCheckoutDir, build2, false);
    config = new RepositoryBuilder().setWorkTree(myCheckoutDir).build().getConfig();
    assertTrue(config.getSubsections("url").isEmpty());
}
Also used : CheckoutRules(jetbrains.buildServer.vcs.CheckoutRules)

Example 62 with CheckoutRules

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

the class AgentVcsSupportTest method do_not_use_mirror_if_agent_property_set_to_false.

public void do_not_use_mirror_if_agent_property_set_to_false() throws Exception {
    AgentRunningBuild build2 = createRunningBuild(false);
    myVcsSupport.updateSources(myRoot, new CheckoutRules(""), GitVcsSupportTest.VERSION_TEST_HEAD, myCheckoutDir, build2, false);
    File gitConfigFile = new File(myCheckoutDir, ".git" + File.separator + "config");
    String config = FileUtil.loadTextAndClose(new FileReader(gitConfigFile));
    assertFalse(config, config.contains("insteadOf"));
}
Also used : CheckoutRules(jetbrains.buildServer.vcs.CheckoutRules) FileReader(java.io.FileReader) GitTestUtil.dataFile(jetbrains.buildServer.buildTriggers.vcs.git.tests.GitTestUtil.dataFile) File(java.io.File)

Example 63 with CheckoutRules

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

the class AgentVcsSupportTest method testSubmodulesCheckout.

/**
 * Test checkout submodules on agent. Machine that runs this test should have git installed.
 */
private void testSubmodulesCheckout(boolean useMirrorsForSubmodules, boolean useAlternates) throws Exception {
    final AgentRunningBuild build = createRunningBuild(new HashMap<String, String>() {

        {
            put(PluginConfigImpl.USE_MIRRORS, useMirrorsForSubmodules ? "true" : null);
            put(PluginConfigImpl.USE_MIRRORS_FOR_SUBMODULES, useMirrorsForSubmodules ? "true" : "false");
            put(PluginConfigImpl.USE_ALTERNATES, useAlternates ? "true" : "false");
        }
    });
    myRoot.addProperty(Constants.BRANCH_NAME, "patch-tests");
    myRoot.addProperty(Constants.SUBMODULES_CHECKOUT, SubmodulesCheckoutPolicy.CHECKOUT.name());
    myVcsSupport.updateSources(myRoot, new CheckoutRules(""), GitVcsSupportTest.SUBMODULE_ADDED_VERSION, myCheckoutDir, build, false);
    assertTrue(new File(myCheckoutDir, "submodule" + File.separator + "file.txt").exists());
}
Also used : CheckoutRules(jetbrains.buildServer.vcs.CheckoutRules) GitTestUtil.dataFile(jetbrains.buildServer.buildTriggers.vcs.git.tests.GitTestUtil.dataFile) File(java.io.File)

Example 64 with CheckoutRules

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

the class AgentVcsSupportTest method testSubmmoduleCommitReferencedByTag_alternates.

@TestFor(issues = "TW-65043")
public void testSubmmoduleCommitReferencedByTag_alternates() throws Exception {
    final AgentRunningBuild build = createRunningBuild(CollectionsUtil.asMap(PluginConfigImpl.USE_ALTERNATES, "true"));
    myRoot.addProperty(Constants.BRANCH_NAME, "TW-65043");
    myRoot.addProperty(Constants.SUBMODULES_CHECKOUT, SubmodulesCheckoutPolicy.CHECKOUT.name());
    myVcsSupport.updateSources(myRoot, new CheckoutRules(""), "4be4cc77ac427ecabf6ca53a76e33f6e186db6f2", myCheckoutDir, build, false);
    final File file = new File(myCheckoutDir, "submodule" + File.separator + "file.txt");
    assertTrue(file.exists());
    assertEquals("TW-65043", FileUtil.readText(file, "UTF-8").trim());
}
Also used : CheckoutRules(jetbrains.buildServer.vcs.CheckoutRules) GitTestUtil.dataFile(jetbrains.buildServer.buildTriggers.vcs.git.tests.GitTestUtil.dataFile) File(java.io.File) TestFor(jetbrains.buildServer.util.TestFor)

Example 65 with CheckoutRules

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

the class AgentVcsSupportTest method shallow_fetch_tag.

@Test
public void shallow_fetch_tag() throws Exception {
    final File remote = dataFile("repo_for_shallow_fetch.git");
    final LoggingGitMetaFactory loggingFactory = new LoggingGitMetaFactory();
    loggingFactory.addCallback(FetchCommand.class.getName() + ".setRefspec", new GitCommandProxyCallback() {

        @Override
        public Optional<Object> call(final Method method, final Object[] args) throws VcsException {
            if (args.length == 1 && "+refs/tags/tag1:refs/tags/tag1".equals(args[0]))
                return null;
            fail("Unexpected fetch refspec " + Arrays.toString(args));
            return null;
        }
    });
    loggingFactory.addCallback(FetchCommand.class.getName() + ".setDepth", new GitCommandProxyCallback() {

        @Override
        public Optional<Object> call(final Method method, final Object[] args) throws VcsException {
            if (args.length == 1 && Integer.valueOf(1).equals(args[0]))
                return null;
            fail("Unexpected fetch depth " + Arrays.toString(args));
            return null;
        }
    });
    myVcsSupport = myBuilder.setGitMetaFactory(loggingFactory).setFS(new MockFS()).build();
    final AgentRunningBuild build = createRunningBuild(CollectionsUtil.asMap(PluginConfigImpl.USE_SHALLOW_CLONE_INTERNAL, "true"));
    myVcsSupport.updateSources(createRoot(remote, "refs/tags/tag1"), new CheckoutRules(""), "fd1eb9776b5fad5cc433586f7933811c6853917d", myCheckoutDir, build, false);
    assertEquals(1, loggingFactory.getNumberOfCalls(FetchCommand.class));
    final Repository checkout = new RepositoryBuilder().setWorkTree(myCheckoutDir).build();
    final Ref main = checkout.getRefDatabase().findRef("refs/tags/tag1");
    assertNotNull(main);
    assertEquals("fd1eb9776b5fad5cc433586f7933811c6853917d", main.getObjectId().getName());
    assertNull(checkout.getRefDatabase().findRef("refs/tags/tag2"));
    assertFalse(checkout.getObjectDatabase().has(ObjectId.fromString("a1d6299597f8d6f6d8316577c46cc8fffd657d5e")));
}
Also used : CheckoutRules(jetbrains.buildServer.vcs.CheckoutRules) AfterMethod(org.testng.annotations.AfterMethod) Method(java.lang.reflect.Method) BeforeMethod(org.testng.annotations.BeforeMethod) FetchCommand(jetbrains.buildServer.buildTriggers.vcs.git.command.FetchCommand) VcsException(jetbrains.buildServer.vcs.VcsException) GitTestUtil.dataFile(jetbrains.buildServer.buildTriggers.vcs.git.tests.GitTestUtil.dataFile) File(java.io.File) Test(org.testng.annotations.Test)

Aggregations

CheckoutRules (jetbrains.buildServer.vcs.CheckoutRules)71 File (java.io.File)29 GitTestUtil.dataFile (jetbrains.buildServer.buildTriggers.vcs.git.tests.GitTestUtil.dataFile)29 VcsRoot (jetbrains.buildServer.vcs.VcsRoot)25 Test (org.testng.annotations.Test)23 TestFor (jetbrains.buildServer.util.TestFor)21 AgentRunningBuild (jetbrains.buildServer.agent.AgentRunningBuild)13 GitVcsSupport (jetbrains.buildServer.buildTriggers.vcs.git.GitVcsSupport)10 AgentCheckoutAbility (jetbrains.buildServer.agent.vcs.AgentCheckoutAbility)7 VcsException (jetbrains.buildServer.vcs.VcsException)6 VcsRootImpl (jetbrains.buildServer.vcs.impl.VcsRootImpl)5 FileReader (java.io.FileReader)4 Method (java.lang.reflect.Method)4 FetchCommand (jetbrains.buildServer.buildTriggers.vcs.git.command.FetchCommand)4 SVcsRoot (jetbrains.buildServer.vcs.SVcsRoot)4 BuildTypeOrTemplate (jetbrains.buildServer.server.rest.util.BuildTypeOrTemplate)3 AfterMethod (org.testng.annotations.AfterMethod)3 BeforeMethod (org.testng.annotations.BeforeMethod)3 ArrayList (java.util.ArrayList)2 BuildTriggerDescriptor (jetbrains.buildServer.buildTriggers.BuildTriggerDescriptor)2