Example usage for org.eclipse.jgit.lib RefRename setRefLogMessage

List of usage examples for org.eclipse.jgit.lib RefRename setRefLogMessage

Introduction

In this page you can find the example usage for org.eclipse.jgit.lib RefRename setRefLogMessage.

Prototype

public void setRefLogMessage(String msg) 

Source Link

Document

Set the message to include in the reflog.

Usage

From source file:com.gitblit.tickets.BranchTicketService.java

License:Apache License

/**
 * Returns a RefModel for the refs/meta/gitblit/tickets branch in the repository.
 * If the branch can not be found, null is returned.
 *
 * @return a refmodel for the gitblit tickets branch or null
 *//*from   w  w  w.  j av a  2 s .  c o m*/
private RefModel getTicketsBranch(Repository db) {
    List<RefModel> refs = JGitUtils.getRefs(db, "refs/");
    Ref oldRef = null;
    for (RefModel ref : refs) {
        if (ref.reference.getName().equals(BRANCH)) {
            return ref;
        } else if (ref.reference.getName().equals("refs/gitblit/tickets")) {
            oldRef = ref.reference;
        }
    }
    if (oldRef != null) {
        // rename old ref to refs/meta/gitblit/tickets
        RefRename cmd;
        try {
            cmd = db.renameRef(oldRef.getName(), BRANCH);
            cmd.setRefLogIdent(new PersonIdent("Gitblit", "gitblit@localhost"));
            cmd.setRefLogMessage("renamed " + oldRef.getName() + " => " + BRANCH);
            Result res = cmd.rename();
            switch (res) {
            case RENAMED:
                log.info(db.getDirectory() + " " + cmd.getRefLogMessage());
                return getTicketsBranch(db);
            default:
                log.error("failed to rename " + oldRef.getName() + " => " + BRANCH + " (" + res.name() + ")");
            }
        } catch (IOException e) {
            log.error("failed to rename tickets branch", e);
        }
    }
    return null;
}

From source file:com.gitblit.utils.RefLogUtils.java

License:Apache License

/**
 * Returns a RefModel for the reflog branch in the repository. If the
 * branch can not be found, null is returned.
 *
 * @param repository/*  w w  w .ja  v a  2 s  . c om*/
 * @return a refmodel for the reflog branch or null
 */
public static RefModel getRefLogBranch(Repository repository) {
    List<RefModel> refs = JGitUtils.getRefs(repository, "refs/");
    Ref oldRef = null;
    for (RefModel ref : refs) {
        if (ref.reference.getName().equals(GB_REFLOG)) {
            return ref;
        } else if (ref.reference.getName().equals("refs/gitblit/reflog")) {
            oldRef = ref.reference;
        } else if (ref.reference.getName().equals("refs/gitblit/pushes")) {
            oldRef = ref.reference;
        }
    }
    if (oldRef != null) {
        // rename old ref to refs/meta/gitblit/reflog
        RefRename cmd;
        try {
            cmd = repository.renameRef(oldRef.getName(), GB_REFLOG);
            cmd.setRefLogIdent(new PersonIdent("Gitblit", "gitblit@localhost"));
            cmd.setRefLogMessage("renamed " + oldRef.getName() + " => " + GB_REFLOG);
            Result res = cmd.rename();
            switch (res) {
            case RENAMED:
                LOGGER.info(repository.getDirectory() + " " + cmd.getRefLogMessage());
                return getRefLogBranch(repository);
            default:
                LOGGER.error(
                        "failed to rename " + oldRef.getName() + " => " + GB_REFLOG + " (" + res.name() + ")");
            }
        } catch (IOException e) {
            LOGGER.error("failed to rename reflog", e);
        }
    }
    return null;
}

From source file:org.kuali.student.git.model.ref.utils.GitRefUtils.java

License:Educational Community License

public static Ref renameRef(Repository repo, PersonIdent refLogIdent, String fromRefName, String toRefName)
        throws IOException {

    RefRename rename = repo.renameRef(fromRefName, toRefName);

    rename.setRefLogIdent(refLogIdent);//from   w w w.j  av a2s.c o m
    rename.setRefLogMessage(refLogIdent + " archived " + fromRefName + " to " + toRefName);

    Result result = rename.rename();

    if (result.equals(Result.LOCK_FAILURE)) {
        log.warn("lockfailure archiving " + fromRefName + " to branch = " + toRefName);
        try {
            Thread.currentThread().sleep(1000);
        } catch (InterruptedException e) {
            //fall through
        }

        return renameRef(repo, refLogIdent, fromRefName, toRefName);
    } else {
        if (result.equals(Result.RENAMED))
            return repo.getRef(toRefName);
        else
            return null;
    }
}