Search in sources :

Example 11 with CheckoutRules

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

the class AgentVcsSupportTest method testSubmodulesCheckoutWithCustomConfigPerLine.

@Test(dataProvider = "custom_config_per_line")
public void testSubmodulesCheckoutWithCustomConfigPerLine(@NotNull String line) throws Throwable {
    final AgentRunningBuild build = createRunningBuild(new HashMap<String, String>() {

        {
            put(PluginConfigImpl.CUSTOM_GIT_CONFIG, line);
        }
    });
    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) Test(org.testng.annotations.Test)

Example 12 with CheckoutRules

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

the class AgentVcsSupportTest method shallow_fetch_with_older_revision.

@Test
public void shallow_fetch_with_older_revision() 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 && "+a1d6299597f8d6f6d8316577c46cc8fffd657d5e:refs/remotes/origin/main".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/heads/main"), new CheckoutRules(""), "a1d6299597f8d6f6d8316577c46cc8fffd657d5e", myCheckoutDir, build, false);
    assertEquals(1, loggingFactory.getNumberOfCalls(FetchCommand.class));
    final Repository checkout = new RepositoryBuilder().setWorkTree(myCheckoutDir).build();
    assertEquals("main", checkout.getBranch());
    final Ref main = checkout.getRefDatabase().findRef("main");
    assertNotNull(main);
    assertEquals("a1d6299597f8d6f6d8316577c46cc8fffd657d5e", main.getObjectId().getName());
    assertNotNull(checkout.getRefDatabase().findRef("refs/remotes/origin/main"));
    assertNull(checkout.getRefDatabase().findRef("refs/tags/tag1"));
    assertNotNull(checkout.getRefDatabase().findRef("refs/tags/tag2"));
    assertFalse(checkout.getObjectDatabase().has(ObjectId.fromString("fd1eb9776b5fad5cc433586f7933811c6853917d")));
}
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)

Example 13 with CheckoutRules

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

the class AgentVcsSupportTest method testDumpConfig.

@Test
public void testDumpConfig() throws Exception {
    final File remote = dataFile("repo_for_shallow_fetch.git");
    final StringBuilder log = new StringBuilder();
    final AgentRunningBuild build = createRunningBuild(CollectionsUtil.asMap(PluginConfigImpl.TEAMCITY_GIT_SSH_DEBUG, "true"), new NullBuildProgressLogger() {

        @Override
        public void message(String message) {
            log.append(message);
        }
    });
    myVcsSupport.updateSources(createRoot(remote, "refs/heads/main"), new CheckoutRules(""), "64195c330d99c467a142f682bc23d4de3a68551d", myCheckoutDir, build, false);
    final String result = log.toString();
    if (SystemInfo.isWindows) {
        assertTrue(result, result.contains("git config --list") || result.contains("git.exe config --list") || result.contains("git.exe\" config --list"));
    } else {
        BaseTestCase.assertContains(result, "git config --list");
    }
}
Also used : CheckoutRules(jetbrains.buildServer.vcs.CheckoutRules) GitTestUtil.dataFile(jetbrains.buildServer.buildTriggers.vcs.git.tests.GitTestUtil.dataFile) File(java.io.File) Test(org.testng.annotations.Test)

Example 14 with CheckoutRules

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

the class AgentVcsSupportTest method do_not_create_branch_when_checkout_tag.

public void do_not_create_branch_when_checkout_tag() throws Exception {
    myRoot.addProperty(Constants.BRANCH_NAME, "refs/tags/v1.0");
    myVcsSupport.updateSources(myRoot, new CheckoutRules(""), GitVcsSupportTest.VERSION_TEST_HEAD, myCheckoutDir, myBuild, false);
    Repository r = new RepositoryBuilder().setWorkTree(myCheckoutDir).build();
    Map<String, Ref> refs = r.getRefDatabase().getRefs("refs/");
    assertTrue(refs.containsKey("tags/v1.0"));
    // it is reachable from refs/tags/v1.0
    assertTrue(refs.containsKey("tags/v0.7"));
    // also reachable
    assertTrue(refs.containsKey("tags/v0.5"));
    assertEquals(3, refs.size());
}
Also used : CheckoutRules(jetbrains.buildServer.vcs.CheckoutRules)

Example 15 with CheckoutRules

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

the class AutoCheckoutTest method exclude_rules_are_used_without_sparse_checkout.

public void exclude_rules_are_used_without_sparse_checkout() throws IOException, VcsException {
    myVcsSupport = vcsSupportWithFakeGitOfVersion(GIT_WITH_SPARSE_CHECKOUT);
    VcsRoot vcsRoot = vcsRootWithAgentGitPath();
    AgentRunningBuild build = runningBuild().sharedConfigParams(PluginConfigImpl.USE_SPARSE_CHECKOUT, "false").addRootEntry(vcsRoot, "-:dir/q.txt").build();
    AgentCheckoutAbility canCheckout = myVcsSupport.canCheckout(vcsRoot, new CheckoutRules("-:dir/q.txt"), build);
    then(canCheckout.getCanNotCheckoutReason().getType()).isEqualTo(AgentCanNotCheckoutReason.NOT_SUPPORTED_CHECKOUT_RULES);
    then(canCheckout.getCanNotCheckoutReason().getDetails()).contains("Cannot perform sparse checkout using git " + GIT_WITH_SPARSE_CHECKOUT);
}
Also used : AgentRunningBuild(jetbrains.buildServer.agent.AgentRunningBuild) AgentCheckoutAbility(jetbrains.buildServer.agent.vcs.AgentCheckoutAbility) CheckoutRules(jetbrains.buildServer.vcs.CheckoutRules) VcsRoot(jetbrains.buildServer.vcs.VcsRoot)

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