and I'm experiencing just a tiny bit of poop in my test Git directory. To do the commit, I'm using code modified from egit and from a thread on the old list:
Is this normal behavior for JGit? Here's the Scala script I'm using to test JGit (should be fairly easy to read for a Java person).
import java.io.File
import java.io.IOException
import org.eclipse.jgit.lib.Commit
import org.eclipse.jgit.lib.Constants
import org.eclipse.jgit.lib.ObjectId
import org.eclipse.jgit.lib.ObjectWriter
import org.eclipse.jgit.lib.PersonIdent
import org.eclipse.jgit.lib.RefUpdate
import org.eclipse.jgit.lib.Repository
import org.eclipse.jgit.lib.Tree
import org.eclipse.jgit.dircache.DirCache
import org.eclipse.jgit.dircache.DirCacheEntry
import org.eclipse.jgit.lib.RepositoryState
val cache: File = new File("/tmp/xus/.git")
val repository: Repository = {
val rep = new Repository(cache)
if (!cache.exists) {
rep.create()
}
if (rep.getRepositoryState != RepositoryState.SAFE) {
throw new IOException("Repository state is not safe: "+rep.getRepositoryState)
}
rep
}
val index = repository.getIndex
val repoPath = repository.getDirectory.getParentFile
def pathsDo(dir: File, filter: (File) => Boolean)(block: (File) => Any) {
for (file <- dir.listFiles) {
if (filter(file)) {
if (file.isDirectory) {
pathsDo(file, filter)(block)
} else {
println("FILE: "+file.getName)
block(file)
}
}
}
}
pathsDo(repoPath, _.getName != ".git") {index.add(repoPath, _)}
index.write
val currentHeadId = repository.resolve(Constants.HEAD)
val commit = new Commit(repository, if (currentHeadId != null) Array(currentHeadId) else Array[ObjectId]())
commit.setTree(repository.mapTree(index.writeTree))
commit.setMessage("Test commit")
commit.setAuthor(author)
commit.setCommitter(author)
commit.setCommitId(new ObjectWriter(repository).writeCommit(commit))
val refUpdate = repository.updateRef(Constants.HEAD)
refUpdate.setNewObjectId(commit.getCommitId())
refUpdate.setRefLogMessage("commit: Test commit", false);
if (refUpdate.forceUpdate() == RefUpdate.Result.LOCK_FAILURE) {
throw new IOException("Failed to update " + refUpdate.getName + " to commit " + commit.getCommitId + ".");
}