Search in sources :

Example 46 with VcsRootImpl

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

the class AgentVcsSupportTest method should_remap_mirror_if_its_fetch_and_remove_failed.

@TestFor(issues = "TW-43884")
public void should_remap_mirror_if_its_fetch_and_remove_failed() throws Exception {
    MockFS fs = new MockFS();
    LoggingGitMetaFactory loggingFactory = new LoggingGitMetaFactory();
    myVcsSupport = myBuilder.setGitMetaFactory(loggingFactory).setFS(fs).build();
    File repo = dataFile("repo_for_fetch.1");
    File remoteRepo = myTempFiles.createTempDir();
    copyRepository(repo, remoteRepo);
    // run build to prepare mirror
    VcsRootImpl root = vcsRoot().withAgentGitPath(getGitPath()).withFetchUrl(GitUtils.toURL(remoteRepo)).build();
    myVcsSupport.updateSources(root, CheckoutRules.DEFAULT, "add81050184d3c818560bdd8839f50024c188586", myCheckoutDir, createRunningBuild(true), false);
    // update remote repo: add personal branch
    delete(remoteRepo);
    File updatedRepo = dataFile("repo_for_fetch.2.personal");
    copyRepository(updatedRepo, remoteRepo);
    // make first fetch in local mirror to fail:
    AtomicInteger invocationCount = new AtomicInteger(0);
    loggingFactory.addCallback(FetchCommand.class.getName() + ".call", new GitCommandProxyCallback() {

        @Override
        public Optional<Object> call(final Method method, final Object[] args) throws VcsException {
            if (invocationCount.getAndIncrement() == 0)
                throw new VcsException("TEST ERROR");
            return null;
        }
    });
    File mirror = myBuilder.getMirrorManager().getMirrorDir(GitUtils.toURL(remoteRepo));
    // try to fetch unknown branch, fetch fails and delete of the mirror also fails
    // build should succeed anyway
    fs.makeDeleteFail(mirror);
    VcsRootImpl root2 = vcsRoot().withAgentGitPath(getGitPath()).withBranch("refs/heads/personal").withFetchUrl(GitUtils.toURL(remoteRepo)).build();
    AgentRunningBuild build = runningBuild().useLocalMirrors(true).sharedConfigParams("teamcity.internal.git.remoteOperationAttempts", "1").withAgentConfiguration(myBuilder.getAgentConfiguration()).build();
    myVcsSupport.updateSources(root2, CheckoutRules.DEFAULT, "d47dda159b27b9a8c4cee4ce98e4435eb5b17168", myCheckoutDir, build, false);
    File mirrorAfterBuild = myBuilder.getMirrorManager().getMirrorDir(GitUtils.toURL(remoteRepo));
    // repository was remapped to another dir
    then(mirrorAfterBuild).isNotEqualTo(mirror);
}
Also used : AfterMethod(org.testng.annotations.AfterMethod) Method(java.lang.reflect.Method) BeforeMethod(org.testng.annotations.BeforeMethod) VcsRootImpl(jetbrains.buildServer.vcs.impl.VcsRootImpl) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) VcsException(jetbrains.buildServer.vcs.VcsException) GitTestUtil.dataFile(jetbrains.buildServer.buildTriggers.vcs.git.tests.GitTestUtil.dataFile) File(java.io.File) TestFor(jetbrains.buildServer.util.TestFor)

Example 47 with VcsRootImpl

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

the class AgentVcsSupportTest method should_fail_when_ls_remote_fails.

