git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[JGIT] help needed to create a siimple commit

From
Yann Simon <yann.simon.fr@gmail.com>
Date
Feb 3, 2009, 11:07 UTC
Message-ID
<551f769b0902030307s2a9204cch7967df17c1f2c8a6@mail.gmail.com>
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
Next: Shawn O. Pearce
Message 1 of 4 in “[JGIT] help needed to create a siimple commit”
  1. Yann SimonFeb 3, 2009
  2. Shawn O. PearceFeb 3, 2009
  3. Yann SimonFeb 4, 2009
  4. Shawn O. PearceFeb 4, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.