use of org.locationtech.geogig.api.porcelain.MergeOp.MergeReport in project GeoGig by boundlessgeo.
the class SquashOpTest method testSquashInMergedBranch.
@Test
public void testSquashInMergedBranch() throws Exception {
// Try to squash the commits marked (*) in this history
// o
// |
// o - Points 1 added
// |\
// | o - branch1 - Points 2 added*
// | |
// | o - Points 3 added*
// | |
// o | - Lines 1 added
// |/
// o - master - HEAD - Merge commit*
insertAndAdd(points1);
@SuppressWarnings("unused") final RevCommit c1 = geogig.command(CommitOp.class).setMessage("commit for " + idP1).call();
geogig.command(BranchCreateOp.class).setAutoCheckout(true).setName("branch1").call();
insertAndAdd(points2);
final RevCommit c2 = geogig.command(CommitOp.class).setMessage("commit for " + idP2).call();
insertAndAdd(points3);
@SuppressWarnings("unused") final RevCommit c3 = geogig.command(CommitOp.class).setMessage("commit for " + idP3).call();
geogig.command(CheckoutOp.class).setSource("master").call();
insertAndAdd(lines1);
@SuppressWarnings("unused") final RevCommit c4 = geogig.command(CommitOp.class).setMessage("commit for " + idL1).call();
Ref branch1 = geogig.command(RefParse.class).setName("branch1").call().get();
MergeReport mergeReport = geogig.command(MergeOp.class).addCommit(Suppliers.ofInstance(branch1.getObjectId())).setMessage("My merge message.").call();
try {
geogig.command(SquashOp.class).setSince(c2).setUntil(mergeReport.getMergeCommit()).setMessage("Squashed").call();
} catch (IllegalArgumentException e) {
assertTrue(e.getMessage().equals("Cannot reach 'since' from 'until' commit through first parentage"));
}
}
use of org.locationtech.geogig.api.porcelain.MergeOp.MergeReport in project GeoGig by boundlessgeo.
the class MergeOpTest method testMergeFastForwardSecondCase.
@Test
public void testMergeFastForwardSecondCase() throws Exception {
// Create the following revision graph
// o - master - HEAD
// .\
// . o - branch1 - Points 1 added
// create branch1 and checkout
geogig.command(UpdateRef.class).setName(Ref.HEADS_PREFIX + "branch1").setNewValue(ObjectId.NULL).call();
geogig.command(UpdateSymRef.class).setName(Ref.HEAD).setNewValue(Ref.HEADS_PREFIX + "branch1").call();
insertAndAdd(points1);
final RevCommit c1 = geogig.command(CommitOp.class).setMessage("commit for " + idP1).call();
// checkout master
geogig.command(UpdateSymRef.class).setName(Ref.HEAD).setNewValue(Ref.HEADS_PREFIX + "master").call();
// Merge branch1 into master to create the following revision graph
// o
// |
// o - master - HEAD - branch1 - Points 1 added
Ref branch1 = geogig.command(RefParse.class).setName("branch1").call().get();
final MergeReport mergeReport = geogig.command(MergeOp.class).addCommit(Suppliers.ofInstance(branch1.getObjectId())).call();
RevTree mergedTree = repo.getTree(mergeReport.getMergeCommit().getTreeId());
String path = appendChild(pointsName, points1.getIdentifier().getID());
assertTrue(repo.command(FindTreeChild.class).setParent(mergedTree).setChildPath(path).call().isPresent());
Iterator<RevCommit> log = geogig.command(LogOp.class).call();
// Commit 1
RevCommit logC1 = log.next();
assertEquals(c1.getAuthor(), logC1.getAuthor());
assertEquals(c1.getCommitter(), logC1.getCommitter());
assertEquals(c1.getMessage(), logC1.getMessage());
assertEquals(c1.getTreeId(), logC1.getTreeId());
}
use of org.locationtech.geogig.api.porcelain.MergeOp.MergeReport in project GeoGig by boundlessgeo.
the class MergeOpTest method testMergeNoCommitMessage.
@Test
public void testMergeNoCommitMessage() throws Exception {
// Create the following revision graph
// o
// |
// o - Points 1 added
// |\
// | o - branch1 - Points 2 added
// |
// o - Points 3 added
// |
// o - master - HEAD - Lines 1 added
insertAndAdd(points1);
final RevCommit c1 = geogig.command(CommitOp.class).setMessage("commit for " + idP1).call();
// create branch1 and checkout
geogig.command(BranchCreateOp.class).setAutoCheckout(true).setName("branch1").call();
insertAndAdd(points2);
final RevCommit c2 = geogig.command(CommitOp.class).setMessage("commit for " + idP2).call();
// checkout master
geogig.command(CheckoutOp.class).setSource("master").call();
insertAndAdd(points3);
final RevCommit c3 = geogig.command(CommitOp.class).setMessage("commit for " + idP3).call();
insertAndAdd(lines1);
final RevCommit c4 = geogig.command(CommitOp.class).setMessage("commit for " + idL1).call();
// Merge branch1 into master to create the following revision graph
// o
// |
// o - Points 1 added
// |\
// | o - branch1 - Points 2 added
// | |
// o | - Points 3 added
// | |
// o | - Lines 1 added
// |/
// o - master - HEAD - Merge commit
Ref branch1 = geogig.command(RefParse.class).setName("branch1").call().get();
final MergeReport mergeReport = geogig.command(MergeOp.class).addCommit(Suppliers.ofInstance(branch1.getObjectId())).call();
RevTree mergedTree = repo.getTree(mergeReport.getMergeCommit().getTreeId());
String path = appendChild(pointsName, points2.getIdentifier().getID());
assertTrue(repo.command(FindTreeChild.class).setParent(mergedTree).setChildPath(path).call().isPresent());
path = appendChild(pointsName, points1.getIdentifier().getID());
assertTrue(repo.command(FindTreeChild.class).setParent(mergedTree).setChildPath(path).call().isPresent());
path = appendChild(pointsName, points3.getIdentifier().getID());
assertTrue(repo.command(FindTreeChild.class).setParent(mergedTree).setChildPath(path).call().isPresent());
path = appendChild(linesName, lines1.getIdentifier().getID());
assertTrue(repo.command(FindTreeChild.class).setParent(mergedTree).setChildPath(path).call().isPresent());
Iterator<RevCommit> log = geogig.command(LogOp.class).setFirstParentOnly(true).call();
// Commit 4
RevCommit logC4 = log.next();
assertTrue(logC4.getMessage().contains("refs/heads/branch1"));
assertEquals(2, logC4.getParentIds().size());
assertEquals(c4.getId(), logC4.getParentIds().get(0));
assertEquals(c2.getId(), logC4.getParentIds().get(1));
// Commit 3
RevCommit logC3 = log.next();
assertEquals(c4.getAuthor(), logC3.getAuthor());
assertEquals(c4.getCommitter(), logC3.getCommitter());
assertEquals(c4.getMessage(), logC3.getMessage());
assertEquals(c4.getTreeId(), logC3.getTreeId());
// Commit 2
RevCommit logC2 = log.next();
assertEquals(c3.getAuthor(), logC2.getAuthor());
assertEquals(c3.getCommitter(), logC2.getCommitter());
assertEquals(c3.getMessage(), logC2.getMessage());
assertEquals(c3.getTreeId(), logC2.getTreeId());
// Commit 1
RevCommit logC1 = log.next();
assertEquals(c1.getAuthor(), logC1.getAuthor());
assertEquals(c1.getCommitter(), logC1.getCommitter());
assertEquals(c1.getMessage(), logC1.getMessage());
assertEquals(c1.getTreeId(), logC1.getTreeId());
}
use of org.locationtech.geogig.api.porcelain.MergeOp.MergeReport in project GeoGig by boundlessgeo.
the class MergeWebOp method run.
/**
* Runs the command and builds the appropriate response.
*
* @param context - the context to use for this command
*
* @throws CommandSpecException
*/
@Override
public void run(CommandContext context) {
if (this.getTransactionId() == null) {
throw new CommandSpecException("No transaction was specified, merge requires a transaction to preserve the stability of the repository.");
} else if (this.commit == null) {
throw new CommandSpecException("No commits were specified for merging.");
}
final GeogigTransaction transaction = (GeogigTransaction) this.getCommandLocator(context);
final Optional<Ref> currHead = transaction.command(RefParse.class).setName(Ref.HEAD).call();
if (!currHead.isPresent()) {
throw new CommandSpecException("Repository has no HEAD, can't merge.");
}
MergeOp merge = transaction.command(MergeOp.class);
merge.setAuthor(authorName.orNull(), authorEmail.orNull());
final Optional<ObjectId> oid = transaction.command(RevParse.class).setRefSpec(commit).call();
if (oid.isPresent()) {
merge.addCommit(Suppliers.ofInstance(oid.get()));
} else {
throw new CommandSpecException("Couldn't resolve '" + commit + "' to a commit.");
}
try {
final MergeReport report = merge.setNoCommit(noCommit).call();
context.setResponseContent(new CommandResponse() {
@Override
public void write(ResponseWriter out) throws Exception {
out.start();
out.writeMergeResponse(Optional.fromNullable(report.getMergeCommit()), report.getReport().get(), transaction, report.getOurs(), report.getPairs().get(0).getTheirs(), report.getPairs().get(0).getAncestor());
out.finish();
}
});
} catch (Exception e) {
final RevCommit ours = context.getGeoGIG().getRepository().getCommit(currHead.get().getObjectId());
final RevCommit theirs = context.getGeoGIG().getRepository().getCommit(oid.get());
final Optional<ObjectId> ancestor = transaction.command(FindCommonAncestor.class).setLeft(ours).setRight(theirs).call();
context.setResponseContent(new CommandResponse() {
final MergeScenarioReport report = transaction.command(ReportMergeScenarioOp.class).setMergeIntoCommit(ours).setToMergeCommit(theirs).call();
@Override
public void write(ResponseWriter out) throws Exception {
out.start();
Optional<RevCommit> mergeCommit = Optional.absent();
out.writeMergeResponse(mergeCommit, report, transaction, ours.getId(), theirs.getId(), ancestor.get());
out.finish();
}
});
}
}
use of org.locationtech.geogig.api.porcelain.MergeOp.MergeReport in project GeoGig by boundlessgeo.
the class ResponseWriter method writePullResponse.
public void writePullResponse(PullResult result, Iterator<DiffEntry> iter, Context geogig) throws XMLStreamException {
out.writeStartElement("Pull");
writeFetchResponse(result.getFetchResult());
if (iter != null) {
writeElement("Remote", result.getRemoteName());
writeElement("Ref", result.getNewRef().localName());
int added = 0;
int removed = 0;
int modified = 0;
while (iter.hasNext()) {
DiffEntry entry = iter.next();
if (entry.changeType() == ChangeType.ADDED) {
added++;
} else if (entry.changeType() == ChangeType.MODIFIED) {
modified++;
} else if (entry.changeType() == ChangeType.REMOVED) {
removed++;
}
}
writeElement("Added", Integer.toString(added));
writeElement("Modified", Integer.toString(modified));
writeElement("Removed", Integer.toString(removed));
}
if (result.getMergeReport().isPresent() && result.getMergeReport().get().getReport().isPresent()) {
MergeReport report = result.getMergeReport().get();
writeMergeResponse(Optional.fromNullable(report.getMergeCommit()), report.getReport().get(), geogig, report.getOurs(), report.getPairs().get(0).getTheirs(), report.getPairs().get(0).getAncestor());
}
out.writeEndElement();
}
Aggregations