Search in sources :

Example 26 with VcsRootImpl

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

the class GitVcsSupportTest method getFetchExceptionMessage.

private String getFetchExceptionMessage() {
    String result = null;
    File notExisting = new File(myTmpDir, "not-existing");
    VcsRootImpl root = new VcsRootImpl(1, Constants.VCS_NAME);
    root.addProperty(Constants.FETCH_URL, GitUtils.toURL(notExisting));
    try {
        getSupport().getContentProvider().getContent("some/path", root, MERGE_VERSION);
        fail("Should throw an exception for not-existing repository");
    } catch (VcsException e) {
        result = e.getMessage();
    }
    return result;
}
Also used : VcsRootImpl(jetbrains.buildServer.vcs.impl.VcsRootImpl) GitTestUtil.dataFile(jetbrains.buildServer.buildTriggers.vcs.git.tests.GitTestUtil.dataFile) FileUtil.writeFile(jetbrains.buildServer.util.FileUtil.writeFile) File(java.io.File) LockFile(org.eclipse.jgit.internal.storage.file.LockFile)

Example 27 with VcsRootImpl

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

the class GitVcsSupportTest method gc_disabled_by_user.

@Test
public void gc_disabled_by_user() throws Exception {
    final File repo = createTempDir();
    ZipUtil.extract(new File(getTestDataPath(), "TW-65641-1.zip"), repo, null);
    final GitVcsSupport support = getSupport();
    final VcsRootImpl root = getRoot("master", false, repo);
    final OperationContext context = support.createContext(root, "fetch");
    final GitVcsRoot gitRoot = context.getGitRoot();
    final File mirror = gitRoot.getRepositoryDir();
    ZipUtil.extract(new File(getTestDataPath(), "TW-65641.zip"), mirror, null);
    // make sure old pack files won't be kept
    final StoredConfig config = context.getRepository().getConfig();
    config.setString("gc", null, "prunepackexpire", "now");
    // disable gc externally
    config.setInt("gc", null, "auto", 0);
    config.save();
    final File gitObjects = new File(mirror + "/objects");
    Assert.assertTrue(gitObjects.isDirectory());
    final HashSet<String> before = listObjectsRecursively(mirror);
    support.collectChanges(root, "2faa6375bf6139923245a625a47bef046e5e6550", "ba04d81036c5953d17469f532e520fc1ecbcd3f1", CheckoutRules.DEFAULT);
    // enough time for auto gc to start
    Thread.sleep(5000);
    new WaitFor() {

        @Override
        protected boolean condition() {
            return !new File(mirror, "gc.log.lock").isFile();
        }
    };
    final HashSet<String> after = listObjectsRecursively(mirror);
    Assert.assertTrue(after.containsAll(before));
}
Also used : StoredConfig(org.eclipse.jgit.lib.StoredConfig) VcsRootImpl(jetbrains.buildServer.vcs.impl.VcsRootImpl) WaitFor(jetbrains.buildServer.util.WaitFor) GitTestUtil.dataFile(jetbrains.buildServer.buildTriggers.vcs.git.tests.GitTestUtil.dataFile) FileUtil.writeFile(jetbrains.buildServer.util.FileUtil.writeFile) File(java.io.File) LockFile(org.eclipse.jgit.internal.storage.file.LockFile) Test(org.testng.annotations.Test)

Example 28 with VcsRootImpl

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

the class GitVcsSupportTest method collecting_changes_should_not_block_IDE_requests.

