Example usage for org.eclipse.jgit.api ReflogCommand call

List of usage examples for org.eclipse.jgit.api ReflogCommand call

Introduction

In this page you can find the example usage for org.eclipse.jgit.api ReflogCommand call.

Prototype

@Override
public Collection<ReflogEntry> call() throws GitAPIException, InvalidRefNameException 

Source Link

Document

Run the reflog command

Usage

From source file:org.eclipse.egit.ui.internal.reflog.ReflogViewContentProvider.java

License:Open Source License

public Object[] getElements(Object inputElement) {
    if (inputElement instanceof ReflogInput) {
        ReflogInput input = (ReflogInput) inputElement;
        ReflogCommand command = new Git(input.repository).reflog();
        command.setRef(input.ref);//ww  w  . j  av a 2s .com
        try {
            return command.call().toArray();
        } catch (Exception e) {
            Activator.logError("Error running reflog command", e); //$NON-NLS-1$
        }
    }
    return new Object[0];
}

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

License:Open Source License

private static boolean hasReflog(Git git) throws Exception {
    try {/*from   w w  w .j  a va2  s .  c  om*/
        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 -->
 * /* w ww. j av  a  2 s  . c  o m*/
 * @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));
        }
    }

}