[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