Search in sources :

Example 1 with UpdateRef

use of org.locationtech.geogig.api.plumbing.UpdateRef 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 2 with UpdateRef

use of org.locationtech.geogig.api.plumbing.UpdateRef in project GeoGig by boundlessgeo.

the class BranchDeleteOp method _call.

/**
     * @return the reference to the branch deleted, or absent if no such branch existed
     * @throws RuntimeException if the branch couldn't be deleted
     * @Throws IllegalStateException if the branch to be deleted is the HEAD
     * @throws IllegalArgumentException if the given branch name does not resolve to a branch
     *         reference (i.e. under the {@link Ref#HEADS_PREFIX heads} or
     *         {@link Ref#REMOTES_PREFIX remotes} namespace)
     */
@Override
protected Optional<? extends Ref> _call() {
    checkState(branchName != null, "Branch name not provided");
    Optional<Ref> branchRef = command(RefParse.class).setName(branchName).call();
    if (branchRef.isPresent()) {
        final Ref ref = branchRef.get();
        checkArgument(ref.getName().startsWith(Ref.HEADS_PREFIX) || ref.getName().startsWith(Ref.REMOTES_PREFIX), branchName + " does not resolve to a branch reference: " + ref.getName());
        checkState(!(ref instanceof SymRef));
        final Optional<Ref> head = command(RefParse.class).setName(Ref.HEAD).call();
        checkState(!(head.isPresent() && head.get() instanceof SymRef && ((SymRef) head.get()).getTarget().equals(ref.getName())), "Cannot delete the branch you are on");
        UpdateRef updateRef = command(UpdateRef.class).setName(ref.getName()).setDelete(true).setReason("Delete branch " + ref.getName());
        branchRef = updateRef.call();
        checkState(branchRef.isPresent());
    }
    return branchRef;
}
Also used : Ref(org.locationtech.geogig.api.Ref) UpdateRef(org.locationtech.geogig.api.plumbing.UpdateRef) SymRef(org.locationtech.geogig.api.SymRef) SymRef(org.locationtech.geogig.api.SymRef) UpdateRef(org.locationtech.geogig.api.plumbing.UpdateRef)

Example 3 with UpdateRef

use of org.locationtech.geogig.api.plumbing.UpdateRef in project GeoGig by boundlessgeo.

the class UpdateRefWeb method run.

/**
     * Runs the command and builds the appropriate response.
     * 
     * @param context - the context to use for this command
     * 
     * @throws CommandSpecException
     */
@Override
public void run(CommandContext context) {
    if (name == null) {
        throw new CommandSpecException("No name was given.");
    } else if (!(delete) && newValue == null) {
        throw new CommandSpecException("Nothing specified to update with, must specify either deletion or new value to update to.");
    }
    final Context geogig = this.getCommandLocator(context);
    Optional<Ref> ref;
    try {
        ref = geogig.command(RefParse.class).setName(name).call();
        if (!ref.isPresent()) {
            throw new CommandSpecException("Invalid name: " + name);
        }
        if (ref.get() instanceof SymRef) {
            Optional<Ref> target = geogig.command(RefParse.class).setName(newValue).call();
            if (target.isPresent() && !(target.get() instanceof SymRef)) {
                ref = geogig.command(UpdateSymRef.class).setDelete(delete).setName(name).setNewValue(target.get().getName()).call();
            } else {
                throw new CommandSpecException("Invalid new target: " + newValue);
            }
        } else {
            Optional<ObjectId> target = geogig.command(RevParse.class).setRefSpec(newValue).call();
            if (target.isPresent()) {
                ref = geogig.command(UpdateRef.class).setDelete(delete).setName(ref.get().getName()).setNewValue(target.get()).call();
            } else {
                throw new CommandSpecException("Invalid new value: " + newValue);
            }
        }
    } catch (Exception e) {
        context.setResponseContent(CommandResponse.error("Aborting UpdateRef: " + e.getMessage()));
        return;
    }
    if (ref.isPresent()) {
        final Ref newRef = ref.get();
        context.setResponseContent(new CommandResponse() {

            @Override
            public void write(ResponseWriter out) throws Exception {
                out.start();
                out.writeUpdateRefResponse(newRef);
                out.finish();
            }
        });
    }
}
Also used : Context(org.locationtech.geogig.api.Context) CommandContext(org.locationtech.geogig.web.api.CommandContext) ObjectId(org.locationtech.geogig.api.ObjectId) UpdateRef(org.locationtech.geogig.api.plumbing.UpdateRef) CommandResponse(org.locationtech.geogig.web.api.CommandResponse) CommandSpecException(org.locationtech.geogig.web.api.CommandSpecException) UpdateSymRef(org.locationtech.geogig.api.plumbing.UpdateSymRef) Ref(org.locationtech.geogig.api.Ref) UpdateRef(org.locationtech.geogig.api.plumbing.UpdateRef) SymRef(org.locationtech.geogig.api.SymRef) UpdateSymRef(org.locationtech.geogig.api.plumbing.UpdateSymRef) SymRef(org.locationtech.geogig.api.SymRef) UpdateSymRef(org.locationtech.geogig.api.plumbing.UpdateSymRef) ResponseWriter(org.locationtech.geogig.web.api.ResponseWriter) RefParse(org.locationtech.geogig.api.plumbing.RefParse) CommandSpecException(org.locationtech.geogig.web.api.CommandSpecException)

Aggregations

Ref (org.locationtech.geogig.api.Ref)3 UpdateRef (org.locationtech.geogig.api.plumbing.UpdateRef)3 SymRef (org.locationtech.geogig.api.SymRef)2 Context (org.locationtech.geogig.api.Context)1 ObjectId (org.locationtech.geogig.api.ObjectId)1 RevObject (org.locationtech.geogig.api.RevObject)1 RevTag (org.locationtech.geogig.api.RevTag)1 RefParse (org.locationtech.geogig.api.plumbing.RefParse)1 UpdateSymRef (org.locationtech.geogig.api.plumbing.UpdateSymRef)1 CommandContext (org.locationtech.geogig.web.api.CommandContext)1 CommandResponse (org.locationtech.geogig.web.api.CommandResponse)1 CommandSpecException (org.locationtech.geogig.web.api.CommandSpecException)1 ResponseWriter (org.locationtech.geogig.web.api.ResponseWriter)1