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

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

Introduction

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

Prototype

public static Git open(File dir, FS fs) throws IOException 

Source Link

Document

Open repository

Usage

From source file:org.exist.git.xquery.Merge.java

License:Open Source License

@Override
public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {

    try {//from   w ww.j  a  v  a2 s . c om
        String localPath = args[0].getStringValue();
        if (!(localPath.endsWith("/")))
            localPath += File.separator;

        Git git = Git.open(new Resource(localPath), FS);

        MergeResult res = git.merge()
                //                   .include("foo")
                .call(); // actually do the merge

        return new StringValue(res.getMergeStatus().toString());

    } catch (Throwable e) {
        throw new XPathException(this, Module.EXGIT001, e);
    }
}

From source file:org.exist.git.xquery.Pull.java

License:Open Source License

@Override
public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {

    try {/*ww w.ja v  a2  s  .  c o m*/
        String localPath = args[0].getStringValue();
        if (!(localPath.endsWith("/")))
            localPath += File.separator;

        Git git = Git.open(new Resource(localPath), FS);

        PullResult answer = git.pull().setCredentialsProvider(
                new UsernamePasswordCredentialsProvider(args[1].getStringValue(), args[2].getStringValue()))
                .call();

        MemTreeBuilder builder = getContext().getDocumentBuilder();

        int nodeNr = builder.startElement(PULL, null);
        builder.addAttribute(IS_SUCCESSFUL, Boolean.toString(answer.isSuccessful()));

        MergeResult merge = answer.getMergeResult();

        if (merge != null) {
            builder.startElement(MERGE, null);
            builder.addAttribute(STATUS, merge.getMergeStatus().toString());
            builder.addAttribute(IS_SUCCESSFUL, Boolean.toString(merge.getMergeStatus().isSuccessful()));

            for (ObjectId commit : merge.getMergedCommits()) {
                builder.startElement(COMMIT, null);

                builder.addAttribute(ID, commit.name());

                builder.endElement();
            }
            builder.endElement();

            if (merge.getConflicts() != null) {
                for (Entry<String, int[][]> entry : merge.getConflicts().entrySet()) {
                    builder.startElement(CHECKOUT_CONFLICT, null);
                    builder.addAttribute(PATH, entry.getKey());

                    builder.endElement();
                }

            }

            if (merge.getCheckoutConflicts() != null) {
                for (String path : merge.getCheckoutConflicts()) {
                    builder.startElement(CHECKOUT_CONFLICT, null);
                    builder.addAttribute(PATH, path);

                    builder.endElement();
                }
            }

            if (merge.getFailingPaths() != null) {
                for (Entry<String, MergeFailureReason> entry : merge.getFailingPaths().entrySet()) {
                    builder.startElement(FAILING_PATH, null);
                    builder.addAttribute(PATH, entry.getKey());
                    builder.addAttribute(REASON, entry.getValue().name());

                    builder.endElement();
                }
            }
        }

        RebaseResult rebase = answer.getRebaseResult();

        if (rebase != null) {
            builder.startElement(REBASE, null);
            builder.addAttribute(STATUS, rebase.getStatus().toString());
            builder.addAttribute(IS_SUCCESSFUL, Boolean.toString(rebase.getStatus().isSuccessful()));

            //rebase.getConflicts()

            if (rebase.getFailingPaths() != null) {
                for (Entry<String, MergeFailureReason> entry : rebase.getFailingPaths().entrySet()) {
                    builder.startElement(FAILING_PATH, null);
                    builder.addAttribute(PATH, entry.getKey());
                    builder.addAttribute(REASON, entry.getValue().name());

                    builder.endElement();
                }
            }
            builder.endElement();
        }

        return builder.getDocument().getNode(nodeNr);
    } catch (Throwable e) {
        e.printStackTrace();
        throw new XPathException(this, Module.EXGIT001, e);
    }
}

From source file:org.exist.git.xquery.Push.java

License:Open Source License

@Override
public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {

    try {/* w  w w. j a  va 2  s .  c  om*/
        String localPath = args[0].getStringValue();
        if (!(localPath.endsWith("/")))
            localPath += File.separator;

        Git git = Git.open(new Resource(localPath), FS);

        Iterable<PushResult> answer = git.push().setCredentialsProvider(
                new UsernamePasswordCredentialsProvider(args[1].getStringValue(), args[2].getStringValue()))
                .call();

        MemTreeBuilder builder = getContext().getDocumentBuilder();

        int nodeNr = builder.startElement(PUSH, null);

        for (PushResult push : answer) {

            builder.startElement(RESULT, null);

            for (TrackingRefUpdate tracking : push.getTrackingRefUpdates()) {

                builder.startElement(TRACKING_REF_UPDATE, null);

                builder.addAttribute(REMOTE_NAME, tracking.getRemoteName());
                builder.addAttribute(LOCAL_NAME, tracking.getLocalName());

                //builder.addAttribute(FORCE_UPDATE, Boolean.toString(tracking.forceUpdate));

                builder.addAttribute(OLD_OBJECTID, tracking.getOldObjectId().name());
                builder.addAttribute(NEW_OBJECTID, tracking.getNewObjectId().name());
            }

            for (RemoteRefUpdate remote : push.getRemoteUpdates()) {

                builder.startElement(REMOTE_REF_UPDATE, null);

                builder.addAttribute(REMOTE_NAME, remote.getRemoteName());
                builder.addAttribute(STATUS, remote.getStatus().name());

                if (remote.isExpectingOldObjectId())
                    builder.addAttribute(EXPECTED_OLD_OBJECTID, remote.getExpectedOldObjectId().name());

                if (remote.getNewObjectId() != null)
                    builder.addAttribute(NEW_OBJECTID, remote.getNewObjectId().name());

                builder.addAttribute(FAST_FORWARD, Boolean.toString(remote.isFastForward()));
                builder.addAttribute(FORCE_UPDATE, Boolean.toString(remote.isForceUpdate()));

                if (remote.getMessage() != null)
                    builder.characters(remote.getMessage());

                builder.endElement();
            }
            builder.endElement();
        }

        builder.endElement();

        return builder.getDocument().getNode(nodeNr);
    } catch (Throwable e) {
        e.printStackTrace();
        throw new XPathException(this, Module.EXGIT001, e);
    }
}

