Search in sources :

Example 1 with RefRename

use of org.eclipse.jgit.lib.RefRename in project gitblit by gitblit.

the class RefLogUtils method getRefLogBranch.

/**
	 * Returns a RefModel for the reflog branch in the repository. If the
	 * branch can not be found, null is returned.
	 *
	 * @param repository
	 * @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;
}
Also used : Ref(org.eclipse.jgit.lib.Ref) RefModel(com.gitblit.models.RefModel) PersonIdent(org.eclipse.jgit.lib.PersonIdent) IOException(java.io.IOException) RefRename(org.eclipse.jgit.lib.RefRename) Result(org.eclipse.jgit.lib.RefUpdate.Result)

Example 2 with RefRename

use of org.eclipse.jgit.lib.RefRename in project gitblit by gitblit.

the class BranchTicketService method getTicketsBranch.

/**
	 * 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
	 */
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;
}
Also used : Ref(org.eclipse.jgit.lib.Ref) RefModel(com.gitblit.models.RefModel) PersonIdent(org.eclipse.jgit.lib.PersonIdent) IOException(java.io.IOException) RefRename(org.eclipse.jgit.lib.RefRename) Result(org.eclipse.jgit.lib.RefUpdate.Result)

Aggregations

RefModel (com.gitblit.models.RefModel)2 IOException (java.io.IOException)2 PersonIdent (org.eclipse.jgit.lib.PersonIdent)2 Ref (org.eclipse.jgit.lib.Ref)2 RefRename (org.eclipse.jgit.lib.RefRename)2 Result (org.eclipse.jgit.lib.RefUpdate.Result)2