Search in sources :

Example 26 with TestFor

use of jetbrains.buildServer.util.TestFor in project teamcity-git by JetBrains.

the class CollectChangesTest method do_not_do_fetch_per_branch.

@TestFor(issues = "TW-29798")
public void do_not_do_fetch_per_branch() throws Exception {
    VcsRoot root = vcsRoot().withFetchUrl(myRepo).withBranch("master").withReportTags(true).build();
    // setup fetcher with counter
    ServerPluginConfig config = myConfig.build();
    VcsRootSshKeyManager manager = new EmptyVcsRootSshKeyManager();
    FetchCommand fetchCommand = new FetchCommandImpl(config, new TransportFactoryImpl(config, manager), new FetcherProperties(config), manager);
    FetchCommandCountDecorator fetchCounter = new FetchCommandCountDecorator(fetchCommand);
    GitVcsSupport git = gitSupport().withPluginConfig(myConfig).withFetchCommand(fetchCounter).build();
    RepositoryStateData state = git.getCurrentState(root);
    // has a single branch
    RepositoryStateData s1 = createVersionState("refs/heads/master", map("refs/heads/master", state.getBranchRevisions().get("refs/heads/master")));
    // has many branches
    RepositoryStateData s2 = createVersionState("refs/heads/master", state.getBranchRevisions());
    git.getCollectChangesPolicy().collectChanges(root, s1, s2, CheckoutRules.DEFAULT);
    assertEquals(fetchCounter.getFetchCount(), 1);
    FileUtil.delete(config.getCachesDir());
    fetchCounter.resetFetchCounter();
    git.getCollectChangesPolicy().collectChanges(root, s2, s1, CheckoutRules.DEFAULT);
    assertEquals(fetchCounter.getFetchCount(), 1);
}
Also used : VcsRootSshKeyManager(jetbrains.buildServer.ssh.VcsRootSshKeyManager) TestFor(jetbrains.buildServer.util.TestFor)

Example 27 with TestFor

use of jetbrains.buildServer.util.TestFor in project teamcity-git by JetBrains.

the class AgentVcsSupportTest method handle_files_marked_as_unchanged.

@TestFor(issues = "TW-44844")
@Test(dataProviderClass = BaseRemoteRepositoryTest.class, dataProvider = "true,false")
public void handle_files_marked_as_unchanged(boolean switchBranch) throws Exception {
    // checkout
    myVcsSupport.updateSources(myRoot, CheckoutRules.DEFAULT, "97442a720324a0bd092fb9235f72246dc8b345bc", myCheckoutDir, myBuild, false);
    // modify file
    File f = new File(myCheckoutDir, "dir/a.txt");
    writeFileAndReportErrors(f, "update by build script");
    // git update-index --no-assume-unchanged <file>
    Process updateIndex = new ProcessBuilder().directory(myCheckoutDir).command(getGitPath(), "update-index", "--assume-unchanged", "dir/a.txt").start();
    updateIndex.waitFor();
    if (updateIndex.exitValue() != 0) {
        fail("git update-index failed, exit code " + updateIndex.exitValue() + "\nstdout: " + StreamUtil.readText(updateIndex.getInputStream()) + "\nstderr: " + StreamUtil.readText(updateIndex.getErrorStream()));
    }
    // update to commit which changes the file
    if (switchBranch)
        myBuild = createRunningBuild(map(GitUtils.getGitRootBranchParamName(myRoot), "refs/heads/personal-branch1"));
    myVcsSupport.updateSources(myRoot, CheckoutRules.DEFAULT, "ad4528ed5c84092fdbe9e0502163cf8d6e6141e7", myCheckoutDir, myBuild, false);
    then(FileUtil.readFile(f)).doesNotContain("update by build script");
}
Also used : 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 28 with TestFor

use of jetbrains.buildServer.util.TestFor in project teamcity-git by JetBrains.

the class AgentVcsSupportTest method mirror_delete_can_be_disabled.

