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?
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.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With