Search in sources :

Example 26 with GitContext

use of io.fabric8.api.GitContext in project fabric8 by jboss-fuse.

the class PushPullPolicyIT method remoteRemovalOfSingleBranchAndUpdateOfAnotherBranch.

@Test
public void remoteRemovalOfSingleBranchAndUpdateOfAnotherBranch() throws GitAPIException, IOException {
    servlet.branchDelete().setForce(true).setBranchNames("1.1").call();
    editVersion("1.0.1", 3, true);
    Ref ref1 = local.getRepository().getRef("1.0.1");
    PullPushPolicy.PullPolicyResult result = policy.doPull(new GitContext(), CP, true);
    assertNull(result.getLastException());
    Ref ref2 = local.getRepository().getRef("1.0.1");
    Iterable<RevCommit> commits = local.log().addRange(ref1.getObjectId(), ref2.getObjectId()).call();
    Iterator<RevCommit> it = commits.iterator();
    int count = 0;
    while (it.hasNext()) {
        it.next();
        count++;
    }
    assertThat(count, equalTo(3));
    List<String> versions = new ArrayList<>(result.getVersions());
    // these are sorted (TreeSet)
    assertThat(versions.size(), equalTo(4));
    assertThat(versions.get(0), equalTo("1.0"));
    assertThat(versions.get(1), equalTo("1.0.1"));
    assertThat(versions.get(2), equalTo("1.2"));
    assertThat(versions.get(3), equalTo("master"));
    List<String> localUpdateVersions = new ArrayList<>(result.localUpdateVersions().keySet());
    assertThat(localUpdateVersions.size(), equalTo(2));
    assertTrue(localUpdateVersions.contains("1.0.1"));
    assertTrue(localUpdateVersions.contains("1.1"));
    assertFalse(result.remoteUpdateRequired());
    List<Ref> localBranches = local.branchList().call();
    assertThat(localBranches.size(), equalTo(4));
}
Also used : Ref(org.eclipse.jgit.lib.Ref) GitContext(io.fabric8.api.GitContext) ArrayList(java.util.ArrayList) DefaultPullPushPolicy(io.fabric8.git.internal.DefaultPullPushPolicy) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 27 with GitContext

use of io.fabric8.api.GitContext in project fabric8 by jboss-fuse.

the class PushPullPolicyIT method remoteUpdateOfSingleBranch.

@Test
public void remoteUpdateOfSingleBranch() {
    editVersion("1.1", 2, true);
    PullPushPolicy.PullPolicyResult result = policy.doPull(new GitContext(), CP, true);
    assertNull(result.getLastException());
    List<String> versions = new ArrayList<>(result.getVersions());
    // these are sorted (TreeSet)
    assertThat(versions.size(), equalTo(5));
    assertThat(versions.get(0), equalTo("1.0"));
    assertThat(versions.get(1), equalTo("1.0.1"));
    assertThat(versions.get(2), equalTo("1.1"));
    assertThat(versions.get(3), equalTo("1.2"));
    assertThat(versions.get(4), equalTo("master"));
    List<String> localUpdateVersions = new ArrayList<>(result.localUpdateVersions().keySet());
    assertThat(localUpdateVersions.size(), equalTo(1));
    assertThat(localUpdateVersions.get(0), equalTo("1.1"));
    assertFalse(result.remoteUpdateRequired());
}
Also used : GitContext(io.fabric8.api.GitContext) ArrayList(java.util.ArrayList) DefaultPullPushPolicy(io.fabric8.git.internal.DefaultPullPushPolicy) Test(org.junit.Test)

Example 28 with GitContext

use of io.fabric8.api.GitContext in project fabric8 by jboss-fuse.

the class PushPullPolicyIT method pushNoUpdates.

@Test
public void pushNoUpdates() {
    PullPushPolicy.PushPolicyResult result = policy.doPush(new GitContext(), CP);
    assertNull(result.getLastException());
    // push to only one remote, so one PushResult
    PushResult pr = result.getPushResults().get(0);
    assertThat(pr.getRemoteUpdate("refs/heads/1.0").getStatus(), equalTo(RemoteRefUpdate.Status.UP_TO_DATE));
    assertThat(pr.getRemoteUpdate("refs/heads/1.0.1").getStatus(), equalTo(RemoteRefUpdate.Status.UP_TO_DATE));
    assertThat(pr.getRemoteUpdate("refs/heads/1.1").getStatus(), equalTo(RemoteRefUpdate.Status.UP_TO_DATE));
    assertThat(pr.getRemoteUpdate("refs/heads/1.2").getStatus(), equalTo(RemoteRefUpdate.Status.UP_TO_DATE));
    assertThat(pr.getRemoteUpdate("refs/heads/master").getStatus(), equalTo(RemoteRefUpdate.Status.UP_TO_DATE));
    assertThat(pr.getRemoteUpdate("refs/tags/root").getStatus(), equalTo(RemoteRefUpdate.Status.UP_TO_DATE));
}
Also used : GitContext(io.fabric8.api.GitContext) DefaultPullPushPolicy(io.fabric8.git.internal.DefaultPullPushPolicy) PushResult(org.eclipse.jgit.transport.PushResult) Test(org.junit.Test)

Example 29 with GitContext

use of io.fabric8.api.GitContext in project fabric8 by jboss-fuse.

the class PushPullPolicyIT method remoteCreationOfSingleBranch.

