Search in sources :

Example 11 with GitVcsSupport

use of jetbrains.buildServer.buildTriggers.vcs.git.GitVcsSupport in project teamcity-git by JetBrains.

the class LatestAcceptedRevisionTest method branch_merged_to_master.

public void branch_merged_to_master() throws IOException, VcsException {
    GitVcsSupport support = git();
    VcsRoot root = vcsRoot().withFetchUrl(myRepo).build();
    ensureFetchPerformed(support, root, "refs/heads/master", "b304522994197be5f336d58cc34edc11cbda095e");
    String rev = support.getCollectChangesPolicy().getLatestRevisionAcceptedByCheckoutRules(root, new CheckoutRules("+:src"), "b304522994197be5f336d58cc34edc11cbda095e", Collections.emptySet());
    then(rev).isEqualTo("bb6ab65d23fa0ffbaa61d44c8241f127cf0f323f");
    rev = support.getCollectChangesPolicy().getLatestRevisionAcceptedByCheckoutRules(root, new CheckoutRules("+:test"), "b304522994197be5f336d58cc34edc11cbda095e", Collections.emptySet());
    then(rev).isEqualTo("b265fd1608fe17f912a031312e1efc758c4e8a35");
}
Also used : GitVcsSupport(jetbrains.buildServer.buildTriggers.vcs.git.GitVcsSupport) CheckoutRules(jetbrains.buildServer.vcs.CheckoutRules) VcsRoot(jetbrains.buildServer.vcs.VcsRoot)

Example 12 with GitVcsSupport

use of jetbrains.buildServer.buildTriggers.vcs.git.GitVcsSupport in project teamcity-git by JetBrains.

the class LatestAcceptedRevisionTest method test_include_all_exclude_all.

public void test_include_all_exclude_all() throws IOException, VcsException {
    GitVcsSupport support = git();
    VcsRoot root = vcsRoot().withFetchUrl(myRepo).build();
    ensureFetchPerformed(support, root, "refs/heads/master", "bbdf67dc5d1d2fa1ce08a0c7db7371f14cd918bf");
    String rev = support.getCollectChangesPolicy().getLatestRevisionAcceptedByCheckoutRules(root, new CheckoutRules("+:."), "bbdf67dc5d1d2fa1ce08a0c7db7371f14cd918bf", Collections.emptySet());
    then(rev).isEqualTo("bbdf67dc5d1d2fa1ce08a0c7db7371f14cd918bf");
    rev = support.getCollectChangesPolicy().getLatestRevisionAcceptedByCheckoutRules(root, new CheckoutRules("-:."), "bbdf67dc5d1d2fa1ce08a0c7db7371f14cd918bf", Collections.emptySet());
    then(rev).isNull();
}
Also used : GitVcsSupport(jetbrains.buildServer.buildTriggers.vcs.git.GitVcsSupport) CheckoutRules(jetbrains.buildServer.vcs.CheckoutRules) VcsRoot(jetbrains.buildServer.vcs.VcsRoot)

Example 13 with GitVcsSupport

use of jetbrains.buildServer.buildTriggers.vcs.git.GitVcsSupport in project teamcity-git by JetBrains.

the class LatestAcceptedRevisionTest method traverse_through_merges_looking_for_interesting_commit.

public void traverse_through_merges_looking_for_interesting_commit() throws VcsException, IOException {
    GitVcsSupport support = git();
    VcsRoot root = vcsRoot().withFetchUrl(myRepo).build();
    ensureFetchPerformed(support, root, "refs/heads/master", "6d8cc5e06db390a20f5b2bf278206a0ec47f05dc");
    Set<String> visited = new HashSet<>();
    String rev = support.getCollectChangesPolicy().getLatestRevisionAcceptedByCheckoutRules(root, new CheckoutRules("+:test/subDir"), "6ff32b16fe485e7a0a1e209bf10987e1ad46292e", Collections.emptySet(), visited);
    then(rev).isEqualTo("be6e6b68e84b5aec8a022a8b2d740ed39a7c63b9");
    then(visited).containsOnly("6ff32b16fe485e7a0a1e209bf10987e1ad46292e", "eea4a3e48901ba036998c9fe0afdc78cc8a05a33", "1330f191b990a389459e28f8754c913e9b417c93", "75c9325d5b129f299fba8567f0fd7f599d336e8f", "be6e6b68e84b5aec8a022a8b2d740ed39a7c63b9");
    visited.clear();
    rev = support.getCollectChangesPolicy().getLatestRevisionAcceptedByCheckoutRules(root, new CheckoutRules("+:test/TestFile4.java"), "6ff32b16fe485e7a0a1e209bf10987e1ad46292e", Collections.emptySet(), visited);
    then(rev).isEqualTo("40224a053e16145562d1befa3d0a127c54f5dbff");
    then(visited).containsOnly("6ff32b16fe485e7a0a1e209bf10987e1ad46292e", "ce92302a768ce0763e83aebf8c0e16e102c8d06b", "d036d012385a762568a474b57337b9cf398b96e0", "40224a053e16145562d1befa3d0a127c54f5dbff");
}
Also used : GitVcsSupport(jetbrains.buildServer.buildTriggers.vcs.git.GitVcsSupport) CheckoutRules(jetbrains.buildServer.vcs.CheckoutRules) VcsRoot(jetbrains.buildServer.vcs.VcsRoot) HashSet(java.util.HashSet)

