Example usage for org.eclipse.jgit.lib RefUpdate getOldObjectId

List of usage examples for org.eclipse.jgit.lib RefUpdate getOldObjectId

Introduction

In this page you can find the example usage for org.eclipse.jgit.lib RefUpdate getOldObjectId.

Prototype

public ObjectId getOldObjectId() 

Source Link

Document

The old value of the ref, prior to the update being attempted.

Usage

From source file:org.nbgit.client.CommitBuilder.java

License:Open Source License

/**
 * Write the commit to the repository./* w ww  . j a v a2 s.co  m*/
 *
 * @throws IOException if creation of the commit fails.
 */
public void write() throws IOException {
    index.write();
    final RefUpdate ru = repository.updateRef(Constants.HEAD);
    ObjectId[] parentIds;
    if (ru.getOldObjectId() != null)
        parentIds = new ObjectId[] { ru.getOldObjectId() };
    else
        parentIds = new ObjectId[0];

    ObjectId id = writeCommit(index.writeTree(), parentIds);
    if (!updateRef(ru, id))
        logger.output("Failed to update " + ru.getName() + " to commit " + id + ".");
}

From source file:org.nbgit.client.CommitBuilder.java

License:Open Source License

private boolean updateRef(RefUpdate ru, ObjectId id) throws IOException {
    ru.setNewObjectId(id);//www .j a  v a2s .  co m
    ru.setRefLogMessage(buildReflogMessage(), false);
    ru.update();
    return ru.getOldObjectId() != null ? ru.getResult() == RefUpdate.Result.FAST_FORWARD
            : ru.getResult() == RefUpdate.Result.NEW;
}

From source file:svnserver.repository.git.push.GitPushEmbedded.java

License:GNU General Public License

@Override
public boolean push(@NotNull Repository repository, @NotNull ObjectId ReceiveId, @NotNull String branch,
        @NotNull User userInfo) throws SVNException, IOException {
    final RefUpdate refUpdate = repository.updateRef(branch);
    refUpdate.getOldObjectId();
    refUpdate.setNewObjectId(ReceiveId);
    runReceiveHook(repository, refUpdate, preReceive, userInfo);
    runUpdateHook(repository, refUpdate, update, userInfo);
    final RefUpdate.Result result = refUpdate.update();
    switch (result) {
    case REJECTED:
        return false;
    case NEW://from   w  w w.j av  a2s. c o m
    case FAST_FORWARD:
        runReceiveHook(repository, refUpdate, postReceive, userInfo);
        return true;
    default:
        log.error("Unexpected push error: {}", result);
        throw new SVNException(SVNErrorMessage.create(SVNErrorCode.IO_WRITE_ERROR, result.name()));
    }
}

From source file:svnserver.repository.git.push.GitPushEmbedded.java

License:GNU General Public License

private void runReceiveHook(@NotNull Repository repository, @NotNull RefUpdate refUpdate, @NotNull String hook,
        @NotNull User userInfo) throws IOException, SVNException {
    runHook(repository, hook, userInfo, processBuilder -> {
        final Process process = processBuilder.start();
        try (Writer stdin = new OutputStreamWriter(process.getOutputStream(), StandardCharsets.UTF_8)) {
            stdin.write(getObjectId(refUpdate.getOldObjectId()));
            stdin.write(' ');
            stdin.write(getObjectId(refUpdate.getNewObjectId()));
            stdin.write(' ');
            stdin.write(refUpdate.getName());
            stdin.write('\n');
        }/*from   w w w .  ja v a 2 s  .  co  m*/
        return process;
    });
}

From source file:svnserver.repository.git.push.GitPushEmbedded.java

License:GNU General Public License

private void runUpdateHook(@NotNull Repository repository, @NotNull RefUpdate refUpdate, @Nullable String hook,
        @NotNull User userInfo) throws IOException, SVNException {
    runHook(repository, hook, userInfo, processBuilder -> {
        processBuilder.command().addAll(Arrays.asList(refUpdate.getName(),
                getObjectId(refUpdate.getOldObjectId()), getObjectId(refUpdate.getNewObjectId())));
        return processBuilder.start();
    });//from   ww  w  . ja va2s .  c om
}