use of org.locationtech.geogig.api.Ref in project GeoGig by boundlessgeo.
the class ShowRef method runInternal.
@Override
public void runInternal(GeogigCLI cli) throws IOException {
ConsoleReader console = cli.getConsole();
GeoGIG geogig = cli.getGeogig();
ForEachRef op = geogig.command(ForEachRef.class);
Predicate<Ref> filter = new Predicate<Ref>() {
@Override
public boolean apply(Ref ref) {
String name = ref.getName();
if (!name.startsWith(Ref.REFS_PREFIX)) {
return false;
}
boolean match = patterns.isEmpty() ? true : false;
for (String pattern : patterns) {
if (Strings.isNullOrEmpty(pattern)) {
match = true;
} else if (name.endsWith("/" + pattern)) {
match = true;
break;
}
}
return match;
}
};
op.setFilter(filter);
ImmutableSet<Ref> refs = op.call();
for (Ref ref : refs) {
console.println(ref.getObjectId() + " " + ref.getName());
}
}
use of org.locationtech.geogig.api.Ref in project GeoGig by boundlessgeo.
the class LocalRemoteRepo method pushNewData.
/**
* Push all new objects from the specified {@link Ref} to the given refspec.
*
* @param ref the local ref that points to new commit data
* @param refspec the refspec to push to
*/
@Override
public void pushNewData(final Ref ref, final String refspec, final ProgressListener progress) throws SynchronizationException {
Optional<Ref> remoteRef = remoteGeoGig.command(RefParse.class).setName(refspec).call();
remoteRef = remoteRef.or(remoteGeoGig.command(RefParse.class).setName(Ref.TAGS_PREFIX + refspec).call());
checkPush(ref, remoteRef);
CommitTraverser traverser = getPushTraverser(remoteRef);
traverser.traverse(ref.getObjectId());
progress.setDescription("Uploading objects to " + refspec);
progress.setProgress(0);
while (!traverser.commits.isEmpty()) {
ObjectId commitId = traverser.commits.pop();
walkHead(commitId, false, progress);
}
String nameToSet = remoteRef.isPresent() ? remoteRef.get().getName() : Ref.HEADS_PREFIX + refspec;
Ref updatedRef = remoteGeoGig.command(UpdateRef.class).setName(nameToSet).setNewValue(ref.getObjectId()).call().get();
Ref remoteHead = headRef();
if (remoteHead instanceof SymRef) {
if (((SymRef) remoteHead).getTarget().equals(updatedRef.getName())) {
remoteGeoGig.command(UpdateSymRef.class).setName(Ref.HEAD).setNewValue(ref.getName()).call();
RevCommit commit = remoteGeoGig.getRepository().getCommit(ref.getObjectId());
remoteGeoGig.getRepository().workingTree().updateWorkHead(commit.getTreeId());
remoteGeoGig.getRepository().index().updateStageHead(commit.getTreeId());
}
}
}
use of org.locationtech.geogig.api.Ref in project GeoGig by boundlessgeo.
the class LocalMappedRemoteRepo method listRefs.
/**
* List the remote's {@link Ref refs}.
*
* @param getHeads whether to return refs in the {@code refs/heads} namespace
* @param getTags whether to return refs in the {@code refs/tags} namespace
* @return an immutable set of refs from the remote
*/
@Override
public ImmutableSet<Ref> listRefs(final boolean getHeads, final boolean getTags) {
Predicate<Ref> filter = new Predicate<Ref>() {
@Override
public boolean apply(Ref input) {
boolean keep = false;
if (getHeads) {
keep = input.getName().startsWith(Ref.HEADS_PREFIX);
}
if (getTags) {
keep = keep || input.getName().startsWith(Ref.TAGS_PREFIX);
}
return keep;
}
};
ImmutableSet<Ref> remoteRefs = remoteGeoGig.command(ForEachRef.class).setFilter(filter).call();
// Translate the refs to their mapped values.
ImmutableSet.Builder<Ref> builder = new ImmutableSet.Builder<Ref>();
for (Ref remoteRef : remoteRefs) {
Ref newRef = remoteRef;
if (!(newRef instanceof SymRef) && localRepository.graphDatabase().exists(remoteRef.getObjectId())) {
ObjectId mappedCommit = localRepository.graphDatabase().getMapping(remoteRef.getObjectId());
if (mappedCommit != null) {
newRef = new Ref(remoteRef.getName(), mappedCommit);
}
}
builder.add(newRef);
}
return builder.build();
}
use of org.locationtech.geogig.api.Ref in project GeoGig by boundlessgeo.
the class LocalMappedRemoteRepo method updateRemoteRef.
/**
* Updates the remote ref that matches the given refspec.
*
* @param refspec the ref to update
* @param commitId the new value of the ref
* @param delete if true, the remote ref will be deleted
* @return the updated ref
*/
@Override
protected Optional<Ref> updateRemoteRef(String refspec, ObjectId commitId, boolean delete) {
Optional<Ref> updatedRef = remoteGeoGig.command(UpdateRef.class).setName(refspec).setNewValue(commitId).setDelete(delete).call();
if (updatedRef.isPresent()) {
final Ref remoteHead = headRef();
if (remoteHead instanceof SymRef) {
if (((SymRef) remoteHead).getTarget().equals(updatedRef.get().getName())) {
remoteGeoGig.command(UpdateSymRef.class).setName(Ref.HEAD).setNewValue(updatedRef.get().getName()).call();
RevCommit commit = remoteGeoGig.getRepository().getCommit(commitId);
remoteGeoGig.getRepository().workingTree().updateWorkHead(commit.getTreeId());
remoteGeoGig.getRepository().index().updateStageHead(commit.getTreeId());
}
}
}
return updatedRef;
}
use of org.locationtech.geogig.api.Ref in project GeoGig by boundlessgeo.
the class MergeOpTest method testMergeConflictingBranches.
@Test
public void testMergeConflictingBranches() throws Exception {
// Create the following revision graph
// o
// |
// o - Points 1,2 added
// |\
// | o - TestBranch - Points 1 modified, 2 removed, 3 added
// |
// o - master - HEAD - Points 1 modifiedB, 2 removed
insertAndAdd(points1, points2);
geogig.command(CommitOp.class).call();
geogig.command(BranchCreateOp.class).setName("TestBranch").call();
Feature points1Modified = feature(pointsType, idP1, "StringProp1_2", new Integer(1000), "POINT(1 1)");
insert(points1Modified);
delete(points2);
insert(points3);
geogig.command(AddOp.class).call();
RevCommit masterCommit = geogig.command(CommitOp.class).call();
geogig.command(CheckoutOp.class).setSource("TestBranch").call();
Feature points1ModifiedB = feature(pointsType, idP1, "StringProp1_3", new Integer(2000), "POINT(1 1)");
insert(points1ModifiedB);
delete(points2);
geogig.command(AddOp.class).call();
RevCommit branchCommit = geogig.command(CommitOp.class).call();
// Now try to merge branch into master
geogig.command(CheckoutOp.class).setSource("master").call();
Ref branch = geogig.command(RefParse.class).setName("TestBranch").call().get();
try {
geogig.command(MergeOp.class).addCommit(Suppliers.ofInstance(branch.getObjectId())).call();
fail();
} catch (MergeConflictsException e) {
assertTrue(e.getMessage().contains("conflict"));
}
Optional<Ref> ref = geogig.command(RefParse.class).setName(Ref.ORIG_HEAD).call();
assertTrue(ref.isPresent());
assertEquals(masterCommit.getId(), ref.get().getObjectId());
ref = geogig.command(RefParse.class).setName(Ref.MERGE_HEAD).call();
assertTrue(ref.isPresent());
assertEquals(branch.getObjectId(), ref.get().getObjectId());
String msg = geogig.command(ReadMergeCommitMessageOp.class).call();
assertFalse(Strings.isNullOrEmpty(msg));
List<Conflict> conflicts = geogig.command(ConflictsReadOp.class).call();
assertEquals(1, conflicts.size());
String path = NodeRef.appendChild(pointsName, idP1);
assertEquals(conflicts.get(0).getPath(), path);
assertEquals(conflicts.get(0).getOurs(), RevFeatureBuilder.build(points1Modified).getId());
assertEquals(conflicts.get(0).getTheirs(), RevFeatureBuilder.build(points1ModifiedB).getId());
// try to commit
try {
geogig.command(CommitOp.class).call();
fail();
} catch (IllegalStateException e) {
assertEquals(e.getMessage(), "Cannot run operation while merge conflicts exist.");
}
// solve, and commit
Feature points1Merged = feature(pointsType, idP1, "StringProp1_2", new Integer(2000), "POINT(1 1)");
insert(points1Merged);
geogig.command(AddOp.class).call();
RevCommit commit = geogig.command(CommitOp.class).call();
assertTrue(commit.getMessage().contains(idP1));
List<ObjectId> parents = commit.getParentIds();
assertEquals(2, parents.size());
assertEquals(masterCommit.getId(), parents.get(0));
assertEquals(branchCommit.getId(), parents.get(1));
Optional<RevFeature> revFeature = geogig.command(RevObjectParse.class).setRefSpec(Ref.HEAD + ":" + path).call(RevFeature.class);
assertTrue(revFeature.isPresent());
assertEquals(RevFeatureBuilder.build(points1Merged), revFeature.get());
path = NodeRef.appendChild(pointsName, idP2);
revFeature = geogig.command(RevObjectParse.class).setRefSpec(Ref.HEAD + ":" + path).call(RevFeature.class);
assertFalse(revFeature.isPresent());
path = NodeRef.appendChild(pointsName, idP3);
revFeature = geogig.command(RevObjectParse.class).setRefSpec(Ref.HEAD + ":" + path).call(RevFeature.class);
assertTrue(revFeature.isPresent());
ref = geogig.command(RefParse.class).setName(Ref.MERGE_HEAD).call();
assertFalse(ref.isPresent());
}
Aggregations