Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EGit » add content without file
add content without file [message #1060939] Wed, 29 May 2013 05:04 Go to next message
Eugene   is currently offline Eugene
Messages: 26
Registered: July 2009
Junior Member
Hi,

Is it possible with JGit to add content to git somehow without saving it to a file before? Something similar to

echo 'test content' | git hash-object -w --stdin

Best regards, Eugene.
Re: add content without file [message #1060968 is a reply to message #1060939] Wed, 29 May 2013 07:01 Go to previous messageGo to next message
Christian Halstrick is currently offline Christian Halstrick
Messages: 93
Registered: July 2009
Member
One strategy how to find out "how to do ... with jgit" is: find a command in the org.eclipse.jgit.api package which does something similar to what you want. Even if you don't find exactly what you need you'll find hints by inspectinging the source code there.

In your case: we don't have a HashObject command, but we have a AddCommand which does what "git add ..." does. By reading the relatively small file [1] you should find out how to add content to the index without having the content stored in the file. If want to pump directly into the object database without dealing with the index use:

Git r = Git.open(new File("/home/user/git/myRepo"));
ObjectInserter inserter = r.getRepository().getObjectDatabase().newInserter();
ObjectId obj = inserter.insert(Constants.OBJ_BLOB, new byte[] {1,2,3,4});
inserter.flush();
System.out.println("Inserted a new blob: "+obj);


[1] https://github.com/eclipse/jgit/blob/master/org.eclipse.jgit/src/org/eclipse/jgit/api/AddCommand.java


Ciao
Chris
Re: add content without file [message #1060996 is a reply to message #1060968] Wed, 29 May 2013 09:21 Go to previous message
Eugene   is currently offline Eugene
Messages: 26
Registered: July 2009
Junior Member
Thank you!
Previous Topic:JGit RevWalk.isMergedInto()
Next Topic:Where are the icon decorations?
Goto Forum:
  


Current Time: Sun Apr 20 19:51:15 EDT 2014

Powered by FUDForum. Page generated in 0.02507 seconds