use of org.locationtech.geogig.api.plumbing.merge.Conflict in project GeoGig by boundlessgeo.
the class RevertOpTest method testRevertModifiedFeatureConflictSolveAndContinue.
@Test
public void testRevertModifiedFeatureConflictSolveAndContinue() throws Exception {
ObjectId oId1 = insertAndAdd(points1);
RevCommit c1 = geogig.command(CommitOp.class).setMessage("commit for " + idP1).call();
insertAndAdd(points1_modified);
RevCommit c2 = geogig.command(CommitOp.class).setMessage("commit for modified " + idP1).call();
Feature points1_modifiedB = feature(pointsType, idP1, "StringProp1_2", new Integer(2000), "POINT(1 1)");
insertAndAdd(points1_modifiedB);
RevCommit c3 = geogig.command(CommitOp.class).setMessage("commit for modified " + idP1 + " again").call();
try {
geogig.command(RevertOp.class).addCommit(Suppliers.ofInstance(c2.getId())).call();
fail();
} catch (RevertConflictsException e) {
assertTrue(e.getMessage().contains(idP1));
}
Optional<Ref> ref = geogig.command(RefParse.class).setName(Ref.ORIG_HEAD).call();
assertTrue(ref.isPresent());
assertEquals(c3.getId(), ref.get().getObjectId());
List<Conflict> conflicts = geogig.command(ConflictsReadOp.class).call();
assertEquals(1, conflicts.size());
String path = NodeRef.appendChild(pointsName, idP1);
assertEquals(conflicts.get(0).getPath(), path);
assertEquals(conflicts.get(0).getOurs(), RevFeatureBuilder.build(points1_modifiedB).getId());
assertEquals(conflicts.get(0).getTheirs(), RevFeatureBuilder.build(points1).getId());
// solve, and continue
insert(points1);
geogig.command(AddOp.class).call();
geogig.command(RevertOp.class).setContinue(true).call();
Iterator<RevCommit> log = geogig.command(LogOp.class).call();
RevCommit logCommit = log.next();
assertEquals(c2.getAuthor().getName(), logCommit.getAuthor().getName());
assertEquals(c2.getCommitter().getName(), logCommit.getCommitter().getName());
assertEquals("Revert '" + c2.getMessage() + "'\nThis reverts " + c2.getId().toString(), logCommit.getMessage());
assertNotSame(c2.getCommitter().getTimestamp(), logCommit.getCommitter().getTimestamp());
assertNotSame(c2.getTreeId(), logCommit.getTreeId());
final Optional<Ref> currHead = geogig.command(RefParse.class).setName(Ref.HEAD).call();
final Optional<ObjectId> headTreeId = geogig.command(ResolveTreeish.class).setTreeish(currHead.get().getObjectId()).call();
RevTree headTree = repo.getTree(headTreeId.get());
Optional<NodeRef> points1Node = geogig.command(FindTreeChild.class).setChildPath(NodeRef.appendChild(pointsName, idP1)).setParent(headTree).call();
assertTrue(points1Node.isPresent());
assertEquals(oId1, points1Node.get().getNode().getObjectId());
assertEquals(c3.getId(), log.next().getId());
assertEquals(c2.getId(), log.next().getId());
assertEquals(c1.getId(), log.next().getId());
assertFalse(log.hasNext());
}
use of org.locationtech.geogig.api.plumbing.merge.Conflict in project GeoGig by boundlessgeo.
the class RemoveOp method _call.
/**
* @see java.util.concurrent.Callable#call()
*/
protected WorkingTree _call() {
// Check that all paths are valid and exist
for (String pathToRemove : pathsToRemove) {
NodeRef.checkValidPath(pathToRemove);
Optional<NodeRef> node;
node = command(FindTreeChild.class).setParent(workingTree().getTree()).setIndex(true).setChildPath(pathToRemove).call();
List<Conflict> conflicts = index().getConflicted(pathToRemove);
if (conflicts.size() > 0) {
for (Conflict conflict : conflicts) {
stagingDatabase().removeConflict(null, conflict.getPath());
}
} else {
Preconditions.checkArgument(node.isPresent(), "pathspec '%s' did not match any feature or tree", pathToRemove);
}
}
// separate trees from features an delete accordingly
for (String pathToRemove : pathsToRemove) {
Optional<NodeRef> node = command(FindTreeChild.class).setParent(workingTree().getTree()).setIndex(true).setChildPath(pathToRemove).call();
if (!node.isPresent()) {
continue;
}
switch(node.get().getType()) {
case TREE:
workingTree().delete(pathToRemove);
break;
case FEATURE:
String parentPath = NodeRef.parentPath(pathToRemove);
String name = node.get().name();
workingTree().delete(parentPath, name);
break;
default:
break;
}
final long numChanges = workingTree().countUnstaged(pathToRemove).count();
Iterator<DiffEntry> unstaged = workingTree().getUnstaged(pathToRemove);
index().stage(getProgressListener(), unstaged, numChanges);
}
return workingTree();
}
use of org.locationtech.geogig.api.plumbing.merge.Conflict in project GeoGig by boundlessgeo.
the class RevertOp method applyNextCommit.
private boolean applyNextCommit(boolean useCommitChanges) {
File rebaseFolder = getRevertFolder();
File nextFile = new File(rebaseFolder, "next");
Repository repository = repository();
try {
String idx = Files.readFirstLine(nextFile, Charsets.UTF_8);
File commitFile = new File(rebaseFolder, idx);
if (commitFile.exists()) {
String commitId = Files.readFirstLine(commitFile, Charsets.UTF_8);
RevCommit commit = repository.getCommit(ObjectId.valueOf(commitId));
List<Conflict> conflicts = Lists.newArrayList();
if (useCommitChanges) {
conflicts = applyRevertedChanges(commit);
}
if (createCommit && conflicts.isEmpty()) {
createCommit(commit);
} else {
workingTree().updateWorkHead(repository.index().getTree().getId());
if (!conflicts.isEmpty()) {
// mark conflicted elements
command(ConflictsWriteOp.class).setConflicts(conflicts).call();
// created exception message
StringBuilder msg = new StringBuilder();
msg.append("error: could not apply ");
msg.append(commit.getId().toString().substring(0, 7));
msg.append(" " + commit.getMessage() + "\n");
for (Conflict conflict : conflicts) {
msg.append("CONFLICT: conflict in " + conflict.getPath() + "\n");
}
throw new RevertConflictsException(msg.toString());
}
}
commitFile.delete();
int newIdx = Integer.parseInt(idx) + 1;
Files.write(Integer.toString(newIdx), nextFile, Charsets.UTF_8);
return true;
} else {
return false;
}
} catch (IOException e) {
throw new IllegalStateException("Cannot read/write revert commits index file");
}
}
use of org.locationtech.geogig.api.plumbing.merge.Conflict in project GeoGig by boundlessgeo.
the class ResponseWriter method writeUnmerged.
public void writeUnmerged(List<Conflict> conflicts, int start, int length) throws XMLStreamException {
Iterator<Conflict> entries = conflicts.iterator();
Iterators.advance(entries, start);
if (length < 0) {
length = Integer.MAX_VALUE;
}
for (int i = 0; i < length && entries.hasNext(); i++) {
Conflict entry = entries.next();
out.writeStartElement("unmerged");
writeElement("changeType", "CONFLICT");
writeElement("path", entry.getPath());
writeElement("ours", entry.getOurs().toString());
writeElement("theirs", entry.getTheirs().toString());
writeElement("ancestor", entry.getAncestor().toString());
out.writeEndElement();
}
}
use of org.locationtech.geogig.api.plumbing.merge.Conflict in project GeoGig by boundlessgeo.
the class Add method runInternal.
/**
* Executes the add 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();
final ConsoleReader console = cli.getConsole();
String pathFilter = null;
if (patterns.size() == 1) {
pathFilter = patterns.get(0);
} else if (patterns.size() > 1) {
throw new InvalidParameterException("Only a single path is supported so far");
}
List<Conflict> conflicts = geogig.command(ConflictsReadOp.class).call();
console.print("Counting unstaged elements...");
console.flush();
DiffObjectCount unstaged = geogig.getRepository().workingTree().countUnstaged(pathFilter);
if (0 == unstaged.count() && conflicts.isEmpty()) {
console.println();
console.println("No unstaged elements, exiting.");
return;
} else {
console.println(String.valueOf(unstaged.count()));
}
console.println("Staging changes...");
AddOp op = geogig.command(AddOp.class);
if (patterns.size() == 1) {
op.addPattern(patterns.get(0));
}
WorkingTree workTree = op.setUpdateOnly(updateOnly).setProgressListener(cli.getProgressListener()).call();
DiffObjectCount staged = geogig.getRepository().index().countStaged(null);
unstaged = workTree.countUnstaged(null);
console.println(staged.featureCount() + " features and " + staged.treeCount() + " trees staged for commit");
console.println(unstaged.featureCount() + " features and " + unstaged.treeCount() + " trees not staged for commit");
}
Aggregations