git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [JGIT] help needed to create a siimple commit
@ 2009-02-03 11:07 Yann Simon
  2009-02-03 15:51 ` Shawn O. Pearce
  0 siblings, 1 reply; 4+ messages in thread
From: Yann Simon @ 2009-02-03 11:07 UTC (permalink / raw)
  To: Shawn O. Pearce, Robin Rosenberg; +Cc: git

Hi,

I wrote the following unit test to learn how to make a commit with JGIT:

package org.spearce.jgit.lib;

import java.io.File;
import java.io.IOException;

public class CommitTest extends RepositoryTestCase {

	public void testASimpleCommit() throws IOException {
		
		GitIndex index = new GitIndex(db);
		index.filemode = Boolean.TRUE;
		
		File file;
		file = writeTrashFile("file1", "file1");
		
		index.add(trash, file);
		index.write();
		ObjectId objectId = index.writeTree();
		Tree tree = db.mapTree(objectId);
		tree.accept(new WriteTree(trash, db), TreeEntry.MODIFIED_ONLY);
		
		final Commit c1 = new Commit(db);
		c1.setAuthor(new PersonIdent(jauthor, 1154236443000L, -4 * 60));
		c1.setCommitter(new PersonIdent(jcommitter, 1154236443000L, -4 * 60));
		c1.setMessage("A Commit\n");
		c1.setTree(tree);
		assertEquals(tree.getTreeId(), c1.getTreeId());
		c1.commit();
		
	}
}

But the result is not brillant.
In the trash workspace, git log does not show me my commit.
git diff --cached shows me that my file is in the index but not committed...

Thank for the help.

Yann

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2009-02-04 17:08 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-02-03 11:07 [JGIT] help needed to create a siimple commit Yann Simon
2009-02-03 15:51 ` Shawn O. Pearce
2009-02-04 16:10   ` Yann Simon
2009-02-04 17:07     ` Shawn O. Pearce

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).