Search in sources :

Example 16 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_constraints2.

@TestFor(issues = "TW-49786")
public void should_respect_root_settings_when_checking_multi_root_constraints2() throws Exception {
    VcsRoot root1 = vcsRoot().withId(1).withFetchUrl("http://some.org/repo1.git").build();
    VcsRoot root2 = vcsRoot().withId(2).withFetchUrl("http://some.org/repo2.git").build();
    AgentRunningBuild build = runningBuild().addRootEntry(root1, "+:dir1").addRootEntry(root2, "+:dir2").build();
    // both roots require sparse checkout and mapped into the same directory, but the second
    // root uses git version which doesn't support sparse checkout; we shouldn't take it into
    // account during canCheckout() check for the first root
    GitDetector detector = new GitDetector() {

        @NotNull
        public GitExec getGitPathAndVersion(@NotNull VcsRoot root, @NotNull BuildAgentConfiguration config, @NotNull AgentRunningBuild build) throws VcsException {
            if (root.equals(root1)) {
                return new GitExec("git1", GIT_WITH_SPARSE_CHECKOUT);
            }
            if (root.equals(root2)) {
                return new GitExec("git2", GIT_WITH_SPARSE_CHECKOUT.previousVersion());
            }
            throw new VcsException("Unexpected VCS root");
        }

        @NotNull
        @Override
        public GitExec getGitPathAndVersion(@NotNull AgentRunningBuild build) throws VcsException {
            throw new UnsupportedOperationException();
        }
    };
    myVcsSupport = createVcsSupport(detector);
    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.NOT_SUPPORTED_CHECKOUT_RULES);
    then(canCheckout2.getCanNotCheckoutReason().getDetails()).contains("Cannot perform sparse checkout using git " + GIT_WITH_SPARSE_CHECKOUT.previousVersion());
}
Also used : AgentRunningBuild(jetbrains.buildServer.agent.AgentRunningBuild) AgentCheckoutAbility(jetbrains.buildServer.agent.vcs.AgentCheckoutAbility) VcsException(jetbrains.buildServer.vcs.VcsException) GitExec(jetbrains.buildServer.buildTriggers.vcs.git.command.GitExec) CheckoutRules(jetbrains.buildServer.vcs.CheckoutRules) VcsRoot(jetbrains.buildServer.vcs.VcsRoot) GitDetector(jetbrains.buildServer.buildTriggers.vcs.git.agent.GitDetector) NotNull(org.jetbrains.annotations.NotNull) BuildAgentConfiguration(jetbrains.buildServer.agent.BuildAgentConfiguration) TestFor(jetbrains.buildServer.util.TestFor)

Example 17 with CheckoutRules

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

the class AutoCheckoutTest method should_check_shared_paths_not_clashing.

public void should_check_shared_paths_not_clashing() throws Exception {
    myVcsSupport = vcsSupportWithFakeGitOfVersion(GIT_CLEAN_LEARNED_EXCLUDE);
    final VcsRoot vcsRoot = vcsRoot().withFetchUrl("/some/path").withAgentGitPath(getGitPath()).build();
    {
        final AgentRunningBuild build = runningBuild().sharedConfigParams(PluginConfigImpl.USE_SPARSE_CHECKOUT, "true").addRoot(vcsRoot).addRootEntry(new VcsRootImpl(2, "svn"), "some/path=>.").build();
        AgentCheckoutAbility canCheckout = myVcsSupport.canCheckout(vcsRoot, CheckoutRules.DEFAULT, build);
        then(canCheckout.getCanNotCheckoutReason().getDetails()).contains("Cannot checkout VCS root", "into the same directory as VCS root");
    }
    {
        final AgentRunningBuild build = runningBuild().sharedConfigParams(PluginConfigImpl.USE_SPARSE_CHECKOUT, "true").addRoot(vcsRoot).addRootEntry(new VcsRootImpl(2, "svn"), ".=>some/path").build();
        AgentCheckoutAbility canCheckout = myVcsSupport.canCheckout(vcsRoot, new CheckoutRules(".=>some/path"), build);
        then(canCheckout.getCanNotCheckoutReason().getDetails()).contains("Cannot checkout VCS root", "into the same directory as VCS root");
    }
}
Also used : AgentRunningBuild(jetbrains.buildServer.agent.AgentRunningBuild) AgentCheckoutAbility(jetbrains.buildServer.agent.vcs.AgentCheckoutAbility) VcsRootImpl(jetbrains.buildServer.vcs.impl.VcsRootImpl) CheckoutRules(jetbrains.buildServer.vcs.CheckoutRules) VcsRoot(jetbrains.buildServer.vcs.VcsRoot)