Example 14 with GitVcsSupport

use of jetbrains.buildServer.buildTriggers.vcs.git.GitVcsSupport in project teamcity-git by JetBrains.

the class GitLabelingSupportTest method fail_labeling_when_heuristics_fails.

public void fail_labeling_when_heuristics_fails() throws Exception {
    myConfig.setUsePackHeuristic(true);
    myConfig.setFailLabelingWhenPackHeuristicsFail(true);
    GitVcsSupport git = buildGit();
    File remoteRepoDir = getRemoteRepositoryDir("repo_for_fetch.2");
    VcsRoot root = vcsRoot().withFetchUrl(remoteRepoDir).build();
    makeCloneOnServer(git, root);
    // erase commit in the remote repository
    FileUtil.delete(remoteRepoDir);
    remoteRepoDir.mkdirs();
    FileUtil.copyDir(getRemoteRepositoryDir("repo_for_fetch.1"), remoteRepoDir);
    try {
        // label erased commit
        String erasedCommit = "d47dda159b27b9a8c4cee4ce98e4435eb5b17168";
        git.getLabelingSupport().label("label", erasedCommit, root, CheckoutRules.DEFAULT);
        fail("Should fail labeling since heuristics fails");
    } catch (VcsException e) {
        assertTrue(true);
    }
}
Also used : GitVcsSupport(jetbrains.buildServer.buildTriggers.vcs.git.GitVcsSupport) VcsException(jetbrains.buildServer.vcs.VcsException) VcsRoot(jetbrains.buildServer.vcs.VcsRoot) File(java.io.File)

Example 15 with GitVcsSupport

use of jetbrains.buildServer.buildTriggers.vcs.git.GitVcsSupport in project teamcity-git by JetBrains.

the class GitLabelingSupportTest method should_push_all_objects_missing_in_remote_repository.

@Test(dataProvider = "true,false")
public void should_push_all_objects_missing_in_remote_repository(boolean usePackHeuristics) throws Exception {
    myConfig.setUsePackHeuristic(usePackHeuristics);
    GitVcsSupport git = buildGit();
    File remoteRepoDir = getRemoteRepositoryDir("repo_for_fetch.2");
    VcsRoot root = vcsRoot().withFetchUrl(remoteRepoDir).build();
    makeCloneOnServer(git, root);
    // erase commit in the remote repository
    FileUtil.delete(remoteRepoDir);
    remoteRepoDir.mkdirs();
    FileUtil.copyDir(getRemoteRepositoryDir("repo_for_fetch.1"), remoteRepoDir);
    // label erased commit
    String erasedCommit = "d47dda159b27b9a8c4cee4ce98e4435eb5b17168";
    git.getLabelingSupport().label("label", erasedCommit, root, CheckoutRules.DEFAULT);
    // erased commit should appear in the remote repository
    Repository r = new RepositoryBuilder().setGitDir(remoteRepoDir).build();
    RevWalk walk = new RevWalk(r);
    try {
        walk.parseCommit(ObjectId.fromString(erasedCommit));
    } catch (MissingObjectException e) {
        fail("Not all objects were pushed, labeled commit " + erasedCommit + " is missing");
    } finally {
        walk.close();
        r.close();
    }
}
Also used : GitVcsSupport(jetbrains.buildServer.buildTriggers.vcs.git.GitVcsSupport) VcsRoot(jetbrains.buildServer.vcs.VcsRoot) RevWalk(org.eclipse.jgit.revwalk.RevWalk) File(java.io.File) MissingObjectException(org.eclipse.jgit.errors.MissingObjectException) Test(org.testng.annotations.Test)

Aggregations

GitVcsSupport (jetbrains.buildServer.buildTriggers.vcs.git.GitVcsSupport)31 VcsRoot (jetbrains.buildServer.vcs.VcsRoot)15 CheckoutRules (jetbrains.buildServer.vcs.CheckoutRules)10 Test (org.testng.annotations.Test)9 GitFetchService (jetbrains.buildServer.buildTriggers.vcs.git.GitFetchService)6 GitCommitsInfoBuilder (jetbrains.buildServer.buildTriggers.vcs.git.commitInfo.GitCommitsInfoBuilder)5 CommitInfo (jetbrains.vcs.api.CommitInfo)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 PatchBuilderImpl (jetbrains.buildServer.vcs.patches.PatchBuilderImpl)3 File (java.io.File)2 VcsRootImpl (jetbrains.buildServer.vcs.impl.VcsRootImpl)2 HashSet (java.util.HashSet)1 OperationContext (jetbrains.buildServer.buildTriggers.vcs.git.OperationContext)1 ModificationData (jetbrains.buildServer.vcs.ModificationData)1 VcsException (jetbrains.buildServer.vcs.VcsException)1 CommitMountPointInfo (jetbrains.vcs.api.CommitMountPointInfo)1 MissingObjectException (org.eclipse.jgit.errors.MissingObjectException)1 RevWalk (org.eclipse.jgit.revwalk.RevWalk)1