List of usage examples for org.eclipse.jgit.api Git open
public static Git open(File dir, FS fs) throws IOException
From source file:org.exist.git.xquery.Add.java
License:Open Source License
@Override public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException { try {//from www. j a va 2 s.com String localPath = args[0].getStringValue(); if (!(localPath.endsWith("/"))) localPath += File.separator; Git git = Git.open(new Resource(localPath), FS); AddCommand command = git.add(); for (int i = 0; i < args[1].getItemCount(); i++) { command.addFilepattern(args[1].itemAt(i).getStringValue()); } command.call(); return BooleanValue.TRUE; } catch (Throwable e) { Throwable cause = e.getCause(); if (cause != null) { throw new XPathException(this, Module.EXGIT001, cause.getMessage()); } throw new XPathException(this, Module.EXGIT001, e); } }
From source file:org.exist.git.xquery.BranchCreate.java
License:Open Source License
@Override public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException { try {//from w w w .j a v a 2 s . c o m String localPath = args[0].getStringValue(); if (!(localPath.endsWith("/"))) localPath += File.separator; Git git = Git.open(new Resource(localPath), FS); git.branchCreate().setName(args[1].getStringValue()) .setStartPoint( args.length <= 2 || args[2].isEmpty() ? Constants.HEAD : args[2].getStringValue()) .setUpstreamMode(SetupUpstreamMode.SET_UPSTREAM).setForce(true).call(); return BooleanValue.TRUE; } catch (Throwable e) { throw new XPathException(this, Module.EXGIT001, e); } }
From source file:org.exist.git.xquery.BranchDelete.java
License:Open Source License
@Override public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException { try {//from w ww.j a v a 2s. c o m String localPath = args[0].getStringValue(); if (!(localPath.endsWith("/"))) localPath += File.separator; Git git = Git.open(new Resource(localPath), FS); git.branchDelete().setBranchNames(args[1].getStringValue()).call(); return BooleanValue.TRUE; } catch (Throwable e) { throw new XPathException(this, Module.EXGIT001, e); } }
From source file:org.exist.git.xquery.BranchList.java
License:Open Source License
@Override public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException { try {//from ww w . j a v a 2s . c o m String localPath = args[0].getStringValue(); if (!(localPath.endsWith("/"))) localPath += File.separator; Git git = Git.open(new Resource(localPath), FS); Sequence result = new ValueSequence(); List<Ref> list = git.branchList().call(); for (Ref ref : list) { result.add(new StringValue(ref.getName())); } return result; } catch (Throwable e) { throw new XPathException(this, Module.EXGIT001, e); } }
From source file:org.exist.git.xquery.BranchRename.java
License:Open Source License
@Override public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException { try {/*from w w w .jav a 2s. c om*/ String localPath = args[0].getStringValue(); if (!(localPath.endsWith("/"))) localPath += File.separator; Git git = Git.open(new Resource(localPath), FS); git.branchRename().setOldName(args[1].getStringValue()).setNewName(args[2].getStringValue()).call(); return BooleanValue.TRUE; } catch (Throwable e) { throw new XPathException(this, Module.EXGIT001, e); } }
From source file:org.exist.git.xquery.Cat.java
License:Open Source License
@Override public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException { try {/*from www. j av a 2 s .c o m*/ String localPath = args[0].getStringValue(); if (!(localPath.endsWith("/"))) localPath += File.separator; String objPath = args[1].getStringValue(); if (mySignature.getName() == CAT_WORKING_COPY) { Resource resource = new Resource(localPath + objPath); InputStream is = new ResourceInputStream(resource); ; Base64BinaryDocument b64doc = Base64BinaryDocument.getInstance(context, is); return b64doc; } Git git = Git.open(new Resource(localPath), FS); Repository repository = git.getRepository(); // find the HEAD ObjectId lastCommitId = repository.resolve(Constants.HEAD); // now we have to get the commit RevWalk revWalk = new RevWalk(repository); RevCommit commit = revWalk.parseCommit(lastCommitId); // and using commit's tree find the path RevTree tree = commit.getTree(); TreeWalk treeWalk = new TreeWalk(repository); treeWalk.addTree(tree); treeWalk.setRecursive(true); treeWalk.setFilter(PathFilter.create(args[1].getStringValue())); if (!treeWalk.next()) { return Sequence.EMPTY_SEQUENCE; } ObjectId objectId = treeWalk.getObjectId(0); ObjectLoader loader = repository.open(objectId); // and then one can use either InputStream is = loader.openStream(); Base64BinaryDocument b64doc = Base64BinaryDocument.getInstance(context, is); return b64doc; } catch (Throwable e) { throw new XPathException(this, Module.EXGIT001, e); } }
From source file:org.exist.git.xquery.Checkout.java
License:Open Source License
@Override public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException { try {/*from w ww . ja v a 2 s . c o m*/ String localPath = args[0].getStringValue(); if (!(localPath.endsWith("/"))) localPath += File.separator; Git git = Git.open(new Resource(localPath), FS); git.checkout().setName(args[1].getStringValue()).setCreateBranch(false).setForce(true).call(); return BooleanValue.TRUE; } catch (Throwable e) { throw new XPathException(this, Module.EXGIT001, e); } }
From source file:org.exist.git.xquery.Commit.java
License:Open Source License
@Override public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException { try {/*from w w w . j a v a 2 s . com*/ String localPath = args[0].getStringValue(); if (!(localPath.endsWith("/"))) localPath += File.separator; Git git = Git.open(new Resource(localPath), FS); CommitCommand command = git.commit().setMessage(args[1].getStringValue()); // .setAuthor(name, email) // .setCommitter(name, email) if (args.length >= 3) { for (int i = 0; i < args[2].getItemCount(); i++) { command.setOnly(args[2].itemAt(i).getStringValue()); } } // command.setAll(true); command.call(); return BooleanValue.TRUE; } catch (Throwable e) { Throwable cause = e.getCause(); if (cause != null) { throw new XPathException(this, Module.EXGIT001, cause.getMessage()); } throw new XPathException(this, Module.EXGIT001, e); } }
From source file:org.exist.git.xquery.Diff.java
License:Open Source License
@Override public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException { try {// ww w. jav a2 s . c o m String localPath = args[0].getStringValue(); if (!(localPath.endsWith("/"))) localPath += File.separator; Git git = Git.open(new Resource(localPath), FS); //XXX: code git.diff().call(); return BooleanValue.TRUE; } catch (Throwable e) { throw new XPathException(this, Module.EXGIT001, e); } }
From source file:org.exist.git.xquery.Log.java
License:Open Source License
@Override public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException { try {// w w w .j av a2 s.c om String localPath = args[0].getStringValue(); if (!(localPath.endsWith("/"))) localPath += File.separator; // Repository localRepo = new FileRepository(localPath + ".git"); // Git git = new Git(localRepo); Git git = Git.open(new Resource(localPath), FS); MemTreeBuilder builder = context.getDocumentBuilder(); AttributesImpl attribs = new AttributesImpl(); attribs.addAttribute(NAMESPACE_URI, "local-path", PREFIX + ":local-path", "CDATA", localPath); int nodeNr = builder.startElement(LOG_ELEMENT, attribs); for (RevCommit commit : git.log().call()) { // commit.getParentCount(); // commit.getParents(); attribs = new AttributesImpl(); attribs.addAttribute(NAMESPACE_URI, "id", PREFIX + ":id", "CDATA", commit.name()); attribs.addAttribute(NAMESPACE_URI, "time", PREFIX + ":time", "CDATA", String.valueOf(commit.getCommitTime() * 1000L)); builder.startElement(COMMIT_ELEMENT, attribs); PersonIdent authorIdent = commit.getAuthorIdent(); builder.startElement(AUTHOR_ELEMENT, null); builder.startElement(AUTHOR_NAME_ELEMENT, null); builder.characters(authorIdent.getName()); builder.endElement(); builder.startElement(AUTHOR_EMAIL_ELEMENT, null); builder.characters(authorIdent.getEmailAddress()); builder.endElement(); builder.endElement(); builder.startElement(MESSAGE_ELEMENT, null); builder.characters(commit.getFullMessage()); builder.endElement(); builder.endElement(); } builder.endElement(); return builder.getDocument().getNode(nodeNr); } catch (Throwable e) { throw new XPathException(this, Module.EXGIT001, e); } }