@Test
public void remoteCreationOfSingleBranch() throws GitAPIException {
    local.checkout().setName("1.1.1").setCreateBranch(true).setStartPoint("1.1").call();
    local.push().setRemote("origin").setRefSpecs(new RefSpec("1.1.1")).call();
    local.checkout().setName("master").setCreateBranch(false).call();
    local.branchDelete().setBranchNames("refs/heads/1.1.1", "refs/remotes/origin/1.1.1").setForce(true).call();
    PullPushPolicy.PullPolicyResult result = policy.doPull(new GitContext(), CP, true);
    assertNull(result.getLastException());
    List<String> versions = new ArrayList<>(result.getVersions());
    // these are sorted (TreeSet)
    assertThat(versions.size(), equalTo(6));
    assertThat(versions.get(0), equalTo("1.0"));
    assertThat(versions.get(1), equalTo("1.0.1"));
    assertThat(versions.get(2), equalTo("1.1"));
    assertThat(versions.get(3), equalTo("1.1.1"));
    assertThat(versions.get(4), equalTo("1.2"));
    assertThat(versions.get(5), equalTo("master"));
    List<String> localUpdateVersions = new ArrayList<>(result.localUpdateVersions().keySet());
    assertThat(localUpdateVersions.size(), equalTo(1));
    assertThat(localUpdateVersions.get(0), equalTo("1.1.1"));
    assertFalse(result.remoteUpdateRequired());
    List<Ref> localBranches = local.branchList().call();
    assertThat(localBranches.size(), equalTo(6));
}
Also used : Ref(org.eclipse.jgit.lib.Ref) RefSpec(org.eclipse.jgit.transport.RefSpec) GitContext(io.fabric8.api.GitContext) ArrayList(java.util.ArrayList) DefaultPullPushPolicy(io.fabric8.git.internal.DefaultPullPushPolicy) Test(org.junit.Test)

Example 30 with GitContext

use of io.fabric8.api.GitContext in project fabric8 by jboss-fuse.

the class PushPullPolicyIT method remoteUpdateWhenLocalBranchIsAhead.

@Test
public void remoteUpdateWhenLocalBranchIsAhead() throws GitAPIException, IOException {
    editVersion("1.1", 2, true, "fabric/profiles/default.profile/io.fabric8.other.properties");
    editVersion("1.1", 2, false);
    ObjectId branch1_1local = local.getRepository().getRef("refs/heads/1.1").getObjectId();
    ObjectId branch1_1remote = servlet.getRepository().getRef("refs/heads/1.1").getObjectId();
    assertThat(branch1_1local, not(equalTo(branch1_1remote)));
    local.checkout().setName("1.0").setCreateBranch(false).call();
    assertTrue(local.status().call().isClean());
    PullPushPolicy.PullPolicyResult result = policy.doPull(new GitContext(), CP, true);
    assertNull(result.getLastException());
    List<String> versions = new ArrayList<>(result.getVersions());
    // these are sorted (TreeSet)
    assertThat(versions.size(), equalTo(5));
    assertThat(versions.get(0), equalTo("1.0"));
    assertThat(versions.get(1), equalTo("1.0.1"));
    assertThat(versions.get(2), equalTo("1.1"));
    assertThat(versions.get(3), equalTo("1.2"));
    assertThat(versions.get(4), equalTo("master"));
    List<String> localUpdateVersions = new ArrayList<>(result.localUpdateVersions().keySet());
    assertThat(localUpdateVersions.size(), equalTo(1));
    assertThat(localUpdateVersions.get(0), equalTo("1.1"));
    assertTrue(result.remoteUpdateRequired());
    assertTrue(local.status().call().isClean());
    List<Ref> localBranches = local.branchList().call();
    assertThat(localBranches.size(), equalTo(5));
    assertNotNull(local.getRepository().getRef("1.1"));
    assertThat("Local branch should change by rebase on top of what's in remote", local.getRepository().getRef("refs/heads/1.1").getObjectId(), not(equalTo(branch1_1remote)));
}
Also used : Ref(org.eclipse.jgit.lib.Ref) ObjectId(org.eclipse.jgit.lib.ObjectId) GitContext(io.fabric8.api.GitContext) ArrayList(java.util.ArrayList) DefaultPullPushPolicy(io.fabric8.git.internal.DefaultPullPushPolicy) Test(org.junit.Test)

Aggregations

GitContext (io.fabric8.api.GitContext)41 Git (org.eclipse.jgit.api.Git)22 DefaultPullPushPolicy (io.fabric8.git.internal.DefaultPullPushPolicy)18 Test (org.junit.Test)18 LockHandle (io.fabric8.api.LockHandle)15 ArrayList (java.util.ArrayList)13 File (java.io.File)12 Ref (org.eclipse.jgit.lib.Ref)11 IOException (java.io.IOException)9 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)8 PushResult (org.eclipse.jgit.transport.PushResult)8 PersonIdent (org.eclipse.jgit.lib.PersonIdent)7 FabricException (io.fabric8.api.FabricException)5 Profile (io.fabric8.api.Profile)4 RevCommit (org.eclipse.jgit.revwalk.RevCommit)3 GitVersion (io.fabric8.api.commands.GitVersion)2 GitDataStore (io.fabric8.git.GitDataStore)2 GitService (io.fabric8.git.GitService)2 PushPolicyResult (io.fabric8.git.PullPushPolicy.PushPolicyResult)2 GitOperation (io.fabric8.git.internal.GitOperation)2