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());
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(); } }