Example 18 with CheckoutRules

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

the class AgentVcsSupportTest method not_fetch_submodules.

@TestFor(issues = "TW-63901")
@Test
public void not_fetch_submodules() throws Exception {
    final File repo = new File(getTempDirectory(), "TW-63901");
    FileUtil.delete(repo);
    copyDir(dataFile("TW-63901-1"), repo);
    final File submoduleRepo = new File(getTempDirectory(), "TW-63901-submodule");
    FileUtil.delete(submoduleRepo);
    copyDir(dataFile("TW-63901-submodule"), submoduleRepo);
    final VcsRootImpl root = createRoot(repo, "master");
    root.addProperty(Constants.SUBMODULES_CHECKOUT, SubmodulesCheckoutPolicy.CHECKOUT.name());
    final AgentRunningBuild build = createRunningBuild(new HashMap<String, String>() {

        {
            put(PluginConfigImpl.USE_MIRRORS, "false");
            put(PluginConfigImpl.USE_MIRRORS_FOR_SUBMODULES, "false");
        }
    });
    myVcsSupport.updateSources(root, new CheckoutRules(""), "78fcadbf51f44cf78fce816be5e3943e4bb5f95c", myCheckoutDir, build, false);
    assertTrue(new File(myCheckoutDir, ".gitmodules").isFile());
    assertTrue(new File(myCheckoutDir, "TW-63901-submodule/f.txt").isFile());
    // patch config to fetch submodules during fetch
    final StoredConfig config = new RepositoryBuilder().setWorkTree(myCheckoutDir).build().getConfig();
    config.setBoolean("fetch", null, "recursesubmodules", true);
    config.save();
    root.addProperty(Constants.SUBMODULES_CHECKOUT, SubmodulesCheckoutPolicy.IGNORE.name());
    FileUtil.delete(repo);
    // new repo references submodule commit, which doesn't exist
    copyDir(dataFile("TW-63901-2"), repo);
    myVcsSupport.updateSources(root, new CheckoutRules(""), "565f5f32581cd1dba1305c5f5651270c33f40323", myCheckoutDir, build, false);
}
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) Test(org.testng.annotations.Test) TestFor(jetbrains.buildServer.util.TestFor)

Example 19 with CheckoutRules

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

the class AgentVcsSupportTest method should_create_bare_repository_in_caches_dir.

public void should_create_bare_repository_in_caches_dir() throws Exception {
    File mirrorsDir = myBuilder.getAgentConfiguration().getCacheDirectory("git");
    assertTrue(mirrorsDir.listFiles(new FileFilter() {

        public boolean accept(File f) {
            return f.isDirectory();
        }
    }).length == 0);
    myVcsSupport.updateSources(myRoot, new CheckoutRules(""), GitVcsSupportTest.VERSION_TEST_HEAD, myCheckoutDir, myBuild, false);
    GitVcsRoot root = new AgentGitVcsRoot(myBuilder.getMirrorManager(), myRoot, myTookenStorage);
    File bareRepositoryDir = root.getRepositoryDir();
    assertTrue(bareRepositoryDir.exists());
    // check some dirs that should be present in the bare repository:
    File objectsDir = new File(bareRepositoryDir, "objects");
    assertTrue(new File(bareRepositoryDir, "info").exists());
    assertTrue(objectsDir.exists());
    assertTrue(new File(bareRepositoryDir, "refs").exists());
    String config = FileUtil.loadTextAndClose(new FileReader(new File(bareRepositoryDir, "config")));
    assertTrue(config.contains("[remote \"origin\"]"));
    String remoteUrl = "url = " + root.getRepositoryFetchURL();
    assertTrue(config.contains(remoteUrl));
    File packDir = new File(objectsDir, "pack");
    // 2 - because there are 2 dirs there: info and pack
    boolean looseObjectsExists = objectsDir.listFiles().length > 2;
    // at least one pack file with its index exists
    boolean packFilesExists = packDir.listFiles().length >= 2;
    boolean fetchWasDone = looseObjectsExists || packFilesExists;
    assertTrue(fetchWasDone);
}
Also used : CheckoutRules(jetbrains.buildServer.vcs.CheckoutRules) FileReader(java.io.FileReader) FileFilter(java.io.FileFilter) GitTestUtil.dataFile(jetbrains.buildServer.buildTriggers.vcs.git.tests.GitTestUtil.dataFile) File(java.io.File)

Example 20 with CheckoutRules

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

the class AgentVcsSupportTest method checkout_tag.

public void 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();
    Ref tagRef = r.exactRef("refs/tags/v1.0");
    assertNotNull(tagRef);
}
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