/** * Updates the WORK_HEAD ref to the specified tree. * * @param newTree the tree to be set as the new WORK_HEAD */ @Override public synchronized ObjectId updateWorkHead(ObjectId newTree) { context.command(UpdateRef.class).setName(Ref.WORK_HEAD).setNewValue(newTree).call(); return newTree; }
private Iterable<RefDiff> updateLocalRemoteRefs(Remote remote, List<LocalRemoteRef> fetchSpecs, final boolean prune) { List<RefDiff> updatedLocalRemoteRefs = new ArrayList<>(); for (LocalRemoteRef expected : fetchSpecs) { final boolean isNew = expected.isNew; final boolean remoteDeleted = expected.remoteDeleted; final String localName = expected.localRemoteRef.getName(); if (remoteDeleted) { if (prune) { updatedLocalRemoteRefs.add(RefDiff.removed(expected.localRemoteRef)); command(UpdateRef.class).setName(localName) .setOldValue(expected.localRemoteRef.getObjectId()).setDelete(true) .call(); } continue; } RefDiff localRefDiff; Ref oldRef = isNew ? null : expected.localRemoteRef; Ref newRef = new Ref(localName, expected.remoteRef.getObjectId()); command(UpdateRef.class).setName(localName).setNewValue(newRef.getObjectId()).call(); localRefDiff = new RefDiff(oldRef, newRef); updatedLocalRemoteRefs.add(localRefDiff); } return updatedLocalRemoteRefs; }
/** * 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(); }
when(mockUpdateRef.setName(anyString())).thenReturn(mockUpdateRef); when(mockUpdateRef.setDelete(anyBoolean())).thenReturn(mockUpdateRef); when(mockUpdateRef.setNewValue((ObjectId) anyObject())).thenReturn(mockUpdateRef); when(mockUpdateRef.setOldValue((ObjectId) anyObject())).thenReturn(mockUpdateRef); when(mockUpdateRef.setReason(anyString())).thenReturn(mockUpdateRef);
protected Ref _call() { checkState(branchName != null, "branch name was not provided"); final String branchRefPath = Ref.append(Ref.HEADS_PREFIX, branchName); checkArgument(force || !command(RefParse.class).setName(branchRefPath).call().isPresent(), "A branch named '" + branchName + "' already exists."); command(CheckRefFormat.class).setThrowsException(true).setRef(branchRefPath).call(); Optional<Ref> branchRef; if (orphan) { branchRef = command(UpdateRef.class).setName(branchRefPath).setNewValue(ObjectId.NULL) .setProgressListener(getProgressListener()).call(); } else { final String branchOrigin = Optional.fromNullable(commit_ish).or(Ref.HEAD); final ObjectId branchOriginCommitId = resolveOriginCommitId(branchOrigin); branchRef = command(UpdateRef.class).setName(branchRefPath) .setNewValue(branchOriginCommitId).setProgressListener(getProgressListener()).call(); checkState(branchRef.isPresent()); } if (checkout) { command(CheckoutOp.class).setSource(branchRefPath).call(); } return branchRef.get(); }
public @Test void healthCheckWithConflicts() { // fake PRPrepareOp fakeUpToDate(); TestData.point1_modified.setAttribute("sp", "changed on pr target repo"); origin.checkout("master").insert(TestData.point1_modified).add().commit("ci for conflict"); GeogigTransaction tx = request.getTransaction(origin.getRepo().context()); tx.command(UpdateRef.class).setName("refs/heads/" + request.getTargetBranch()) .setNewValue(origin.getRef(request.getTargetBranch()).getObjectId()); tx.command(CheckoutOp.class).setSource(request.getTargetBranch()).call(); tx.command(ResetOp.class).setCommit(origin.getRef(request.getTargetBranch()).getObjectId()) .setMode(ResetMode.HARD).call(); ObjectId localRemoteCommit = clone.getRef(request.getRemoteBranch()).getObjectId(); try { tx.command(MergeOp.class).addCommit(localRemoteCommit).call(); fail("Expected MergeConflictsException"); } catch (MergeConflictsException expected) { // } PRStatus status = origin.getRepo().command(PRHealthCheckOp.class).setId(request.getId()) .call(); assertNotNull(status); assertEquals(request, status.getRequest()); assertEquals(Sets.newHashSet("Lines", "Points", "Polygons"), Sets.newHashSet(status.getAffectedLayers())); Optional<ObjectId> mergeCommit = status.getMergeCommit(); assertFalse(mergeCommit.toString(), mergeCommit.isPresent()); assertEquals(0, status.getCommitsBehindRemoteBranch()); assertEquals(1, status.getCommitsBehindTargetBranch()); assertEquals(1, status.getNumConflicts()); }
@Test public void testNoName() { exception.expect(IllegalStateException.class); geogig.command(UpdateRef.class).call(); }
when(mockUpdateRef.setName(anyString())).thenReturn(mockUpdateRef); when(mockUpdateRef.setDelete(anyBoolean())).thenReturn(mockUpdateRef); when(mockUpdateRef.setNewValue((ObjectId) anyObject())).thenReturn(mockUpdateRef); when(mockUpdateRef.setOldValue((ObjectId) anyObject())).thenReturn(mockUpdateRef); when(mockUpdateRef.setReason(anyString())).thenReturn(mockUpdateRef);
@Test public void testNoName() { exception.expect(IllegalStateException.class); geogig.command(UpdateRef.class).call(); }
/** * Updates the STAGE_HEAD ref to the specified tree. * * @param newTree the tree to set as the new STAGE_HEAD */ @Override public void updateStageHead(ObjectId newTree) { context.command(UpdateRef.class).setName(Ref.STAGE_HEAD).setNewValue(newTree).call(); }
private void createDefaultRefs() { Optional<Ref> master = command(RefParse.class).setName(Ref.MASTER).call(); Preconditions.checkState(!master.isPresent(), Ref.MASTER + " was already initialized."); command(UpdateRef.class).setName(Ref.MASTER).setNewValue(ObjectId.NULL) .setReason("Repository initialization").call(); Optional<Ref> head = command(RefParse.class).setName(Ref.HEAD).call(); Preconditions.checkState(!head.isPresent(), Ref.HEAD + " was already initialized."); command(UpdateSymRef.class).setName(Ref.HEAD).setNewValue(Ref.MASTER) .setReason("Repository initialization").call(); Optional<Ref> workhead = command(RefParse.class).setName(Ref.WORK_HEAD).call(); Preconditions.checkState(!workhead.isPresent(), Ref.WORK_HEAD + " was already initialized."); command(UpdateRef.class).setName(Ref.WORK_HEAD).setNewValue(RevTree.EMPTY.getId()) .setReason("Repository initialization").call(); Optional<Ref> stagehead = command(RefParse.class).setName(Ref.STAGE_HEAD).call(); Preconditions.checkState(!stagehead.isPresent(), Ref.STAGE_HEAD + " was already initialized."); command(UpdateRef.class).setName(Ref.STAGE_HEAD).setNewValue(RevTree.EMPTY.getId()) .setReason("Repository initialization").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(); }
private void setRef(final GeogigTransaction transaction, String refName, ObjectId value) { transaction.command(UpdateRef.class).setName(refName).setNewValue(value).call(); } }
private void createDefaultRefs() { Optional<Ref> master = command(RefParse.class).setName(Ref.MASTER).call(); Preconditions.checkState(!master.isPresent(), Ref.MASTER + " was already initialized."); command(UpdateRef.class).setName(Ref.MASTER).setNewValue(ObjectId.NULL) .setReason("Repository initialization").call(); Optional<Ref> head = command(RefParse.class).setName(Ref.HEAD).call(); Preconditions.checkState(!head.isPresent(), Ref.HEAD + " was already initialized."); command(UpdateSymRef.class).setName(Ref.HEAD).setNewValue(Ref.MASTER) .setReason("Repository initialization").call(); Optional<Ref> workhead = command(RefParse.class).setName(Ref.WORK_HEAD).call(); Preconditions.checkState(!workhead.isPresent(), Ref.WORK_HEAD + " was already initialized."); command(UpdateRef.class).setName(Ref.WORK_HEAD).setNewValue(RevTree.EMPTY.getId()) .setReason("Repository initialization").call(); Optional<Ref> stagehead = command(RefParse.class).setName(Ref.STAGE_HEAD).call(); Preconditions.checkState(!stagehead.isPresent(), Ref.STAGE_HEAD + " was already initialized."); command(UpdateRef.class).setName(Ref.STAGE_HEAD).setNewValue(RevTree.EMPTY.getId()) .setReason("Repository initialization").call(); } }