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();
}
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;
}
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();
}
});
}
}
Aggregations