Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[jgit-dev] (no subject)

Hi,

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 InCoreMerger.java) 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 http://egit.eclipse.org/r/#change,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.setTreeId(merger.getResultTreeId());
mergeCommit.setParentIds(new ObjectId[] { .... });
...
mergeCommit.setCommitId(merger.getObjectWriter().writeCommit(mergeCommit));

// 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
index.readTree(mergeCommit.getTree());
index.write();

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


---
  Ciao
    Chris

Back to the top