// we run ls-remote during outdated refs cleanup which is needed to
// successfully checkout when ref a/b is renamed to A/b on win or mac (TW-28735).
// If we continue silently this can cause performance problems (TW-44944)
@TestFor(issues = "TW-44944")
public void should_fail_when_ls_remote_fails() throws Exception {
    LoggingGitMetaFactory loggingFactory = new LoggingGitMetaFactory();
    myVcsSupport = myBuilder.setGitMetaFactory(loggingFactory).build();
    File repo = dataFile("repo_for_fetch.1");
    File remoteRepo = myTempFiles.createTempDir();
    copyRepository(repo, remoteRepo);
    // run build to prepare working dir
    VcsRootImpl root = vcsRoot().withAgentGitPath(getGitPath()).withFetchUrl(GitUtils.toURL(remoteRepo)).build();
    myVcsSupport.updateSources(root, CheckoutRules.DEFAULT, "add81050184d3c818560bdd8839f50024c188586", myCheckoutDir, createRunningBuild(false), false);
    loggingFactory.addCallback(LsRemoteCommand.class.getName() + ".call", new GitCommandProxyCallback() {

        @Override
        public Optional<Object> call(final Method method, final Object[] args) throws VcsException {
            throw new VcsException("TEST ERROR");
        }
    });
    // ls-remote will fail during this build
    try {
        myVcsSupport.updateSources(root, CheckoutRules.DEFAULT, "d47dda159b27b9a8c4cee4ce98e4435eb5b17168", myCheckoutDir, createRunningBuild(false), false);
        fail("should fail");
    } catch (VcsException e) {
        assertTrue(true);
    }
}
Also used : VcsRootImpl(jetbrains.buildServer.vcs.impl.VcsRootImpl) VcsException(jetbrains.buildServer.vcs.VcsException) AfterMethod(org.testng.annotations.AfterMethod) Method(java.lang.reflect.Method) BeforeMethod(org.testng.annotations.BeforeMethod) GitTestUtil.dataFile(jetbrains.buildServer.buildTriggers.vcs.git.tests.GitTestUtil.dataFile) File(java.io.File) TestFor(jetbrains.buildServer.util.TestFor)

Example 48 with VcsRootImpl

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

the class AgentVcsSupportTest method should_update_remote_tracking_branch_in_case_of_fast_forward_update.

@TestFor(issues = "TW-46854")
@Test(dataProvider = "mirrors")
public void should_update_remote_tracking_branch_in_case_of_fast_forward_update(boolean useMirrors) throws Exception {
    File remoteRepo = myTempFiles.createTempDir();
    copyRepository(dataFile("repo_for_fetch.2"), remoteRepo);
    VcsRootImpl root = vcsRoot().withAgentGitPath(getGitPath()).withFetchUrl(remoteRepo).withUseMirrors(useMirrors).build();
    String buildBranchParam = GitUtils.getGitRootBranchParamName(root);
    // run build in master branch
    AgentRunningBuild build = createRunningBuild(map(buildBranchParam, "refs/heads/master"));
    myVcsSupport.updateSources(root, CheckoutRules.DEFAULT, "d47dda159b27b9a8c4cee4ce98e4435eb5b17168", myCheckoutDir, build, false);
    // fast-forward update master to point to the same commit as master
    Repository remote = new RepositoryBuilder().setGitDir(remoteRepo).build();
    RefUpdate refUpdate = remote.updateRef("refs/heads/personal");
    refUpdate.setNewObjectId(ObjectId.fromString("add81050184d3c818560bdd8839f50024c188586"));
    refUpdate.update();
    // run build in personal branch
    build = createRunningBuild(map(buildBranchParam, "refs/heads/personal"));
    myVcsSupport.updateSources(root, CheckoutRules.DEFAULT, "add81050184d3c818560bdd8839f50024c188586", myCheckoutDir, build, false);
    // fast-forward update personal branch to point to the same commit as master
    refUpdate = remote.updateRef("refs/heads/personal");
    refUpdate.setNewObjectId(ObjectId.fromString("d47dda159b27b9a8c4cee4ce98e4435eb5b17168"));
    refUpdate.update();
    // run build on updated personal branch
    build = createRunningBuild(map(buildBranchParam, "refs/heads/personal"));
    myVcsSupport.updateSources(root, CheckoutRules.DEFAULT, "d47dda159b27b9a8c4cee4ce98e4435eb5b17168", myCheckoutDir, build, false);
    // both branch and its remote-tracking branch should be updated
    Repository r = new RepositoryBuilder().setWorkTree(myCheckoutDir).build();
    then(r.getAllRefs().get("refs/heads/personal").getObjectId().name()).isEqualTo("d47dda159b27b9a8c4cee4ce98e4435eb5b17168");
    then(r.getAllRefs().get("refs/remotes/origin/personal").getObjectId().name()).isEqualTo("d47dda159b27b9a8c4cee4ce98e4435eb5b17168");
}
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) TestFor(jetbrains.buildServer.util.TestFor)

