Search in sources :

Example 51 with CheckoutRules

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

the class AgentVcsSupportTest method doTestSubSubmoduleCheckout.

private void doTestSubSubmoduleCheckout(boolean recursiveSubmoduleCheckout, boolean useMirrors, boolean useMirrorsForSubmodules, boolean useAlternates) throws Exception {
    myRoot.addProperty(Constants.BRANCH_NAME, "sub-submodule");
    if (recursiveSubmoduleCheckout) {
        myRoot.addProperty(Constants.SUBMODULES_CHECKOUT, SubmodulesCheckoutPolicy.CHECKOUT.name());
    } else {
        myRoot.addProperty(Constants.SUBMODULES_CHECKOUT, SubmodulesCheckoutPolicy.NON_RECURSIVE_CHECKOUT.name());
    }
    final AgentRunningBuild build = createRunningBuild(new HashMap<String, String>() {

        {
            put(PluginConfigImpl.USE_MIRRORS_FOR_SUBMODULES, useMirrorsForSubmodules ? "true" : "false");
            put(PluginConfigImpl.USE_ALTERNATES, useAlternates ? "true" : "false");
            put(PluginConfigImpl.USE_MIRRORS, useMirrors ? "true" : "false");
        }
    });
    myVcsSupport.updateSources(myRoot, new CheckoutRules(""), GitVcsSupportTest.AFTER_FIRST_LEVEL_SUBMODULE_ADDED_VERSION, myCheckoutDir, build, false);
    assertTrue(new File(myCheckoutDir, "first-level-submodule" + File.separator + "submoduleFile.txt").exists());
    if (recursiveSubmoduleCheckout) {
        assertTrue(new File(myCheckoutDir, "first-level-submodule" + File.separator + "sub-sub" + File.separator + "file.txt").exists());
        assertTrue(new File(myCheckoutDir, "first-level-submodule" + File.separator + "sub-sub" + File.separator + "new file.txt").exists());
    } else {
        assertFalse(new File(myCheckoutDir, "first-level-submodule" + File.separator + "sub-sub" + File.separator + "file.txt").exists());
        assertFalse(new File(myCheckoutDir, "first-level-submodule" + File.separator + "sub-sub" + File.separator + "new 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 52 with CheckoutRules

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

the class AgentVcsSupportTest method clean_files_with_checkout_rules_target_path.

@TestFor(issues = "TW-66105")
public void clean_files_with_checkout_rules_target_path() throws Exception {
    final List<String> excludes = collectExcludes();
    final AgentRunningBuild build = runningBuild().withAgentConfiguration(myBuilder.getAgentConfiguration()).addRootEntry(vcsRoot().withId(2).withFetchUrl("/some/path").build(), ".=>target/path/d1").addRootEntry(vcsRoot().withId(3).withFetchUrl("/some/path").build(), ".=>target/path/d2/d3").addRootEntry(vcsRoot().withId(4).withFetchUrl("/some/path").build(), ".=>target/path/d4").addRootEntry(vcsRoot().withId(5).withFetchUrl("/some/path").build(), ".=>target/path/d4/d5").addRootEntry(vcsRoot().withId(6).withFetchUrl("/some/path").build(), ".=>target/path/d6\nsome/dir=>target/path/d6/another/dir").addRootEntry(vcsRoot().withId(8).withFetchUrl("/some/path").build(), ".=>target/path/path with space/d7").build();
    final List<File> toPreserve = Arrays.asList(createFile("target/path/d1/f"), createFile("target/path/d1/some/dir/f"), createFile("target/path/d2/d3/f"), createFile("target/path/d2/d3/some/dir/f"), createFile("target/path/d4/f"), createFile("target/path/d4/some/dir/f"), createFile("target/path/d4/d5/f"), createFile("target/path/d4/d5/some/dir/f"), createFile("target/path/d6/f"), createFile("target/path/d6/some/dir/f"), createFile("target/path/d6/another/dir/f"), createFile("target/path/d6/another/dir/some/dir/f"), createFile("target/path/path with space/d7/f"), createFile("target/path/path with space/d7/some/dir/f"), createFile("another/path/f"));
    final List<File> toClean = Arrays.asList(createFile("target/path/d2/f"), createFile("target/path/d2/some/dir/f"), createFile("target/path/d8/f"), createFile("target/path/d8/some/dir/f"), createFile("target/path/path with space/f"), createFile("target/path/path with space/some/dir/f"), createFile("target/path/some/dir/d1/f"), createFile("target/path/some/dir/d4"));
    toPreserve.forEach(f -> assertTrue(f.isFile()));
    toClean.forEach(f -> assertTrue(f.isFile()));
    myVcsSupport.updateSources(myRoot, new CheckoutRules(".=>target/path"), "7574b5358ac09d61ec5cb792d4462230de1d00c2", myCheckoutDir, build, false);
    Assertions.assertThat(excludes).containsExactly("/d1", "/d2/d3", "/d4", "/d4/d5", "/d6", "/path with space/d7");
    toPreserve.forEach(f -> assertTrue(f + " must be preserved", f.isFile()));
    toClean.forEach(f -> assertFalse(f + " must be removed", f.exists()));
    assertTrue(new File(myCheckoutDir, "target/path/Folder1").isDirectory());
    assertTrue(new File(myCheckoutDir, "target/path/Folder2").isDirectory());
}
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 53 with CheckoutRules

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

the class AgentVcsSupportTest method testRecoverRefLock.

/**
 * Test work normally if .git/refs/heads/<branch>.lock file exists
 */
public void testRecoverRefLock() throws Exception {
    myVcsSupport.updateSources(myRoot, new CheckoutRules(""), GitVcsSupportTest.VERSION_TEST_HEAD, myCheckoutDir, myBuild, false);
    String firstCommitInPatchTests = GitUtils.makeVersion("a894d7d58ffde625019a9ecf8267f5f1d1e5c341", 1245766034000L);
    myRoot.addProperty(Constants.BRANCH_NAME, "patch-tests");
    myVcsSupport.updateSources(myRoot, new CheckoutRules(""), firstCommitInPatchTests, myCheckoutDir, myBuild, false);
    myRoot.addProperty(Constants.BRANCH_NAME, "master");
    myVcsSupport.updateSources(myRoot, new CheckoutRules(""), GitVcsSupportTest.VERSION_TEST_HEAD, myCheckoutDir, myBuild, false);
    // emulate incorrect git termination (in this it could leave refs/heads/<branch-name>.lock file)
    FileUtil.createIfDoesntExist(new File(myCheckoutDir, ".git" + File.separator + GitUtils.expandRef("master") + ".lock"));
    // should recover from locked ref if previous checkout was on the same branch:
    myRoot.addProperty(Constants.BRANCH_NAME, "master");
    myVcsSupport.updateSources(myRoot, new CheckoutRules(""), firstCommitInPatchTests, myCheckoutDir, myBuild, false);
    // emulate incorrect git termination (in this it could leave refs/heads/<branch-name>.lock file)
    FileUtil.createIfDoesntExist(new File(myCheckoutDir, ".git" + File.separator + GitUtils.expandRef("patch-tests") + ".lock"));
    // should recover from locked ref if previous checkout was on a different branch:
    myRoot.addProperty(Constants.BRANCH_NAME, "patch-tests");
    myVcsSupport.updateSources(myRoot, new CheckoutRules(""), firstCommitInPatchTests, myCheckoutDir, myBuild, false);
}
Also used : CheckoutRules(jetbrains.buildServer.vcs.CheckoutRules) GitTestUtil.dataFile(jetbrains.buildServer.buildTriggers.vcs.git.tests.GitTestUtil.dataFile) File(java.io.File)

Example 54 with CheckoutRules

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

the class AgentVcsSupportTest method shallow_fetch_tag_with_older_revision.

@Test
public void shallow_fetch_tag_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".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(""), "a1d6299597f8d6f6d8316577c46cc8fffd657d5e", myCheckoutDir, build, false);
    assertEquals(1, loggingFactory.getNumberOfCalls(FetchCommand.class));
    final Repository checkout = new RepositoryBuilder().setWorkTree(myCheckoutDir).build();
    assertEquals("a1d6299597f8d6f6d8316577c46cc8fffd657d5e", checkout.getBranch());
    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 55 with CheckoutRules

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

the class AgentVcsSupportTest method should_checkout_tags_reachable_from_branch.

public void should_checkout_tags_reachable_from_branch() throws Exception {
    myVcsSupport.updateSources(myRoot, new CheckoutRules(""), GitVcsSupportTest.VERSION_TEST_HEAD, myCheckoutDir, myBuild, false);
    assertTagExists("refs/tags/v0.5");
    assertTagExists("refs/tags/v1.0");
}
Also used : 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