Example usage for org.eclipse.jgit.api Git reflog

List of usage examples for org.eclipse.jgit.api Git reflog

Introduction

In this page you can find the example usage for org.eclipse.jgit.api Git reflog.

Prototype

public ReflogCommand reflog() 

Source Link

Document

Return a command object to execute a reflog command

Usage

From source file:org.eclipse.oomph.setup.git.impl.GitCloneTaskImpl.java

License:Open Source License

private static boolean hasReflog(Git git) throws Exception {
    try {/*w w w  .  j  a va  2  s.co m*/
        ReflogCommand reflogCommand = git.reflog();
        Collection<ReflogEntry> reflog = reflogCommand.call();
        return !reflog.isEmpty();
    } catch (InvalidRefNameException ex) {
        return false;
    }
}

From source file:org.enterprisedomain.classmaker.impl.ContributionImpl.java

License:Apache License

/**
 * <!-- begin-user-doc --> <!-- end-user-doc -->
 * /*from   ww  w.j  a  va 2 s .  com*/
 * @generated NOT
 */
public String initialize(boolean commit) {
    @SuppressWarnings("unchecked")
    SCMOperator<Git> operator = (SCMOperator<Git>) getWorkspace().getSCMRegistry().get(getProjectName());
    setName(getProjectName());
    try {
        Git git = operator.getRepositorySCM();
        // if (git == null)
        // return "";
        String currentBranch = git.getRepository().getBranch();

        ListBranchCommand listBranches = git.branchList();
        List<Ref> branches = listBranches.call();
        Iterator<Ref> it = branches.iterator();
        Ref branch = null;
        long timestamp = -1;
        String commitId = "";
        do {
            Version version = null;
            if (it.hasNext()) {
                branch = it.next();
                String[] name = branch.getName().split("/"); //$NON-NLS-1$
                try {
                    version = operator.decodeVersion(name[name.length - 1]);
                    ReflogCommand reflog = git.reflog();
                    reflog.setRef(branch.getName().toString());
                    Collection<ReflogEntry> refs = reflog.call();
                    for (ReflogEntry ref : refs)
                        if (ref.getNewId().equals(branch.getObjectId())) {
                            timestamp = operator.decodeTimestamp(ref.getComment());
                            if (timestamp == -1)
                                timestamp = operator.decodeTimestamp(version.getQualifier());
                        }
                } catch (IllegalArgumentException e) {
                    continue;
                }
            }
            if (version != null && !getRevisions().containsKey(version)) {
                Revision newRevision = newBareRevision(version);
                newRevision.setTimestamp(timestamp);
                newRevision.setProject(this);
                doNewRevision(newRevision);
                commitId = newRevision.initialize(commit);
            }
        } while (it.hasNext());
        if (!getRevisions().isEmpty() && getVersion().equals(Version.emptyVersion))
            setVersion(ListUtil.getLast(getRevisions()).getKey());
        else if (!getVersion().equals(Version.emptyVersion))
            checkout(getVersion(), timestamp);
        if (currentBranch.equals(SCMOperator.MASTER_BRANCH))
            checkout(getVersion(), timestamp);
        getWorkspace().getResourceSet().eAdapters().add(resourceAdapter);
        addResourceChangeListener(getResourceReloadListener());
        return commitId;
    } catch (Exception e) {
        ClassMakerPlugin.getInstance().getLog().log(ClassMakerPlugin.createErrorStatus(e));
        return null;
    } finally {
        try {
            operator.ungetRepositorySCM();
        } catch (Exception e) {
            ClassMakerPlugin.getInstance().getLog().log(ClassMakerPlugin.createErrorStatus(e));
        }
    }

}