Search in sources :

Example 26 with VcsException

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

the class CleanCommandImpl method handleLongFileNames.

private void handleLongFileNames(@NotNull File rootDir, @NotNull VcsException originalError) throws VcsException {
    List<String> files = new ArrayList<String>();
    FileUtil.listFilesRecursively(rootDir, "", true, Integer.MAX_VALUE, new Predicate<File>() {

        public boolean apply(File f) {
            return true;
        }
    }, files);
    int targetDirLength = rootDir.getAbsolutePath().length();
    List<String> longFileNames = new ArrayList<String>();
    for (String f : files) {
        if (targetDirLength + 1 + f.length() >= 256)
            longFileNames.add(f);
    }
    if (longFileNames.isEmpty()) {
        Loggers.VCS.info("No files with long names found");
        throw originalError;
    } else {
        Loggers.VCS.info(longFileNames.size() + " files with long names found:");
        for (String f : longFileNames) {
            Loggers.VCS.info(f);
        }
        Loggers.VCS.info("Try removing files with long names manually");
    }
    Repository repository = null;
    try {
        repository = new RepositoryBuilder().setWorkTree(rootDir).build();
        WorkingDirStatus status = getWorkingDirStatus(repository);
        Set<String> untracked = status.getUntracked();
        for (String f : longFileNames) {
            if (untracked.contains(f) || status.isIgnored(f)) {
                FileUtil.delete(new File(rootDir, f));
                Loggers.VCS.info(f + " is removed");
            } else {
                Loggers.VCS.info("The file " + f + " is tracked, don't remove it");
            }
        }
    } catch (Exception e1) {
        Loggers.VCS.error("Error while cleaning files with long names", e1);
    } finally {
        if (repository != null)
            repository.close();
    }
}
Also used : Repository(org.eclipse.jgit.lib.Repository) RepositoryBuilder(org.eclipse.jgit.lib.RepositoryBuilder) ArrayList(java.util.ArrayList) File(java.io.File) IOException(java.io.IOException) JGitInternalException(org.eclipse.jgit.api.errors.JGitInternalException) VcsException(jetbrains.buildServer.vcs.VcsException)

Example 27 with VcsException

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

the class UpdaterWithAlternates method setupAlternates.

private void setupAlternates(@NotNull File gitDir, @NotNull File mirrorDir) throws VcsException {
    if (!gitDir.exists())
        throw new IllegalStateException(gitDir.getAbsolutePath() + " doesn't exist");
    File objectsInfo = new File(new File(gitDir, "objects"), "info");
    objectsInfo.mkdirs();
    File alternates = new File(objectsInfo, "alternates");
    try {
        FileUtil.writeFileAndReportErrors(alternates, getAlternatePath(gitDir, mirrorDir));
        copyRefs(gitDir, mirrorDir);
    } catch (IOException e) {
        LOG.warn("Error while configuring alternates at " + alternates.getAbsoluteFile(), e);
        throw new VcsException(e);
    }
}
Also used : VcsException(jetbrains.buildServer.vcs.VcsException) IOException(java.io.IOException) File(java.io.File)

Example 28 with VcsException

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

the class TestConnectionTest method testConnection_should_validate_branchSpec.

public void testConnection_should_validate_branchSpec() throws Exception {
    VcsRootImpl root = vcsRoot().withFetchUrl(getRemoteRepositoryUrl("repo.git")).withBranch("master").withBranchSpec("+:/refs/heads/*").build();
    try {
        myGit.testConnection(root);
        fail("Test connection should validate branchSpec");
    } catch (VcsException e) {
        assertTrue(e.getMessage().contains("pattern should not start with /"));
    }
}
Also used : VcsRootImpl(jetbrains.buildServer.vcs.impl.VcsRootImpl) VcsException(jetbrains.buildServer.vcs.VcsException)

Example 29 with VcsException

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

the class TestConnectionTest method testConnection_should_throw_exception_for_anonymous_git_url_with_username.

