Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[jgit-dev] Transient poopies after JGit commit

I'm using JGit in my Xus project, which I talk about here: http://this-statement-is-false.blogspot.com/ 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: 
https://kerneltrap.org/mailarchive/git/2009/2/4/4899784/thread

After I run my code, when I open gitk in the git project directory in which I just committed, gitk says there are "Local uncommitted changes, not checked into index".  When I select that item in gitk, it displays a list of all of the files in the diff area, but there are no diff contents for any of the files; just an empty entry under each file name.  After I use git gui or git status and then reload or reopen gitk, the uncommitted changes item is no longer in the 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).


thanks,
Bill Burdick


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 author: PersonIdent = new PersonIdent("Bubba", "gump@xxxxxxxxxx")
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 + ".");
}


Back to the top