From source file:org.exist.git.xquery.Remove.java

License:Open Source License

@Override
public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {

    try {/*from  w  ww .j av a2s.  c  o m*/
        String localPath = args[0].getStringValue();
        if (!(localPath.endsWith("/")))
            localPath += File.separator;

        Git git = Git.open(new Resource(localPath), FS);

        git.rm().addFilepattern(args[1].getStringValue()).call();

        return BooleanValue.TRUE;
    } catch (Throwable e) {
        throw new XPathException(this, Module.EXGIT001, e);
    }
}

From source file:org.exist.git.xquery.Reset.java

License:Open Source License

@Override
public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {
    ResetType type;//from  w w w  .java  2s .  c  om

    String sType = args[1].getStringValue();
    if ("KEEP".equalsIgnoreCase(sType)) {
        type = ResetType.KEEP;
    } else if ("MERGE".equalsIgnoreCase(sType)) {
        type = ResetType.MERGE;
    } else if ("HARD".equalsIgnoreCase(sType)) {
        type = ResetType.HARD;
    } else if ("SOFT".equalsIgnoreCase(sType)) {
        type = ResetType.SOFT;
    } else if ("MIXED".equalsIgnoreCase(sType)) {
        type = ResetType.MIXED;
    } else {
        throw new XPathException(this, "Unknow type '" + sType + "'.");
    }

    try {
        String localPath = args[0].getStringValue();
        if (!(localPath.endsWith("/")))
            localPath += File.separator;

        Git git = Git.open(new Resource(localPath), FS);

        git.reset().setMode(type).call();

        return BooleanValue.TRUE;
    } catch (Throwable e) {
        throw new XPathException(this, Module.EXGIT001, e);
    }
}

From source file:org.exist.git.xquery.Status.java

License:Open Source License

@Override
public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {

    try {/*from ww w. j  a  v a2 s  . co  m*/
        String localPath = args[0].getStringValue();
        if (!(localPath.endsWith("/")))
            localPath += File.separator;

        Git git = Git.open(new Resource(localPath), FS);

        if (getName().equals(STATUS)) {
            MemTreeBuilder builder = getContext().getDocumentBuilder();

            int nodeNr = builder.startElement(REPOSITORY, null);
            StatusBuilder statusBuilder = new StatusBuilder(builder);

            final Repository repo = git.getRepository();
            diff(repo, Constants.HEAD, new FileTreeIterator(repo), statusBuilder, args[1].getStringValue(),
                    args[2].effectiveBooleanValue());

            builder.endElement();

            return builder.getDocument().getNode(nodeNr);
        }

        org.eclipse.jgit.api.Status status = git.status().call();

        Set<String> list;

        if (getName().equals(UNTRACKED)) {
            list = status.getUntracked();

        } else if (getName().equals(ADDED)) {
            list = status.getAdded();

        } else if (getName().equals(CHANGED)) {
            list = status.getChanged();

        } else if (getName().equals(CONFLICTING)) {
            list = status.getConflicting();

        } else if (getName().equals(IGNORED)) {
            list = status.getIgnoredNotInIndex();

        } else if (getName().equals(MISSING)) {
            list = status.getMissing();

        } else if (getName().equals(MODIFIED)) {
            list = status.getModified();

        } else if (getName().equals(REMOVED)) {
            list = status.getRemoved();

        } else if (getName().equals(UNTRACKED)) {
            list = status.getUntracked();

        } else if (getName().equals(UNTRACKED_FOLDERS)) {
            list = status.getUntrackedFolders();

        } else {
            return Sequence.EMPTY_SEQUENCE;
        }

        Sequence result = new ValueSequence();
        for (String modified : list) {
            result.add(new StringValue(modified));
        }

        return result;
    } catch (Throwable e) {
        e.printStackTrace();
        throw new XPathException(this, Module.EXGIT001, e);
    }
}

From source file:org.exist.git.xquery.Tag.java

License:Open Source License

@Override
public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {

    try {// w  w w. j a  va 2s.c  om
        String localPath = args[0].getStringValue();
        if (!(localPath.endsWith("/")))
            localPath += File.separator;

        Git git = Git.open(new Resource(localPath), FS);

        git.tag().setName(args[1].getStringValue()).call();

        return BooleanValue.TRUE;
    } catch (Throwable e) {
        throw new XPathException(this, Module.EXGIT001, e);
    }
}