use of io.fabric8.api.GitContext in project fabric8 by jboss-fuse.
the class PushPullPolicyIT method remoteRemovalOfSingleBranchWhenLocalBranchIsAheadAndCheckedOut.
@Test
public void remoteRemovalOfSingleBranchWhenLocalBranchIsAheadAndCheckedOut() throws GitAPIException, IOException {
servlet.branchDelete().setForce(true).setBranchNames("1.1").call();
editVersion("1.1", 4, false);
local.checkout().setName("1.1").setCreateBranch(false).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(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(1));
assertThat(localUpdateVersions.get(0), equalTo("1.1"));
assertFalse(result.remoteUpdateRequired());
List<Ref> localBranches = local.branchList().call();
assertThat(localBranches.size(), equalTo(4));
assertNull(local.getRepository().getRef("1.1"));
}
use of io.fabric8.api.GitContext in project fabric8 by jboss-fuse.
the class PushPullPolicyIT method pushLocalBranchBehind.
@Test
public void pushLocalBranchBehind() throws IOException, GitAPIException {
local.checkout().setName("1.1").setCreateBranch(false).call();
local.reset().setMode(ResetCommand.ResetType.HARD).setRef("HEAD^").call();
assertTrue(local.status().call().isClean());
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(result.getAcceptedUpdates().size(), equalTo(5));
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.REJECTED_NONFASTFORWARD));
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));
assertThat(result.getRejectedUpdates().size(), equalTo(1));
assertThat(result.getRejectedUpdates().get("refs/heads/1.1").getRemoteRefUpdate().getStatus(), equalTo(RemoteRefUpdate.Status.REJECTED_NONFASTFORWARD));
assertTrue(local.status().call().isClean());
}
use of io.fabric8.api.GitContext in project fabric8 by jboss-fuse.
the class PushPullPolicyIT method remoteUpdateWhenLocalBranchIsAheadButAlreadyMerged.
@Test
public void remoteUpdateWhenLocalBranchIsAheadButAlreadyMerged() throws GitAPIException, IOException {
editVersion("1.1", 2, false);
local.checkout().setName("1.0").setCreateBranch(false).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(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(0));
// if remote commit is already present in local branch, which has additional commits, we have to push back
// to central repo
assertTrue(result.remoteUpdateRequired());
assertTrue(local.status().call().isClean());
}
use of io.fabric8.api.GitContext in project fabric8 by jboss-fuse.
the class FabricGitFacade method write.
@Override
public CommitInfo write(final String branch, final String path, final String commitMessage, final String authorName, final String authorEmail, final String contents) {
assertValid();
final PersonIdent personIdent = new PersonIdent(authorName, authorEmail);
return gitWriteOperation(personIdent, new GitOperation<CommitInfo>() {
public CommitInfo call(Git git, GitContext context) throws Exception {
checkoutBranch(git, branch);
File rootDir = getRootGitDirectory(git);
byte[] data = contents.getBytes();
CommitInfo answer = doWrite(git, rootDir, branch, path, data, personIdent, commitMessage);
context.commitMessage(commitMessage);
return answer;
}
});
}
use of io.fabric8.api.GitContext in project fabric8 by jboss-fuse.
the class FabricGitFacade method revertTo.
@Override
public void revertTo(final String branch, final String objectId, final String blobPath, final String commitMessage, final String authorName, final String authorEmail) {
assertValid();
final PersonIdent personIdent = new PersonIdent(authorName, authorEmail);
gitWriteOperation(personIdent, new GitOperation<Void>() {
public Void call(Git git, GitContext context) throws Exception {
checkoutBranch(git, branch);
File rootDir = getRootGitDirectory(git);
Void answer = doRevert(git, rootDir, branch, objectId, blobPath, commitMessage, personIdent);
context.commitMessage(commitMessage);
return answer;
}
});
}
Aggregations