Search in sources :

Example 51 with ReceiveCommand

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));
    }
}
Also used : ReceiveCommand(org.eclipse.jgit.transport.ReceiveCommand) ObjectId(org.eclipse.jgit.lib.ObjectId)

Example 52 with ReceiveCommand

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);
        }
    }
}
Also used : ReceiveCommand(org.eclipse.jgit.transport.ReceiveCommand) IOException(java.io.IOException) RevWalk(org.eclipse.jgit.revwalk.RevWalk) BatchRefUpdate(org.eclipse.jgit.lib.BatchRefUpdate)

Example 53 with ReceiveCommand

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());
    }
}
Also used : ReceiveCommand(org.eclipse.jgit.transport.ReceiveCommand) ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) RevWalk(org.eclipse.jgit.revwalk.RevWalk) BatchRefUpdate(org.eclipse.jgit.lib.BatchRefUpdate)

Example 54 with ReceiveCommand

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();
}
Also used : ReceiveCommand(org.eclipse.jgit.transport.ReceiveCommand) ObjectId(org.eclipse.jgit.lib.ObjectId) Test(org.junit.Test)

Example 55 with ReceiveCommand

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();
}
Also used : ReceiveCommand(org.eclipse.jgit.transport.ReceiveCommand) ObjectId(org.eclipse.jgit.lib.ObjectId) Test(org.junit.Test)

Aggregations

ReceiveCommand (org.eclipse.jgit.transport.ReceiveCommand)55 IOException (java.io.IOException)18 ArrayList (java.util.ArrayList)14 Test (org.junit.Test)14 RepositoryModel (com.gitblit.models.RepositoryModel)13 ObjectId (org.eclipse.jgit.lib.ObjectId)13 BatchRefUpdate (org.eclipse.jgit.lib.BatchRefUpdate)12 RevWalk (org.eclipse.jgit.revwalk.RevWalk)12 Repository (org.eclipse.jgit.lib.Repository)9 Date (java.util.Date)8 Ref (org.eclipse.jgit.lib.Ref)7 OrmException (com.google.gwtorm.server.OrmException)6 Map (java.util.Map)6 RestApiException (com.google.gerrit.extensions.restapi.RestApiException)5 Change (com.google.gerrit.reviewdb.client.Change)5 PersonIdent (org.eclipse.jgit.lib.PersonIdent)5 TicketModel (com.gitblit.models.TicketModel)4 Change (com.gitblit.models.TicketModel.Change)4 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)4 Account (com.google.gerrit.reviewdb.client.Account)4