Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a JGit plumbing API?

Tags:

java

git

jgit

I need to use git plumbing commands (such as those used in chapter 9 of the git book) like git hash-object, git write-tree, git commit-tree and all the rest. Is there a nice API to do these in JGit (I can't seem to find one) or how would you do something basic like write from an output stream or file to a blob/what do you use instead of the git commands?

like image 894
Callum Rogers Avatar asked Sep 15 '25 12:09

Callum Rogers


2 Answers

Welcome to the JGit API. Other than the high-level porcelain API in package org.eclipse.jgit.api the low level API isn't built in close correlation to the plumbing commands of native git. This is due to the fact that JGit is a Java library and not a command line interface.

If you need examples first look at the > 2000 JGit test cases. Next have a look into how EGit is using JGit. If this doesn't help come back and ask more specific questions.

like image 59
Matthias Sohn Avatar answered Sep 18 '25 04:09

Matthias Sohn


If there is, it should be in JGit.

For instance, the DirCache object (ie, the Git Index) has a WriteTree function:

/**
 * Write all index trees to the object store, returning the root tree.
 *
 * @param ow
 *   the writer to use when serializing to the store. The caller is
 *   responsible for flushing the inserter before trying to use the
 *   returned tree identity.
 * @return identity for the root tree.
 * @throws UnmergedPathException
 *   one or more paths contain higher-order stages (stage > 0),
 *   which cannot be stored in a tree object.
 * @throws IllegalStateException
 *   one or more paths contain an invalid mode which should never
 *   appear in a tree object.
 * @throws IOException
 *   an unexpected error occurred writing to the object store.
 */
public ObjectId writeTree(final ObjectInserter ow)
like image 34
VonC Avatar answered Sep 18 '25 05:09

VonC