Search in sources :

Example 41 with VcsRootImpl

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

the class AgentVcsSupportTest method should_remove_orphaned_indexes.

@TestFor(issues = "TW-40313")
public void should_remove_orphaned_indexes() throws Exception {
    // checkout
    VcsRootImpl root = vcsRoot().withAgentGitPath(getGitPath()).withFetchUrl(GitUtils.toURL(myMainRepo)).build();
    myVcsSupport.updateSources(root, CheckoutRules.DEFAULT, "465ad9f630e451b9f2b782ffb09804c6a98c4bb9", myCheckoutDir, createRunningBuild(true), false);
    // create orphaned idx files
    File mirror = myBuilder.getMirrorManager().getMirrorDir(GitUtils.toURL(myMainRepo));
    File idxInMirror = new File(new File(new File(mirror, "objects"), "pack"), "whatever.idx");
    writeFileAndReportErrors(idxInMirror, "whatever");
    File idxInCheckoutDir = new File(new File(new File(mirror, "objects"), "pack"), "whatever.idx");
    writeFileAndReportErrors(idxInCheckoutDir, "whatever");
    // checkout again
    myVcsSupport.updateSources(root, CheckoutRules.DEFAULT, "465ad9f630e451b9f2b782ffb09804c6a98c4bb9", myCheckoutDir, createRunningBuild(true), false);
    // orphaned idx files are removed
    then(idxInCheckoutDir).doesNotExist();
    then(idxInMirror).doesNotExist();
}
Also used : 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)

Example 42 with VcsRootImpl

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

the class AgentVcsSupportTest method test_update_on_revision_from_feature_branch.

@Test(dataProvider = "mirrors")
public void test_update_on_revision_from_feature_branch(Boolean useMirrors) throws Exception {
    AgentRunningBuild build = createRunningBuild(useMirrors);
    final File remote = myTempFiles.createTempDir();
    copyRepository(dataFile("repo_for_fetch.2.personal"), remote);
    VcsRootImpl root = createRoot(remote, "master");
    String commitFromFeatureBranch = "d47dda159b27b9a8c4cee4ce98e4435eb5b17168";
    myVcsSupport.updateSources(root, CheckoutRules.DEFAULT, commitFromFeatureBranch, myCheckoutDir, build, false);
}
Also used : VcsRootImpl(jetbrains.buildServer.vcs.impl.VcsRootImpl) GitTestUtil.dataFile(jetbrains.buildServer.buildTriggers.vcs.git.tests.GitTestUtil.dataFile) File(java.io.File) Test(org.testng.annotations.Test)

Example 43 with VcsRootImpl

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

the class AgentVcsSupportTest method recover_from_ref_lock_during_fetch.

@TestFor(issues = "TW-31381")
public void recover_from_ref_lock_during_fetch() throws Exception {
    File repo = dataFile("repo_for_fetch.2.personal");
    File remoteRepo = myTempFiles.createTempDir();
    copyRepository(repo, remoteRepo);
    final String fetchUrl = GitUtils.toURL(remoteRepo);
    VcsRootImpl root = vcsRoot().withBranch("refs/heads/master").withAgentGitPath(getGitPath()).withFetchUrl(fetchUrl).build();
    myVcsSupport.updateSources(root, CheckoutRules.DEFAULT, "add81050184d3c818560bdd8839f50024c188586", myCheckoutDir, myBuild, false);
    // update remote branch master
    delete(remoteRepo);
    File updatedRepo = dataFile("repo_for_fetch.2");
    copyRepository(updatedRepo, remoteRepo);
    File mirror = myBuilder.getMirrorManager().getMirrorDir(fetchUrl);
    FileUtil.createIfDoesntExist(new File(mirror, "refs/heads/master.lock"));
    FileUtil.createIfDoesntExist(new File(myCheckoutDir, ".git/refs/heads/master.lock"));
    FileUtil.createIfDoesntExist(new File(myCheckoutDir, ".git/refs/remotes/origin/master.lock"));
    myVcsSupport.updateSources(root, CheckoutRules.DEFAULT, "d47dda159b27b9a8c4cee4ce98e4435eb5b17168", myCheckoutDir, myBuild, false);
}
Also used : 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)

Example 44 with VcsRootImpl

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

the class AgentVcsSupportTest method when_fetch_for_mirror_failed_remove_it_and_try_again.

public void when_fetch_for_mirror_failed_remove_it_and_try_again() 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)).build();
    AgentRunningBuild buildWithMirrors = createRunningBuild(true);
    myVcsSupport.updateSources(root, CheckoutRules.DEFAULT, "add81050184d3c818560bdd8839f50024c188586", myCheckoutDir, buildWithMirrors, false);
    // create branch tmp in the mirror
    File mirror = myBuilder.getMirrorManager().getMirrorDir(GitUtils.toURL(remoteRepo));
    Repository r = new RepositoryBuilder().setBare().setGitDir(mirror).build();
    RefUpdate update = r.updateRef("refs/heads/tmp");
    update.setNewObjectId(ObjectId.fromString("add81050184d3c818560bdd8839f50024c188586"));
    update.update();
    // update remote repo
    delete(remoteRepo);
    File updatedRepo = dataFile("repo_for_fetch.2.personal");
    copyRepository(updatedRepo, remoteRepo);
    // create branch tmp/1 in remote repo, so fetch will fail
    r = new RepositoryBuilder().setBare().setGitDir(remoteRepo).build();
    update = r.updateRef("refs/heads/tmp/1");
    update.setNewObjectId(ObjectId.fromString("d47dda159b27b9a8c4cee4ce98e4435eb5b17168"));
    update.update();
    // update succeeds
    myVcsSupport.updateSources(root, CheckoutRules.DEFAULT, "d47dda159b27b9a8c4cee4ce98e4435eb5b17168", myCheckoutDir, buildWithMirrors, false);
}
Also used : VcsRootImpl(jetbrains.buildServer.vcs.impl.VcsRootImpl) GitTestUtil.dataFile(jetbrains.buildServer.buildTriggers.vcs.git.tests.GitTestUtil.dataFile) File(java.io.File)

Example 45 with VcsRootImpl

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

the class AgentVcsSupportTest method should_do_fetch_if_ref_is_outdated.

@Test(dataProvider = "mirrors")
public void should_do_fetch_if_ref_is_outdated(Boolean useMirrors) throws Exception {
    AgentRunningBuild build = createRunningBuild(useMirrors);
    final File remote = myTempFiles.createTempDir();
    copyRepository(dataFile("repo_for_fetch.2.personal"), remote);
    VcsRootImpl masterRoot = createRoot(remote, "master");
    VcsRootImpl personalRoot = createRoot(remote, "personal");
    myVcsSupport.updateSources(personalRoot, new CheckoutRules(""), "d47dda159b27b9a8c4cee4ce98e4435eb5b17168@1303829462000", myCheckoutDir, build, false);
    myVcsSupport.updateSources(masterRoot, new CheckoutRules(""), "add81050184d3c818560bdd8839f50024c188586@1303829295000", myCheckoutDir, build, false);
    FileUtil.delete(remote);
    copyRepository(dataFile("repo_for_fetch.2"), remote);
    myVcsSupport.updateSources(masterRoot, new CheckoutRules(""), "d47dda159b27b9a8c4cee4ce98e4435eb5b17168@1303829462000", 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)

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