use of org.locationtech.geogig.api.porcelain.BlameReport in project GeoGig by boundlessgeo.
the class BlameOpTest method testBlameChangedByLastCommit.
@Test
public void testBlameChangedByLastCommit() throws Exception {
insertAndAdd(points1);
geogig.command(CommitOp.class).call();
insertAndAdd(points1_modified);
RevCommit secondCommit = geogig.command(CommitOp.class).call();
String path = NodeRef.appendChild(pointsName, idP1);
BlameReport report = geogig.command(BlameOp.class).setPath(path).call();
Map<String, ValueAndCommit> changes = report.getChanges();
assertEquals(3, changes.size());
Collection<ValueAndCommit> commits = changes.values();
for (ValueAndCommit valueAndCommit : commits) {
assertEquals(secondCommit, valueAndCommit.commit);
}
}
use of org.locationtech.geogig.api.porcelain.BlameReport in project GeoGig by boundlessgeo.
the class BlameOpTest method testBlameChangedByASingleCommit.
@Test
public void testBlameChangedByASingleCommit() throws Exception {
insertAndAdd(points1);
RevCommit firstCommit = geogig.command(CommitOp.class).call();
String path = NodeRef.appendChild(pointsName, idP1);
BlameReport report = geogig.command(BlameOp.class).setPath(path).call();
Map<String, ValueAndCommit> changes = report.getChanges();
assertEquals(3, changes.size());
Collection<ValueAndCommit> commits = changes.values();
for (ValueAndCommit valueAndCommit : commits) {
assertEquals(firstCommit, valueAndCommit.commit);
}
}
use of org.locationtech.geogig.api.porcelain.BlameReport in project GeoGig by boundlessgeo.
the class Blame method runInternal.
@Override
public void runInternal(GeogigCLI cli) throws IOException {
checkParameter(paths.size() < 2, "Only one path allowed");
checkParameter(!paths.isEmpty(), "A path must be specified");
ConsoleReader console = cli.getConsole();
GeoGIG geogig = cli.getGeogig();
String path = paths.get(0);
try {
BlameReport report = geogig.command(BlameOp.class).setPath(path).call();
Map<String, ValueAndCommit> changes = report.getChanges();
Iterator<String> iter = changes.keySet().iterator();
while (iter.hasNext()) {
String attrib = iter.next();
ValueAndCommit valueAndCommit = changes.get(attrib);
RevCommit commit = valueAndCommit.commit;
Optional<?> value = valueAndCommit.value;
if (porcelain) {
StringBuilder sb = new StringBuilder();
sb.append(attrib).append(' ');
sb.append(commit.getId().toString()).append(' ');
sb.append(commit.getAuthor().getName().or("")).append(' ');
sb.append(commit.getAuthor().getEmail().or("")).append(' ');
sb.append(Long.toString(commit.getAuthor().getTimestamp())).append(' ');
sb.append(Integer.toString(commit.getAuthor().getTimeZoneOffset()));
if (!noValues) {
sb.append(" ").append(TextValueSerializer.asString(Optional.of((Object) value.orNull())));
}
console.println(sb.toString());
} else {
Ansi ansi = newAnsi(console.getTerminal());
ansi.fg(GREEN).a(attrib + ": ").reset();
if (!noValues) {
String s = value.isPresent() ? value.get().toString() : "NULL";
ansi.fg(YELLOW).a(s).a(" ").reset();
}
ansi.a(commit.getId().toString().substring(0, 7)).a(" ");
ansi.a(commit.getAuthor().getName().or("")).a(" ");
ansi.a(commit.getAuthor().getEmail().or("")).a(" ");
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
String date = formatter.format(new Date(commit.getAuthor().getTimestamp() + commit.getAuthor().getTimeZoneOffset()));
ansi.a(date);
console.println(ansi.toString());
}
}
} catch (BlameException e) {
switch(e.statusCode) {
case FEATURE_NOT_FOUND:
throw new InvalidParameterException("The supplied path does not exist", e);
case PATH_NOT_FEATURE:
throw new InvalidParameterException("The supplied path does not resolve to a feature", e);
}
}
}
use of org.locationtech.geogig.api.porcelain.BlameReport in project GeoGig by boundlessgeo.
the class BlameWebOp method run.
/**
* Runs the command and builds the appropriate response.
*
* @param context - the context to use for this command
*/
@Override
public void run(CommandContext context) {
final Context geogig = this.getCommandLocator(context);
Optional<ObjectId> commit = Optional.absent();
if (branchOrCommit != null) {
commit = geogig.command(RevParse.class).setRefSpec(branchOrCommit).call();
if (!commit.isPresent()) {
throw new CommandSpecException("Could not resolve branch or commit");
}
}
try {
final BlameReport report = geogig.command(BlameOp.class).setPath(path).setCommit(commit.orNull()).call();
context.setResponseContent(new CommandResponse() {
@Override
public void write(ResponseWriter out) throws Exception {
out.start();
try {
out.writeBlameReport(report);
} catch (XMLStreamException e) {
throw new CommandSpecException("Error writing stream.");
}
out.finish();
}
});
} catch (BlameException e) {
switch(e.statusCode) {
case PATH_NOT_FEATURE:
throw new CommandSpecException("The supplied path does not resolve to a feature");
case FEATURE_NOT_FOUND:
throw new CommandSpecException("The supplied path does not exist");
}
}
}
use of org.locationtech.geogig.api.porcelain.BlameReport in project GeoGig by boundlessgeo.
the class BlameOpTest method testBlameRemovedAndAdded.
@Test
public void testBlameRemovedAndAdded() throws Exception {
insertAndAdd(points1);
RevCommit firstCommit = geogig.command(CommitOp.class).call();
deleteAndAdd(points1);
RevCommit secondCommit = geogig.command(CommitOp.class).call();
insertAndAdd(points1);
RevCommit thirdCommit = geogig.command(CommitOp.class).call();
String path = NodeRef.appendChild(pointsName, idP1);
BlameReport report = geogig.command(BlameOp.class).setPath(path).call();
Map<String, ValueAndCommit> changes = report.getChanges();
assertEquals(3, changes.size());
Collection<ValueAndCommit> commits = changes.values();
for (ValueAndCommit valueAndCommit : commits) {
assertEquals(thirdCommit, valueAndCommit.commit);
}
try {
report = geogig.command(BlameOp.class).setPath(path).setCommit(secondCommit.getId()).call();
fail();
} catch (BlameException e) {
assertTrue(e.statusCode == StatusCode.FEATURE_NOT_FOUND);
}
report = geogig.command(BlameOp.class).setPath(path).setCommit(firstCommit.getId()).call();
changes = report.getChanges();
assertEquals(3, changes.size());
commits = changes.values();
for (ValueAndCommit valueAndCommit : commits) {
assertEquals(firstCommit, valueAndCommit.commit);
}
}
Aggregations