Example 49 with VcsRootImpl

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

the class AgentVcsSupportTest method should_not_use_custom_clone_on_server.

@TestFor(issues = "TW-46266")
public void should_not_use_custom_clone_on_server() throws Exception {
    File serverCustomCloneDir = myTempFiles.createTempDir();
    VcsRootImpl root = vcsRoot().withAgentGitPath(getGitPath()).withFetchUrl(GitUtils.toURL(myMainRepo)).withRepositoryPathOnServer(serverCustomCloneDir.getCanonicalPath()).build();
    myVcsSupport.updateSources(root, CheckoutRules.DEFAULT, "465ad9f630e451b9f2b782ffb09804c6a98c4bb9", myCheckoutDir, createRunningBuild(true), false);
    then(serverCustomCloneDir.listFiles()).isEmpty();
}
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 50 with VcsRootImpl

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

the class AgentVcsSupportTest method should_retry_fetch_mirror.

@TestFor(issues = "TW-56415")
public void should_retry_fetch_mirror() throws Exception {
    MockFS fs = new MockFS();
    LoggingGitMetaFactory loggingFactory = new LoggingGitMetaFactory();
    myVcsSupport = myBuilder.setGitMetaFactory(loggingFactory).setFS(fs).build();
    File repo = dataFile("repo_for_fetch.1");
    File remoteRepo = myTempFiles.createTempDir();
    copyRepository(repo, remoteRepo);
    // run build to prepare mirror
    VcsRootImpl root = vcsRoot().withAgentGitPath(getGitPath()).withFetchUrl(GitUtils.toURL(remoteRepo)).build();
    myVcsSupport.updateSources(root, CheckoutRules.DEFAULT, "add81050184d3c818560bdd8839f50024c188586", myCheckoutDir, createRunningBuild(true), false);
    // update remote repo: add personal branch
    delete(remoteRepo);
    File updatedRepo = dataFile("repo_for_fetch.2.personal");
    copyRepository(updatedRepo, remoteRepo);
    // make first two fetches in local mirror to fail:
    AtomicInteger invocationCount = new AtomicInteger(0);
    loggingFactory.addCallback(BaseAuthCommandImpl.class.getName() + ".doRunCmd", new GitCommandProxyCallback() {

        @Override
        public Optional<Object> call(final Method method, final Object[] args) throws VcsException {
            if (invocationCount.getAndIncrement() <= 1)
                throw new VcsException("TEST ERROR");
            return null;
        }
    });
    File mirror = myBuilder.getMirrorManager().getMirrorDir(GitUtils.toURL(remoteRepo));
    // try to fetch unknown branch, first fetch fails, second succeeds. If it's not ensure that delete of the mirror also fails
    // build should succeed anyway
    fs.makeDeleteFail(mirror);
    VcsRootImpl root2 = vcsRoot().withAgentGitPath(getGitPath()).withBranch("refs/heads/personal").withFetchUrl(GitUtils.toURL(remoteRepo)).build();
    AgentRunningBuild build = runningBuild().useLocalMirrors(true).withAgentConfiguration(myBuilder.getAgentConfiguration()).sharedConfigParams("teamcity.internal.git.remoteOperationAttempts", "3").build();
    myVcsSupport.updateSources(root2, CheckoutRules.DEFAULT, "d47dda159b27b9a8c4cee4ce98e4435eb5b17168", myCheckoutDir, build, false);
    File mirrorAfterBuild = myBuilder.getMirrorManager().getMirrorDir(GitUtils.toURL(remoteRepo));
    // repository was not remapped to another dir
    then(mirrorAfterBuild).isEqualTo(mirror);
}
Also used : AfterMethod(org.testng.annotations.AfterMethod) Method(java.lang.reflect.Method) BeforeMethod(org.testng.annotations.BeforeMethod) VcsRootImpl(jetbrains.buildServer.vcs.impl.VcsRootImpl) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) VcsException(jetbrains.buildServer.vcs.VcsException) 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