Search in sources :

Example 66 with CheckoutRules

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

the class AgentVcsSupportTest method shallow_fetch.

@Test
public void shallow_fetch() 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 && "+fd1eb9776b5fad5cc433586f7933811c6853917d: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(""), "fd1eb9776b5fad5cc433586f7933811c6853917d", 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("fd1eb9776b5fad5cc433586f7933811c6853917d", main.getObjectId().getName());
    assertNotNull(checkout.getRefDatabase().findRef("refs/remotes/origin/main"));
    assertNotNull(checkout.getRefDatabase().findRef("refs/tags/tag1"));
    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)

Example 67 with CheckoutRules

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

the class AgentVcsSupportTest method switch_from_alternates_to_shallow_clone.

@TestFor(issues = "TW-70493")
@Test
public void switch_from_alternates_to_shallow_clone() throws Exception {
    final File remote = dataFile("repo_for_shallow_fetch.git");
    final File testFile = new File(myCheckoutDir, "test_file");
    final File shallowMarker = new File(myCheckoutDir, ".git/shallow");
    final AgentRunningBuild build1 = createRunningBuild(CollectionsUtil.asMap(PluginConfigImpl.USE_ALTERNATES, "true"));
    myVcsSupport.updateSources(createRoot(remote, "refs/heads/main"), new CheckoutRules(""), "64195c330d99c467a142f682bc23d4de3a68551d", myCheckoutDir, build1, false);
    assertFalse(shallowMarker.exists());
    FileUtil.writeFile(testFile, "test text", StandardCharsets.UTF_8);
    assertTrue(testFile.isFile());
    final AgentRunningBuild build2 = createRunningBuild(CollectionsUtil.asMap(PluginConfigImpl.USE_SHALLOW_CLONE_INTERNAL, "true"));
    myVcsSupport.updateSources(createRoot(remote, "refs/heads/main"), new CheckoutRules(""), "fd1eb9776b5fad5cc433586f7933811c6853917d", myCheckoutDir, build2, false);
    assertTrue(shallowMarker.isFile());
    assertFalse(testFile.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) TestFor(jetbrains.buildServer.util.TestFor)

Example 68 with CheckoutRules

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

the class AutoCheckoutTest method should_respect_root_settings_when_checking_multi_root_constraints.

@TestFor(issues = "TW-49786")
public void should_respect_root_settings_when_checking_multi_root_constraints() throws Exception {
    myVcsSupport = vcsSupportWithRealGit();
    // second root has broken git path, we should not take it into account
    // during canCheckout() for the first VCS root
    VcsRoot root1 = vcsRoot().withId(1).withAgentGitPath(getGitPath()).withFetchUrl("http://some.org/repo1.git").build();
    VcsRoot root2 = vcsRoot().withId(2).withAgentGitPath("wrongGitPath").withFetchUrl("http://some.org/repo2.git").build();
    AgentRunningBuild build = runningBuild().addRootEntry(root1, "+:dir1").addRootEntry(root2, "+:dir2").build();
    AgentCheckoutAbility canCheckout1 = myVcsSupport.canCheckout(root1, new CheckoutRules("+:dir1"), build);
    AgentCheckoutAbility canCheckout2 = myVcsSupport.canCheckout(root2, new CheckoutRules("+:dir2"), build);
    then(canCheckout1.getCanNotCheckoutReason()).isNull();
    then(canCheckout2.getCanNotCheckoutReason().getType()).isEqualTo(AgentCanNotCheckoutReason.NO_VCS_CLIENT);
    then(canCheckout2.getCanNotCheckoutReason().getDetails()).contains("Unable to run git at path wrongGitPath");
}
Also used : AgentRunningBuild(jetbrains.buildServer.agent.AgentRunningBuild) AgentCheckoutAbility(jetbrains.buildServer.agent.vcs.AgentCheckoutAbility) CheckoutRules(jetbrains.buildServer.vcs.CheckoutRules) VcsRoot(jetbrains.buildServer.vcs.VcsRoot) TestFor(jetbrains.buildServer.util.TestFor)

Example 69 with CheckoutRules

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

the class AutoCheckoutTest method include_rule_with_mapping_is_used_without_sparse_checkout.

public void include_rule_with_mapping_is_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, "+:a/b/c => d").build();
    AgentCheckoutAbility canCheckout = myVcsSupport.canCheckout(vcsRoot, new CheckoutRules("+:a/b/c => d"), build);
    then(canCheckout.getCanNotCheckoutReason().getType()).isEqualTo(AgentCanNotCheckoutReason.NOT_SUPPORTED_CHECKOUT_RULES);
    then(canCheckout.getCanNotCheckoutReason().getDetails()).contains("Unsupported rules for agent-side checkout: +:a/b/c => d");
}
Also used : AgentRunningBuild(jetbrains.buildServer.agent.AgentRunningBuild) AgentCheckoutAbility(jetbrains.buildServer.agent.vcs.AgentCheckoutAbility) CheckoutRules(jetbrains.buildServer.vcs.CheckoutRules) VcsRoot(jetbrains.buildServer.vcs.VcsRoot)

Example 70 with CheckoutRules

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

the class AgentSideSparseCheckoutTest method update_files_after_switching_to_default_rules.

public void update_files_after_switching_to_default_rules() throws Exception {
    String version = "465ad9f630e451b9f2b782ffb09804c6a98c4bb9";
    AgentRunningBuild build = runningBuild().sharedConfigParams(PluginConfigImpl.USE_SPARSE_CHECKOUT, "true").withAgentConfiguration(myAgentConfiguration).build();
    CheckoutRules rules = new CheckoutRules("+:dir");
    myVcsSupport.updateSources(myRoot, rules, version, myCheckoutDir, build, false);
    then(myCheckoutDir.list()).contains("dir").doesNotContain("readme.txt");
    rules = CheckoutRules.DEFAULT;
    myVcsSupport.updateSources(myRoot, rules, version, myCheckoutDir, build, false);
    then(myCheckoutDir.list()).contains("dir", "readme.txt");
}
Also used : AgentRunningBuild(jetbrains.buildServer.agent.AgentRunningBuild) CheckoutRules(jetbrains.buildServer.vcs.CheckoutRules)

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