Search in sources :

Example 11 with RevTag

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();
}
Also used : Ref(org.locationtech.geogig.api.Ref) UpdateRef(org.locationtech.geogig.api.plumbing.UpdateRef) RevTag(org.locationtech.geogig.api.RevTag) RevObject(org.locationtech.geogig.api.RevObject) UpdateRef(org.locationtech.geogig.api.plumbing.UpdateRef)

Example 12 with RevTag

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();
            }
        });
    }
}
Also used : Context(org.locationtech.geogig.api.Context) CommandContext(org.locationtech.geogig.web.api.CommandContext) RevTag(org.locationtech.geogig.api.RevTag) ResponseWriter(org.locationtech.geogig.web.api.ResponseWriter) CommandResponse(org.locationtech.geogig.web.api.CommandResponse) TagListOp(org.locationtech.geogig.api.porcelain.TagListOp)

Example 13 with RevTag

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());
}
Also used : RevTag(org.locationtech.geogig.api.RevTag) TagCreateOp(org.locationtech.geogig.api.porcelain.TagCreateOp) ObjectId(org.locationtech.geogig.api.ObjectId) CommitOp(org.locationtech.geogig.api.porcelain.CommitOp) RevCommit(org.locationtech.geogig.api.RevCommit) Test(org.junit.Test)

Example 14 with RevTag

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());
    }
}
Also used : ConsoleReader(jline.console.ConsoleReader) RevTag(org.locationtech.geogig.api.RevTag) ObjectId(org.locationtech.geogig.api.ObjectId) GeoGIG(org.locationtech.geogig.api.GeoGIG)

Example 15 with RevTag

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);
        }
    }
}
Also used : RevTag(org.locationtech.geogig.api.RevTag) IOException(java.io.IOException) GeoGIG(org.locationtech.geogig.api.GeoGIG) TagListOp(org.locationtech.geogig.api.porcelain.TagListOp)

Aggregations

RevTag (org.locationtech.geogig.api.RevTag)16 ObjectId (org.locationtech.geogig.api.ObjectId)8 RevCommit (org.locationtech.geogig.api.RevCommit)8 RevObject (org.locationtech.geogig.api.RevObject)6 Test (org.junit.Test)4 Ref (org.locationtech.geogig.api.Ref)3 CommitOp (org.locationtech.geogig.api.porcelain.CommitOp)3 TagCreateOp (org.locationtech.geogig.api.porcelain.TagCreateOp)3 TagListOp (org.locationtech.geogig.api.porcelain.TagListOp)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Context (org.locationtech.geogig.api.Context)2 GeoGIG (org.locationtech.geogig.api.GeoGIG)2 RevPerson (org.locationtech.geogig.api.RevPerson)2 RevTagImpl (org.locationtech.geogig.api.RevTagImpl)2 RevTree (org.locationtech.geogig.api.RevTree)2 UpdateRef (org.locationtech.geogig.api.plumbing.UpdateRef)2 CommandContext (org.locationtech.geogig.web.api.CommandContext)2 CommandResponse (org.locationtech.geogig.web.api.CommandResponse)2 Optional (com.google.common.base.Optional)1