Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[jgit-dev] How to update index and working-tree?


how should I use jgit to update the working-tree and the index after a successful (conflict-free) merge?

Imagine a merge operation (e.g. the has successfully done a merge. Then I can can get the
resulting tree from the merger and create a merge commit for this tree. 
What do I have to do in order to bring my index and the working tree up to date after doing the commit and refupdates? 
Here is some code from jgit proposal,320 which doesn't work well and which doesn't
look optimal:

GitIndex index = db.getIndex();
Merger merger = mergeStrategy.newMerger(db);
boolean merge = merger.merge(...)

if (!merge) throw die("merge failed");

// commit the merge
final Commit mergeCommit = new Commit(db);
mergeCommit.setParentIds(new ObjectId[] { .... });

// update the HEAD

// update the index.
// I am just overwriting the index. This is (if at all) only safe if the
// index was clean (was matching exactly HEAD state) before the merge

// checkout the index
File workDir = db.getWorkDir();
if (workDir != null) {
	WorkDirCheckout workDirCheckout = new WorkDirCheckout(db, workDir, index, mergeCommit.getTree());


Back to the top