use of org.locationtech.geogig.api.porcelain.CommitOp in project GeoGig by boundlessgeo.
the class CommitOpTest method testCommitWithAllOption.
@Test
public void testCommitWithAllOption() throws Exception {
try {
geogig.command(AddOp.class).addPattern(".").call();
geogig.command(CommitOp.class).call();
fail("expected NothingToCommitException");
} catch (NothingToCommitException e) {
assertTrue(true);
}
insertAndAdd(points1);
geogig.command(AddOp.class).addPattern(".").call();
RevCommit commit = geogig.command(CommitOp.class).call();
ObjectId oid = insertAndAdd(points1_modified);
CommitOp commitCommand = geogig.command(CommitOp.class);
commit = commitCommand.setAll(true).call();
assertNotNull(commit);
assertNotNull(commit.getParentIds());
assertEquals(1, commit.getParentIds().size());
assertNotNull(commit.getId());
ObjectId treeId = commit.getTreeId();
assertNotNull(treeId);
RevTree root = repo.getTree(treeId);
assertNotNull(root);
Optional<Node> typeTreeId = repo.getTreeChild(root, pointsName);
assertTrue(typeTreeId.isPresent());
RevTree typeTree = repo.getTree(typeTreeId.get().getObjectId());
assertNotNull(typeTree);
String featureId = points1.getIdentifier().getID();
Optional<Node> featureBlobId = repo.getTreeChild(root, NodeRef.appendChild(pointsName, featureId));
assertTrue(featureBlobId.isPresent());
assertEquals(oid, featureBlobId.get().getObjectId());
ObjectId commitId = geogig.command(RevParse.class).setRefSpec(Ref.HEAD).call().get();
assertEquals(commit.getId(), commitId);
}
use of org.locationtech.geogig.api.porcelain.CommitOp in project GeoGig by boundlessgeo.
the class CommitOpTest method testCommitEmptyTreeOnNonEmptyRepo.
@Test
public void testCommitEmptyTreeOnNonEmptyRepo() throws Exception {
insertAndAdd(points1, points2);
geogig.command(CommitOp.class).call();
// insertAndAdd(lines1, lines2);
WorkingTree workingTree = geogig.getRepository().workingTree();
final String emptyTreeName = "emptyTree";
workingTree.createTypeTree(emptyTreeName, pointsType);
{
List<DiffEntry> unstaged = toList(workingTree.getUnstaged(null));
assertEquals(unstaged.toString(), 1, unstaged.size());
// assertEquals(NodeRef.ROOT, unstaged.get(0).newName());
assertEquals(emptyTreeName, unstaged.get(0).newName());
}
geogig.command(AddOp.class).call();
{
StagingArea index = geogig.getRepository().index();
List<DiffEntry> staged = toList(index.getStaged(null));
assertEquals(staged.toString(), 1, staged.size());
// assertEquals(NodeRef.ROOT, staged.get(0).newName());
assertEquals(emptyTreeName, staged.get(0).newName());
}
CommitOp commitCommand = geogig.command(CommitOp.class);
RevCommit commit = commitCommand.call();
assertNotNull(commit);
RevTree head = geogig.command(RevObjectParse.class).setObjectId(commit.getTreeId()).call(RevTree.class).get();
Optional<NodeRef> ref = geogig.command(FindTreeChild.class).setChildPath(emptyTreeName).setParent(head).call();
assertTrue(ref.isPresent());
}
use of org.locationtech.geogig.api.porcelain.CommitOp in project GeoGig by boundlessgeo.
the class CommitOpTest method testCommitWithCustomAuthorAndCommitter.
@Test
public void testCommitWithCustomAuthorAndCommitter() throws Exception {
try {
geogig.command(AddOp.class).addPattern(".").call();
geogig.command(CommitOp.class).call();
fail("expected NothingToCommitException");
} catch (NothingToCommitException e) {
assertTrue(true);
}
ObjectId oid1 = insertAndAdd(points1);
ObjectId oid2 = insertAndAdd(points2);
geogig.command(AddOp.class).addPattern(".").call();
CommitOp commitCommand = geogig.command(CommitOp.class);
commitCommand.setAuthor("John Doe", "John@Doe.com");
commitCommand.setCommitter("Jane Doe", "Jane@Doe.com");
RevCommit commit = commitCommand.call();
assertNotNull(commit);
assertNotNull(commit.getParentIds());
assertEquals(0, commit.getParentIds().size());
assertFalse(commit.parentN(0).isPresent());
assertNotNull(commit.getId());
assertEquals("John Doe", commit.getAuthor().getName().get());
assertEquals("John@Doe.com", commit.getAuthor().getEmail().get());
assertEquals("Jane Doe", commit.getCommitter().getName().get());
assertEquals("Jane@Doe.com", commit.getCommitter().getEmail().get());
ObjectId treeId = commit.getTreeId();
assertNotNull(treeId);
RevTree root = repo.getTree(treeId);
assertNotNull(root);
Optional<Node> typeTreeId = repo.getTreeChild(root, pointsName);
assertTrue(typeTreeId.isPresent());
RevTree typeTree = repo.getTree(typeTreeId.get().getObjectId());
assertNotNull(typeTree);
String featureId = points1.getIdentifier().getID();
Optional<Node> featureBlobId = repo.getTreeChild(root, NodeRef.appendChild(pointsName, featureId));
assertTrue(featureBlobId.isPresent());
assertEquals(oid1, featureBlobId.get().getObjectId());
featureId = points2.getIdentifier().getID();
featureBlobId = repo.getTreeChild(root, NodeRef.appendChild(pointsName, featureId));
assertTrue(featureBlobId.isPresent());
assertEquals(oid2, featureBlobId.get().getObjectId());
ObjectId commitId = geogig.command(RevParse.class).setRefSpec(Ref.HEAD).call().get();
assertEquals(commit.getId(), commitId);
}
use of org.locationtech.geogig.api.porcelain.CommitOp in project GeoGig by boundlessgeo.
the class Commit method runInternal.
/**
* Executes the commit command using the provided options.
*
* @param cli
* @see org.locationtech.geogig.cli.AbstractCommand#runInternal(org.locationtech.geogig.cli.GeogigCLI)
*/
@Override
public void runInternal(GeogigCLI cli) throws IOException {
final GeoGIG geogig = cli.getGeogig();
if (message == null || Strings.isNullOrEmpty(message)) {
message = geogig.command(ReadMergeCommitMessageOp.class).call();
}
checkParameter(!Strings.isNullOrEmpty(message) || commitToReuse != null || amend, "No commit message provided");
ConsoleReader console = cli.getConsole();
Ansi ansi = newAnsi(console.getTerminal());
RevCommit commit;
try {
CommitOp commitOp = geogig.command(CommitOp.class).setMessage(message).setAmend(amend);
if (commitTimestamp != null && !Strings.isNullOrEmpty(commitTimestamp)) {
Long millis = geogig.command(ParseTimestamp.class).setString(commitTimestamp).call();
commitOp.setCommitterTimestamp(millis.longValue());
}
if (commitToReuse != null) {
Optional<ObjectId> commitId = geogig.command(RevParse.class).setRefSpec(commitToReuse).call();
checkParameter(commitId.isPresent(), "Provided reference does not exist");
TYPE type = geogig.command(ResolveObjectType.class).setObjectId(commitId.get()).call();
checkParameter(TYPE.COMMIT.equals(type), "Provided reference does not resolve to a commit");
commitOp.setCommit(geogig.getRepository().getCommit(commitId.get()));
}
commit = commitOp.setPathFilters(pathFilters).setProgressListener(cli.getProgressListener()).call();
} catch (NothingToCommitException noChanges) {
throw new CommandFailedException(noChanges.getMessage(), noChanges);
}
final ObjectId parentId = commit.parentN(0).or(ObjectId.NULL);
console.println("[" + commit.getId() + "] " + commit.getMessage());
console.print("Committed, counting objects...");
Iterator<DiffEntry> diff = geogig.command(DiffOp.class).setOldVersion(parentId).setNewVersion(commit.getId()).call();
int adds = 0, deletes = 0, changes = 0;
DiffEntry diffEntry;
while (diff.hasNext()) {
diffEntry = diff.next();
switch(diffEntry.changeType()) {
case ADDED:
++adds;
break;
case REMOVED:
++deletes;
break;
case MODIFIED:
++changes;
break;
}
}
ansi.fg(Color.GREEN).a(adds).reset().a(" features added, ").fg(Color.YELLOW).a(changes).reset().a(" changed, ").fg(Color.RED).a(deletes).reset().a(" deleted.").reset().newline();
console.print(ansi.toString());
}
use of org.locationtech.geogig.api.porcelain.CommitOp in project GeoGig by boundlessgeo.
the class CommitOpTest method testCommitEmptyTreeOnEmptyRepo.
@Test
public void testCommitEmptyTreeOnEmptyRepo() throws Exception {
WorkingTree workingTree = geogig.getRepository().workingTree();
final String emptyTreeName = "emptyTree";
workingTree.createTypeTree(emptyTreeName, pointsType);
geogig.command(AddOp.class).addPattern(emptyTreeName).call();
CommitOp commitCommand = geogig.command(CommitOp.class);
RevCommit commit = commitCommand.call();
assertNotNull(commit);
RevTree head = geogig.command(RevObjectParse.class).setObjectId(commit.getTreeId()).call(RevTree.class).get();
Optional<NodeRef> ref = geogig.command(FindTreeChild.class).setChildPath(emptyTreeName).setParent(head).call();
assertTrue(ref.isPresent());
}
Aggregations