Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EGit / JGit » [JGit] Commit modified files(DirCache doesn't commit modified files)
[JGit] Commit modified files [message #534916] 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));
        dirc.write();
        dirc.commit();        
        
        ObjectId currentHead = localRepository.resolve(Constants.HEAD);
        log.info("Current head ObjectId: " + currentHead.name());
        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.setAuthor(ident);
        commit.setCommitter(ident);
        commit.setMessage(commitMessage);
        commit.setTreeId(tree);
        commit.commit();
        log.info("Commited changes");

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

        RefUpdate ru = localRepository.updateRef(Constants.HEAD);
        ru.setNewObjectId(id);
        ru.setRefLogIdent(ident);
        ru.setRefLogMessage(commitMessage, true);
        Result result = ru.update();
        log.info("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) {
        log.info("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));
            index.write();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }


So does someone have an idea on how it is meant to be done?
Previous Topic:Maven repository unavailable
Next Topic:[JGit] Commit modified files
Goto Forum:
  


Current Time: Tue Mar 19 07:43:45 GMT 2024

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

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

Back to the top