use of org.eclipse.jgit.transport.ReceiveCommand in project gerrit by GerritCodeReview.
the class ChangeRebuilderImpl method deleteChangeMetaRef.
private void deleteChangeMetaRef(Change change, ChainedReceiveCommands cmds) throws IOException {
String refName = changeMetaRef(change.getId());
Optional<ObjectId> old = cmds.get(refName);
if (old.isPresent()) {
cmds.add(new ReceiveCommand(old.get(), ObjectId.zeroId(), refName));
}
}
use of org.eclipse.jgit.transport.ReceiveCommand in project gerrit by GerritCodeReview.
the class ChangeEditModifier method updateReferenceWithNameChange.
private void updateReferenceWithNameChange(Repository repository, String currentRefName, ObjectId currentObjectId, String newRefName, ObjectId targetObjectId, Timestamp timestamp) throws IOException {
BatchRefUpdate batchRefUpdate = repository.getRefDatabase().newBatchUpdate();
batchRefUpdate.addCommand(new ReceiveCommand(ObjectId.zeroId(), targetObjectId, newRefName));
batchRefUpdate.addCommand(new ReceiveCommand(currentObjectId, ObjectId.zeroId(), currentRefName));
batchRefUpdate.setRefLogMessage("rebase edit", false);
batchRefUpdate.setRefLogIdent(getRefLogIdent(timestamp));
try (RevWalk revWalk = new RevWalk(repository)) {
batchRefUpdate.execute(revWalk, NullProgressMonitor.INSTANCE);
}
for (ReceiveCommand cmd : batchRefUpdate.getCommands()) {
if (cmd.getResult() != ReceiveCommand.Result.OK) {
throw new IOException("failed: " + cmd);
}
}
}
use of org.eclipse.jgit.transport.ReceiveCommand in project gerrit by GerritCodeReview.
the class DeleteRef method deleteMultipleRefs.
private void deleteMultipleRefs(Repository r) throws OrmException, IOException, ResourceConflictException, PermissionBackendException {
BatchRefUpdate batchUpdate = r.getRefDatabase().newBatchUpdate();
batchUpdate.setAtomic(false);
List<String> refs = prefix == null ? refsToDelete : refsToDelete.stream().map(ref -> ref.startsWith(prefix) ? ref : prefix + ref).collect(toList());
for (String ref : refs) {
batchUpdate.addCommand(createDeleteCommand(resource, r, ref));
}
try (RevWalk rw = new RevWalk(r)) {
batchUpdate.execute(rw, NullProgressMonitor.INSTANCE);
}
StringBuilder errorMessages = new StringBuilder();
for (ReceiveCommand command : batchUpdate.getCommands()) {
if (command.getResult() == Result.OK) {
postDeletion(resource, command);
} else {
appendAndLogErrorMessage(errorMessages, command);
}
}
if (errorMessages.length() > 0) {
throw new ResourceConflictException(errorMessages.toString());
}
}
use of org.eclipse.jgit.transport.ReceiveCommand in project gerrit by GerritCodeReview.
the class RepoViewTest method getRefsOverwritesCachedValueWithCommand.
@Test
public void getRefsOverwritesCachedValueWithCommand() throws Exception {
ObjectId master1 = repo.exactRef(MASTER).getObjectId();
assertThat(view.getRef(MASTER)).hasValue(master1);
ObjectId master2 = tr.commit().create();
view.getCommands().add(new ReceiveCommand(master1, master2, MASTER));
assertThat(repo.exactRef(MASTER).getObjectId()).isEqualTo(master1);
assertThat(view.getRef(MASTER)).hasValue(master2);
assertThat(view.getRefs(R_HEADS)).containsExactly("master", master2);
view.getCommands().add(new ReceiveCommand(master2, ObjectId.zeroId(), MASTER));
assertThat(repo.exactRef(MASTER).getObjectId()).isEqualTo(master1);
assertThat(view.getRef(MASTER)).isEmpty();
assertThat(view.getRefs(R_HEADS)).isEmpty();
}
use of org.eclipse.jgit.transport.ReceiveCommand in project gerrit by GerritCodeReview.
the class RepoViewTest method getRefsReflectsCommands.
@Test
public void getRefsReflectsCommands() throws Exception {
ObjectId master1 = repo.exactRef(MASTER).getObjectId();
assertThat(view.getRefs(R_HEADS)).containsExactly("master", master1);
ObjectId master2 = tr.commit().create();
view.getCommands().add(new ReceiveCommand(master1, master2, MASTER));
assertThat(repo.exactRef(MASTER).getObjectId()).isEqualTo(master1);
assertThat(view.getRef(MASTER)).hasValue(master2);
assertThat(view.getRefs(R_HEADS)).containsExactly("master", master2);
view.getCommands().add(new ReceiveCommand(master2, ObjectId.zeroId(), MASTER));
assertThat(repo.exactRef(MASTER).getObjectId()).isEqualTo(master1);
assertThat(view.getRef(MASTER)).isEmpty();
assertThat(view.getRefs(R_HEADS)).isEmpty();
}
Aggregations