use of org.locationtech.geogig.api.RevTag in project GeoGig by boundlessgeo.
the class TagRemoveOp method _call.
/**
* Executes the tag removal operation.
*
* @return the tag to remove
*
*/
@Override
protected RevTag _call() throws RuntimeException {
String fullPath = Ref.TAGS_PREFIX + name;
Optional<RevObject> revTag = command(RevObjectParse.class).setRefSpec(fullPath).call();
Preconditions.checkArgument(revTag.isPresent(), "Wrong tag name: " + name);
Preconditions.checkArgument(revTag.get().getType().equals(RevObject.TYPE.TAG), name + " does not resolve to a tag");
UpdateRef updateRef = command(UpdateRef.class).setName(fullPath).setDelete(true).setReason("Delete tag " + name);
Optional<Ref> tagRef = updateRef.call();
checkState(tagRef.isPresent());
return (RevTag) revTag.get();
}
use of org.locationtech.geogig.api.RevTag in project GeoGig by boundlessgeo.
the class TagWebOp 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) {
if (list) {
final Context geogig = this.getCommandLocator(context);
final List<RevTag> tags = geogig.command(TagListOp.class).call();
context.setResponseContent(new CommandResponse() {
@Override
public void write(ResponseWriter out) throws Exception {
out.start();
out.writeTagListResponse(tags);
out.finish();
}
});
}
}
use of org.locationtech.geogig.api.RevTag in project GeoGig by boundlessgeo.
the class TagTest method testTagRemoval.
@Test
public void testTagRemoval() throws Exception {
insertAndAdd(points1);
RevCommit commit = geogig.command(CommitOp.class).call();
RevTag tag = geogig.command(TagCreateOp.class).setCommitId(commit.getId()).setName("Tag1").call();
Optional<RevTag> databaseTag = geogig.command(RevObjectParse.class).setRefSpec("Tag1").call(RevTag.class);
assertTrue(databaseTag.isPresent());
RevTag removedTag = geogig.command(TagRemoveOp.class).setName("Tag1").call();
assertEquals(tag, removedTag);
Optional<ObjectId> databaseTagId = geogig.command(RevParse.class).setRefSpec("Tag1").call();
assertFalse(databaseTagId.isPresent());
}
use of org.locationtech.geogig.api.RevTag in project GeoGig by boundlessgeo.
the class Tag method runInternal.
/**
* Executes the commit command using the provided options.
*/
@Override
public void runInternal(GeogigCLI cli) throws IOException {
checkParameter((message != null && !message.trim().isEmpty()) || nameAndCommit.isEmpty() || delete, "No tag message provided");
checkParameter(nameAndCommit.size() < 2 || (nameAndCommit.size() == 2 && !delete), "Too many parameters provided");
if (nameAndCommit.isEmpty()) {
// looks like an attempt to create a tag with a message but forgot the tag name
checkParameter(message == null, "A tag name must be provided");
listTags(cli);
return;
}
String name = nameAndCommit.get(0);
String commit = nameAndCommit.size() > 1 ? nameAndCommit.get(1) : Ref.HEAD;
ConsoleReader console = cli.getConsole();
final GeoGIG geogig = cli.getGeogig();
if (delete) {
geogig.command(TagRemoveOp.class).setName(name).call();
console.println("Deleted tag " + name);
} else {
Optional<ObjectId> commitId = geogig.command(RevParse.class).setRefSpec(commit).call();
checkParameter(commitId.isPresent(), "Wrong reference: " + commit);
RevTag tag = geogig.command(TagCreateOp.class).setName(name).setMessage(message).setCommitId(commitId.get()).call();
console.println("Created tag " + name + " -> " + tag.getCommitId());
}
}
use of org.locationtech.geogig.api.RevTag in project GeoGig by boundlessgeo.
the class Tag method listTags.
private void listTags(GeogigCLI cli) {
GeoGIG geogig = cli.getGeogig();
ImmutableList<RevTag> tags = geogig.command(TagListOp.class).call();
for (RevTag tag : tags) {
try {
cli.getConsole().println(tag.getName());
} catch (IOException e) {
throw Throwables.propagate(e);
}
}
}
Aggregations