Example usage for org.eclipse.jgit.api ResetCommand ResetCommand

List of usage examples for org.eclipse.jgit.api ResetCommand ResetCommand

Introduction

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

Prototype

public ResetCommand(Repository repo) 

Source Link

Document

Constructor for ResetCommand.

Usage

From source file:com.mpdeimos.ct_tests.looper.GitRevisionLooper.java

License:Apache License

/** {@inheritDoc} */
@Override/*from  w  ww .j  a  v  a  2  s  .co  m*/
public RevIterator iterator() {

    return new RevIterator() {
        int index = commits.size();

        @Override
        public void remove() {
            throw new IllegalStateException();
        }

        @Override
        public RevisionInfo next() {
            final Commit commit = commits.get(--index);

            return new RevisionInfo(commits.size() - index - 1, commit.getId(), commit, root) {
                /** {@inheritDoc} 
                 * @throws ConQATException */
                @Override
                public File getPath() throws ConQATException {
                    CheckoutCommand checkout = new CheckoutCommand(repository) {
                        /**/};
                    checkout.setName(commit.getId());
                    //checkout.setForce(true);
                    try {
                        checkout.call();
                    } catch (Exception e) {
                        getLogger().error(e);
                        ResetCommand reset = new ResetCommand(repository) {
                            /**/};
                        reset.setMode(ResetType.HARD);
                        reset.setRef(commit.getId());
                        try {
                            reset.call();
                            CheckoutCommand checkout2 = new CheckoutCommand(repository) {
                                /**/};
                            checkout2.setName(commit.getId());
                            //                        checkout2.setForce(true);
                            checkout2.call();
                        } catch (Exception e1) {
                            getLogger().error(e1);
                            throw new ConQATException(e1);
                        }
                    }
                    return super.getPath();
                }
            };
        }

        @Override
        public boolean hasNext() {
            return index > 0;
        }

        @Override
        public Commit peekCommit() {
            if (!hasNext())
                throw new IllegalStateException();

            return commits.get(index - 1);
        }
    };
}