@TestFor(issues = "TW-43884")
public void mirror_delete_can_be_disabled() 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);
    // create refs/heads/personal/1 so that incremental fetch will 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 Optional.empty();
        }
    });
    File mirror = myBuilder.getMirrorManager().getMirrorDir(GitUtils.toURL(remoteRepo));
    VcsRootImpl root2 = vcsRoot().withAgentGitPath(getGitPath()).withBranch("refs/heads/personal").withFetchUrl(GitUtils.toURL(remoteRepo)).build();
    fs.makeDeleteFail(mirror);
    try {
        AgentRunningBuild build = runningBuild().useLocalMirrors(true).sharedConfigParams(AgentRuntimeProperties.FAIL_ON_CLEAN_CHECKOUT, "true").withAgentConfiguration(myBuilder.getAgentConfiguration()).sharedConfigParams("teamcity.git.fetchMirrorRetryTimeouts", "0").build();
        myVcsSupport.updateSources(root2, CheckoutRules.DEFAULT, "d47dda159b27b9a8c4cee4ce98e4435eb5b17168", myCheckoutDir, build, false);
        fail("Should fail");
    } catch (VcsException e) {
        File mirrorAfterBuild = myBuilder.getMirrorManager().getMirrorDir(GitUtils.toURL(remoteRepo));
        // should fail on first fetch attempt and not remap or delete the mirror
        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)

Example 29 with TestFor

use of jetbrains.buildServer.util.TestFor in project teamcity-git by JetBrains.

the class AgentVcsSupportTest method should_handle_HEAD_pointing_to_invalid_object.

@TestFor(issues = "TW-74592")
public void should_handle_HEAD_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, "HEAD"), invalidObject);
    // 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);
    assertEquals("ref: refs/heads/master", FileUtil.readText(new File(gitDir, "HEAD")).trim());
}
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 30 with TestFor

use of jetbrains.buildServer.util.TestFor in project teamcity-git by JetBrains.

the class AgentVcsSupportTest method push_with_local_mirrors_should_go_to_original_repository.

@TestFor(issues = "TW-20165")
public void push_with_local_mirrors_should_go_to_original_repository() throws Exception {
    AgentRunningBuild build = createRunningBuild(true);
    myVcsSupport.updateSources(myRoot, CheckoutRules.DEFAULT, GitUtils.makeVersion("465ad9f630e451b9f2b782ffb09804c6a98c4bb9", 1289483394000L), myCheckoutDir, build, false);
    final File fileToChange = new File(myCheckoutDir, "file");
    FileUtil.writeToFile(fileToChange, "text".getBytes());
    Repository r = new RepositoryBuilder().setWorkTree(myCheckoutDir).build();
    Git git = new Git(r);
    git.add().addFilepattern("file").call();
    RevCommit commitDuringTheBuild = git.commit().setMessage("Commit during the build").call();
    // push using native git, seems like jgit doesn't respect url.insteadOf settings
    new PushCommand().run(getGitPath(), myCheckoutDir.getAbsolutePath());
    Repository remote = new RepositoryBuilder().setGitDir(myMainRepo).build();
    assertTrue("Push didn't go to the remote repository", remote.hasObject(commitDuringTheBuild));
}
Also used : Git(org.eclipse.jgit.api.Git) GitTestUtil.dataFile(jetbrains.buildServer.buildTriggers.vcs.git.tests.GitTestUtil.dataFile) File(java.io.File) RevCommit(org.eclipse.jgit.revwalk.RevCommit) TestFor(jetbrains.buildServer.util.TestFor)

Aggregations

TestFor (jetbrains.buildServer.util.TestFor)130 Test (org.testng.annotations.Test)82 File (java.io.File)66 GitTestUtil.dataFile (jetbrains.buildServer.buildTriggers.vcs.git.tests.GitTestUtil.dataFile)56 VcsRootImpl (jetbrains.buildServer.vcs.impl.VcsRootImpl)26 CheckoutRules (jetbrains.buildServer.vcs.CheckoutRules)21 VcsRoot (jetbrains.buildServer.vcs.VcsRoot)17 SFinishedBuild (jetbrains.buildServer.serverSide.SFinishedBuild)12 VcsException (jetbrains.buildServer.vcs.VcsException)11 URIish (org.eclipse.jgit.transport.URIish)11 Repository (org.eclipse.jgit.lib.Repository)9 BaseFinderTest (jetbrains.buildServer.server.rest.data.BaseFinderTest)7 AfterMethod (org.testng.annotations.AfterMethod)7 BeforeMethod (org.testng.annotations.BeforeMethod)7 Method (java.lang.reflect.Method)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 GitTestUtil.copyRepository (jetbrains.buildServer.buildTriggers.vcs.git.tests.GitTestUtil.copyRepository)6 Build (jetbrains.buildServer.server.rest.model.build.Build)6 BuildTypeImpl (jetbrains.buildServer.serverSide.impl.BuildTypeImpl)6 FileUtil.writeFile (jetbrains.buildServer.util.FileUtil.writeFile)6