use of org.locationtech.geogig.api.porcelain.NothingToCommitException 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.NothingToCommitException 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.NothingToCommitException in project GeoGig by boundlessgeo.
the class Merge method runInternal.
/**
* Executes the merge command using the provided options.
*/
@Override
public void runInternal(GeogigCLI cli) throws IOException {
checkParameter(commits.size() > 0 || abort, "No commits provided to merge.");
ConsoleReader console = cli.getConsole();
final GeoGIG geogig = cli.getGeogig();
Ansi ansi = newAnsi(console.getTerminal());
if (abort) {
Optional<Ref> ref = geogig.command(RefParse.class).setName(Ref.ORIG_HEAD).call();
if (!ref.isPresent()) {
throw new CommandFailedException("There is no merge to abort <ORIG_HEAD missing>.");
}
geogig.command(ResetOp.class).setMode(ResetMode.HARD).setCommit(Suppliers.ofInstance(ref.get().getObjectId())).call();
console.println("Merge aborted successfully.");
return;
}
RevCommit commit;
try {
MergeOp merge = geogig.command(MergeOp.class);
merge.setOurs(ours).setTheirs(theirs).setNoCommit(noCommit);
merge.setMessage(message).setProgressListener(cli.getProgressListener());
for (String commitish : commits) {
Optional<ObjectId> commitId;
commitId = geogig.command(RevParse.class).setRefSpec(commitish).call();
checkParameter(commitId.isPresent(), "Commit not found '%s'", commitish);
merge.addCommit(Suppliers.ofInstance(commitId.get()));
}
MergeReport report = merge.call();
commit = report.getMergeCommit();
} catch (RuntimeException e) {
if (e instanceof NothingToCommitException || e instanceof IllegalArgumentException || e instanceof IllegalStateException) {
throw new CommandFailedException(e.getMessage(), e);
}
throw e;
}
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.NothingToCommitException 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.NothingToCommitException in project GeoGig by boundlessgeo.
the class TransactionEnd method updateRefs.
private void updateRefs() {
final Optional<Ref> currHead = command(RefParse.class).setName(Ref.HEAD).call();
final String currentBranch;
if (currHead.isPresent() && currHead.get() instanceof SymRef) {
currentBranch = ((SymRef) currHead.get()).getTarget();
} else {
currentBranch = "";
}
ImmutableSet<Ref> changedRefs = getChangedRefs();
// Lock the repository
try {
refDatabase().lock();
} catch (TimeoutException e) {
Throwables.propagate(e);
}
try {
// Update refs
for (Ref ref : changedRefs) {
if (!ref.getName().startsWith(Ref.REFS_PREFIX)) {
continue;
}
Ref updatedRef = ref;
Optional<Ref> repoRef = command(RefParse.class).setName(ref.getName()).call();
if (repoRef.isPresent() && repositoryChanged(repoRef.get())) {
if (rebase) {
// Try to rebase
transaction.command(CheckoutOp.class).setSource(ref.getName()).setForce(true).call();
try {
transaction.command(RebaseOp.class).setUpstream(Suppliers.ofInstance(repoRef.get().getObjectId())).call();
} catch (RebaseConflictsException e) {
Throwables.propagate(e);
}
updatedRef = transaction.command(RefParse.class).setName(ref.getName()).call().get();
} else {
// sync transactions have to use merge to prevent divergent history
transaction.command(CheckoutOp.class).setSource(ref.getName()).setForce(true).call();
try {
transaction.command(MergeOp.class).setAuthor(authorName.orNull(), authorEmail.orNull()).addCommit(Suppliers.ofInstance(repoRef.get().getObjectId())).call();
} catch (NothingToCommitException e) {
// The repo commit is already in our history, this is a fast
// forward.
}
updatedRef = transaction.command(RefParse.class).setName(ref.getName()).call().get();
}
}
LOGGER.debug(String.format("commit %s %s -> %s", ref.getName(), ref.getObjectId(), updatedRef.getObjectId()));
command(UpdateRef.class).setName(ref.getName()).setNewValue(updatedRef.getObjectId()).call();
if (currentBranch.equals(ref.getName())) {
// Update HEAD, WORK_HEAD and STAGE_HEAD
command(UpdateSymRef.class).setName(Ref.HEAD).setNewValue(ref.getName()).call();
command(UpdateRef.class).setName(Ref.WORK_HEAD).setNewValue(updatedRef.getObjectId()).call();
command(UpdateRef.class).setName(Ref.STAGE_HEAD).setNewValue(updatedRef.getObjectId()).call();
}
}
// TODO: What happens if there are unstaged or staged changes in the repository when
// a transaction is committed?
} finally {
// Unlock the repository
refDatabase().unlock();
}
}
Aggregations