// @Test
public void collecting_changes_should_not_block_IDE_requests() throws Exception {
    String classpath = myConfigBuilder.build().getFetchClasspath() + File.pathSeparator + ClasspathUtil.composeClasspath(new Class[] { MockFetcher.class }, null, null);
    myConfigBuilder.setSeparateProcessForFetch(true).setFetchClasspath(classpath).setFetcherClassName(MockFetcher.class.getName());
    final GitVcsSupport support = getSupport();
    final VcsRootImpl root = (VcsRootImpl) getRoot("master");
    final File customRootDir = new File(myTmpDir, "custom-dir");
    root.addProperty(Constants.PATH, customRootDir.getAbsolutePath());
    final String repositoryUrl = root.getProperty(Constants.FETCH_URL);
    final AtomicInteger succeedIDERequestCount = new AtomicInteger(0);
    final AtomicBoolean fetchBlocksIDERequests = new AtomicBoolean(false);
    final List<Exception> errors = Collections.synchronizedList(new ArrayList<Exception>());
    Runnable longFetch = new Runnable() {

        public void run() {
            try {
                support.collectChanges(root, VERSION_TEST_HEAD, MERGE_VERSION, new CheckoutRules(""));
                fetchBlocksIDERequests.set(succeedIDERequestCount.get() == 0);
            } catch (VcsException e) {
                errors.add(e);
            }
        }
    };
    Runnable requestsFromIDE = new Runnable() {

        public void run() {
            while (!new File(customRootDir, "mock.lock").exists()) {
                // wait for fetch to begin (MockFetcher holds a lock during fetch)
                try {
                    Thread.sleep(50);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            LockFile lock = new LockFile(new File(customRootDir.getAbsolutePath(), "mock"));
            try {
                while (true) {
                    // do mapFullPath while fetch is executed (we cannot acquire a lock while it is executed)
                    if (!lock.lock()) {
                        support.mapFullPath(new VcsRootEntry(root, new CheckoutRules("")), GitUtils.versionRevision(VERSION_TEST_HEAD) + "|" + repositoryUrl + "|readme.txt");
                        succeedIDERequestCount.incrementAndGet();
                    } else {
                        lock.unlock();
                        break;
                    }
                }
            } catch (Exception e) {
                errors.add(e);
            }
        }
    };
    Thread fetch = new Thread(longFetch);
    Thread ideRequests = new Thread(requestsFromIDE);
    fetch.start();
    ideRequests.start();
    fetch.join();
    ideRequests.join();
    if (!errors.isEmpty()) {
        fail("Errors in readers thread", errors.get(0));
    }
    assertFalse(fetchBlocksIDERequests.get());
}
Also used : LockFile(org.eclipse.jgit.internal.storage.file.LockFile) MissingSubmoduleCommitException(jetbrains.buildServer.buildTriggers.vcs.git.submodules.MissingSubmoduleCommitException) JSchException(com.jcraft.jsch.JSchException) NotSupportedException(org.eclipse.jgit.errors.NotSupportedException) MissingSubmoduleConfigException(jetbrains.buildServer.buildTriggers.vcs.git.submodules.MissingSubmoduleConfigException) TransportException(org.eclipse.jgit.errors.TransportException) MissingSubmoduleEntryException(jetbrains.buildServer.buildTriggers.vcs.git.submodules.MissingSubmoduleEntryException) IOException(java.io.IOException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) VcsRootImpl(jetbrains.buildServer.vcs.impl.VcsRootImpl) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GitTestUtil.dataFile(jetbrains.buildServer.buildTriggers.vcs.git.tests.GitTestUtil.dataFile) FileUtil.writeFile(jetbrains.buildServer.util.FileUtil.writeFile) File(java.io.File) LockFile(org.eclipse.jgit.internal.storage.file.LockFile)

Example 29 with VcsRootImpl

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

the class GitVcsSupportTest method should_create_teamcity_config_in_root_with_custom_path.

/*
   * Repository cloned by hand could have no teamcity.remote config, we should create it otherwise we can see 'null' as remote url in error messages
   * (see log in the issue for details).
   */
@TestFor(issues = "TW-15564")
@Test(dataProvider = "doFetchInSeparateProcess", dataProviderClass = FetchOptionsDataProvider.class)
public void should_create_teamcity_config_in_root_with_custom_path(boolean fetchInSeparateProcess) throws IOException, VcsException {
    setInternalProperty(Constants.CUSTOM_CLONE_PATH_ENABLED, "true");
    System.setProperty("teamcity.git.fetch.separate.process", String.valueOf(fetchInSeparateProcess));
    File customRootDir = new File(myTmpDir, "custom-dir");
    VcsRootImpl root = (VcsRootImpl) getRoot("master");
    root.addProperty(Constants.PATH, customRootDir.getAbsolutePath());
    getSupport().getCurrentState(root);
    File configFile = new File(customRootDir, "config");
    String config = FileUtil.readText(configFile);
    Pattern pattern = Pattern.compile("(.*)\\[teamcity\\]\\s+remote = " + Pattern.quote(GitUtils.toURL(myMainRepositoryDir)) + "\\s*(.*)", Pattern.DOTALL);
    Matcher matcher = pattern.matcher(config);
    assertTrue(matcher.matches(), "config is " + config);
    // erase teamcity.remote config
    String newConfig = matcher.group(1) + matcher.group(2);
    writeFile(configFile, newConfig);
    getSupport().getCurrentState(root);
    config = FileUtil.readText(configFile);
    assertTrue(pattern.matcher(config).matches());
}
Also used : Pattern(java.util.regex.Pattern) VcsRootImpl(jetbrains.buildServer.vcs.impl.VcsRootImpl) Matcher(java.util.regex.Matcher) GitTestUtil.dataFile(jetbrains.buildServer.buildTriggers.vcs.git.tests.GitTestUtil.dataFile) FileUtil.writeFile(jetbrains.buildServer.util.FileUtil.writeFile) File(java.io.File) LockFile(org.eclipse.jgit.internal.storage.file.LockFile) Test(org.testng.annotations.Test) TestFor(jetbrains.buildServer.util.TestFor)

Example 30 with VcsRootImpl

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

the class HttpAuthTest method quote_in_password.

@TestFor(issues = "TW-51968")
public void quote_in_password(@NotNull GitExec git) throws Exception {
    File repo = copyRepository(myTempFiles, dataFile("repo_for_fetch.1"), "repo.git");
    final String user = "user";
    final String password = "pass'word";
    myServer = new GitHttpServer(git.getPath(), repo);
    myServer.setCredentials(user, password);
    myServer.start();
    VcsRootImpl root = vcsRoot().withFetchUrl(myServer.getRepoUrl()).withAuthMethod(AuthenticationMethod.PASSWORD).withUsername(user).withPassword(password).withBranch("master").build();
    File buildDir = myTempFiles.createTempDir();
    AgentRunningBuild build = runningBuild().sharedEnvVariable(Constants.TEAMCITY_AGENT_GIT_PATH, git.getPath()).withAgentConfiguration(myAgentConfiguration).addRoot(root).withCheckoutDir(buildDir).build();
    Checkout checkout = new Checkout(root, "add81050184d3c818560bdd8839f50024c188586", buildDir, build);
    checkout.run(TimeUnit.SECONDS.toMillis(10));
    assertTrue(checkout.success());
}
Also used : AgentRunningBuild(jetbrains.buildServer.agent.AgentRunningBuild) VcsRootImpl(jetbrains.buildServer.vcs.impl.VcsRootImpl) GitTestUtil.dataFile(jetbrains.buildServer.buildTriggers.vcs.git.tests.GitTestUtil.dataFile) File(java.io.File) TestFor(jetbrains.buildServer.util.TestFor)

Aggregations

VcsRootImpl (jetbrains.buildServer.vcs.impl.VcsRootImpl)51 File (java.io.File)35 GitTestUtil.dataFile (jetbrains.buildServer.buildTriggers.vcs.git.tests.GitTestUtil.dataFile)34 TestFor (jetbrains.buildServer.util.TestFor)26 Test (org.testng.annotations.Test)25 VcsException (jetbrains.buildServer.vcs.VcsException)10 FileUtil.writeFile (jetbrains.buildServer.util.FileUtil.writeFile)9 LockFile (org.eclipse.jgit.internal.storage.file.LockFile)9 StoredConfig (org.eclipse.jgit.lib.StoredConfig)7 BeforeMethod (org.testng.annotations.BeforeMethod)7 Method (java.lang.reflect.Method)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 AgentRunningBuild (jetbrains.buildServer.agent.AgentRunningBuild)6 AfterMethod (org.testng.annotations.AfterMethod)6 CheckoutRules (jetbrains.buildServer.vcs.CheckoutRules)5 NotNull (org.jetbrains.annotations.NotNull)5 JSchException (com.jcraft.jsch.JSchException)4 Repository (org.eclipse.jgit.lib.Repository)4 ServerPaths (jetbrains.buildServer.serverSide.ServerPaths)3 VcsRootSshKeyManager (jetbrains.buildServer.ssh.VcsRootSshKeyManager)3