public void testConnection_should_throw_exception_for_anonymous_git_url_with_username() throws Exception {
    ServerPluginConfig config = pluginConfig().withDotBuildServerDir(myTempFiles.createTempDir()).setIdleTimeoutSeconds(2).setFetchTimeout(2).setCurrentStateTimeoutSeconds(2).build();
    myGit = gitSupport().withServerPaths(myPaths).withPluginConfig(config).build();
    String url = "git://git@some.org/repository";
    VcsRootImpl root = vcsRoot().withFetchUrl(url).build();
    try {
        myGit.testConnection(root);
        fail("should fail, because native git fails for such url");
    } catch (VcsException e) {
        assertTrue(e.getMessage().contains("Incorrect url " + url + ": anonymous git url should not contain a username"));
    }
    // that means old roots that have such urls and use server-side checkout will still work
    try {
        myGit.collectChanges(root, "f3f826ce85d6dad25156b2d7550cedeb1a422f4c", "ce6044093939bb47283439d97a1c80f759669ff5", CheckoutRules.DEFAULT);
        fail("should fail, because no such root exists");
    } catch (VcsException e) {
        assertFalse(e.getMessage().contains("Incorrect url " + url + ": anonymous git url should not contain a username"));
    }
}
Also used : VcsRootImpl(jetbrains.buildServer.vcs.impl.VcsRootImpl) VcsException(jetbrains.buildServer.vcs.VcsException)

Example 30 with VcsException

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

the class SubmoduleErrorsTest method cannot_fetch_submodule.

public void cannot_fetch_submodule() throws Exception {
    String submodulePath = "sub";
    String wrongSubmoduleUrl = new File(myMainRepo.getParent(), "sub2").getCanonicalPath();
    String brokenCommit = "9c328ea69b41ad2bfa162c72fd52cf87376225b7";
    VcsRoot root = vcsRoot().withFetchUrl(myMainRepoUrl).withSubmodulePolicy(SubmodulesCheckoutPolicy.CHECKOUT).build();
    try {
        myGitSupport.collectChanges(root, "6dbc05799659295e480894e367f4159d57fba30d", brokenCommit, CheckoutRules.DEFAULT);
        fail("Should fail due to incorrect submodule url");
    } catch (VcsException e) {
        String msg = e.getMessage();
        assertTrue(msg.contains("Cannot fetch the '" + wrongSubmoduleUrl + "' repository used as a submodule at the '" + submodulePath + "' path in the '" + myMainRepoUrl + "' repository in the " + brokenCommit + " commit"));
    }
}
Also used : VcsException(jetbrains.buildServer.vcs.VcsException) VcsRoot(jetbrains.buildServer.vcs.VcsRoot) GitTestUtil.dataFile(jetbrains.buildServer.buildTriggers.vcs.git.tests.GitTestUtil.dataFile) File(java.io.File)

Aggregations

VcsException (jetbrains.buildServer.vcs.VcsException)79 File (java.io.File)34 NotNull (org.jetbrains.annotations.NotNull)22 GitTestUtil.dataFile (jetbrains.buildServer.buildTriggers.vcs.git.tests.GitTestUtil.dataFile)13 IOException (java.io.IOException)12 TestFor (jetbrains.buildServer.util.TestFor)11 GeneralCommandLine (com.intellij.execution.configurations.GeneralCommandLine)10 Method (java.lang.reflect.Method)10 ExecResult (jetbrains.buildServer.ExecResult)10 VcsRootImpl (jetbrains.buildServer.vcs.impl.VcsRootImpl)10 AfterMethod (org.testng.annotations.AfterMethod)10 BeforeMethod (org.testng.annotations.BeforeMethod)10 VcsRoot (jetbrains.buildServer.vcs.VcsRoot)9 Repository (org.eclipse.jgit.lib.Repository)9 URIish (org.eclipse.jgit.transport.URIish)9 Nullable (org.jetbrains.annotations.Nullable)8 SimpleCommandLineProcessRunner (jetbrains.buildServer.SimpleCommandLineProcessRunner)5 GitExec (jetbrains.buildServer.buildTriggers.vcs.git.command.GitExec)5 CheckoutRules (jetbrains.buildServer.vcs.CheckoutRules)5 RefSpec (org.eclipse.jgit.transport.RefSpec)5