Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EGit / JGit » [JGit] Commit modified files
[JGit] Commit modified files [message #580456] Thu, 20 May 2010 15:53
Kristof  is currently offline Kristof Friend
Messages: 2
Registered: May 2010
Junior Member
I'm trying to commit added/modified/deleted/missing files (like commit -a). When I use the code below added/deleted/missing files are commited. Modified files are not commited within this step.

DirCache dirc = DirCache.lock(localRepository);
ObjectId tree = dirc.writeTree(new ObjectWriter(localRepository));

ObjectId currentHead = localRepository.resolve(Constants.HEAD);"Current head ObjectId: " +;
ObjectId[] parentIds;
if (currentHead != null) {
parentIds = new ObjectId[] { currentHead };
} else {
parentIds = new ObjectId[0];

Commit commit = new Commit(localRepository, parentIds);
PersonIdent ident = new PersonIdent(developerName, developerEmail);
commit.commit();"Commited changes");

ObjectId id = commit.getCommitId();"ObjectId of this commit is: " +;

RefUpdate ru = localRepository.updateRef(Constants.HEAD);
ru.setRefLogMessage(commitMessage, true);
Result result = ru.update();"Result is " + result.toString());

I also tried to use the DirCacheEditor and made a subclass MyPathEdit and implemented apply (see below) which obviously fails because the index file is locked by DirCache.

public void apply(DirCacheEntry ent) {"Apply invoked for entry " + ent.getPathString());
String entPath = repository.getWorkDir().getAbsolutePath() + File.separator + ent.getPathString();
try {
GitIndex index = repository.getIndex();
index.add(repository.getWorkDir(), new File(entPath));
} catch (IOException e) {


So does someone have an idea on how it is meant to be done?
Previous Topic:[JGit] Commit modified files
Next Topic:Deleted folder still visible in GitHub
Goto Forum:

Current Time: Wed May 27 07:57:05 GMT 2020

Powered by FUDForum. Page generated in 0.01799 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top