Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EGit / JGit » add content without file
add content without file [message #1060939] Wed, 29 May 2013 09:04 Go to next message
Eugene   is currently offline Eugene Friend
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 11:01 Go to previous messageGo to next message
Christian Halstrick is currently offline Christian HalstrickFriend
Messages: 274
Registered: July 2009
Senior 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 13:21 Go to previous message
Eugene   is currently offline Eugene Friend
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: Tue Mar 19 11:20:06 GMT 2024

Powered by FUDForum. Page generated in 0.02653 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top