Search in sources :

Example 51 with VcsRootImpl

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

the class AgentVcsSupportTest method should_handle_ref_pointing_to_invalid_object.

public void should_handle_ref_pointing_to_invalid_object() throws Exception {
    File repo = dataFile("repo_for_fetch.1");
    File remoteRepo = myTempFiles.createTempDir();
    copyRepository(repo, remoteRepo);
    VcsRootImpl root = vcsRoot().withAgentGitPath(getGitPath()).withFetchUrl(GitUtils.toURL(remoteRepo)).withUseMirrors(true).build();
    // first build
    AgentRunningBuild build = createRunningBuild(map(PluginConfigImpl.VCS_ROOT_MIRRORS_STRATEGY, PluginConfigImpl.VCS_ROOT_MIRRORS_STRATEGY_ALTERNATES));
    myVcsSupport.updateSources(root, CheckoutRules.DEFAULT, "add81050184d3c818560bdd8839f50024c188586", myCheckoutDir, build, false);
    // create ref pointing to invalid object
    File gitDir = new File(myCheckoutDir, ".git");
    String invalidObject = "bba7fbcc200b4968e6abd2f7d475dc15306cafc1";
    FileUtil.writeFile(new File(gitDir, "refs/heads/brokenRef"), invalidObject);
    FileUtil.writeFile(new File(gitDir, "refs/remotes/origin/brokenRef"), invalidObject);
    final File packedRefs = new File(gitDir, "packed-refs");
    FileUtil.writeToFile(packedRefs, (invalidObject + " refs/heads/anotherBrokenRef").getBytes(), true);
    FileUtil.writeToFile(packedRefs, (invalidObject + " refs/remotes/origin/anotherBrokenRef").getBytes(), true);
    // update remote repo
    delete(remoteRepo);
    File updatedRepo = dataFile("repo_for_fetch.3");
    copyRepository(updatedRepo, remoteRepo);
    // second build
    build = createRunningBuild(map(PluginConfigImpl.VCS_ROOT_MIRRORS_STRATEGY, PluginConfigImpl.VCS_ROOT_MIRRORS_STRATEGY_ALTERNATES));
    myVcsSupport.updateSources(root, CheckoutRules.DEFAULT, "bba7fbcc200b4968e6abd2f7d475dc15306cafc6", myCheckoutDir, build, false);
    then(new File(gitDir, "refs/heads/brokenRef")).doesNotExist();
    then(new File(gitDir, "refs/heads/anotherBrokenRef")).doesNotExist();
    then(readText(packedRefs)).doesNotContain("refs/heads/brokenRef");
    then(readText(packedRefs)).doesNotContain("refs/remotes/origin/brokenRef");
    then(readText(packedRefs)).doesNotContain("refs/remotes/origin/anotherBrokenRef");
    then(readText(packedRefs)).doesNotContain("refs/remotes/origin/anotherBrokenRef");
    final ShowRefResult showRefResult = new AgentGitFacadeImpl(getGitPath()).showRef().call();
    then(showRefResult.getInvalidRefs()).isEmpty();
    then(showRefResult.getValidRefs()).isNotEmpty();
    then(showRefResult.isFailed()).isFalse();
}
Also used : ShowRefResult(jetbrains.buildServer.buildTriggers.vcs.git.agent.command.ShowRefResult) VcsRootImpl(jetbrains.buildServer.vcs.impl.VcsRootImpl) GitTestUtil.dataFile(jetbrains.buildServer.buildTriggers.vcs.git.tests.GitTestUtil.dataFile) File(java.io.File)

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