else {
// the preferred version THEIRS has a different mode
// than ours. Check it out!
if (isWorktreeDirty())
return false;
DirCacheEntry e = add(tw.getRawPath(), theirs,
DirCacheEntry.STAGE_0);
toBeCheckedOut.put(tw.getPathString(), e);
}
return true;
} else {
// FileModes are not mergeable. We found a conflict on modes
add(tw.getRawPath(), base, DirCacheEntry.STAGE_1);
add(tw.getRawPath(), ours, DirCacheEntry.STAGE_2);
add(tw.getRawPath(), theirs, DirCacheEntry.STAGE_3);
unmergedPaths.add(tw.getPathString());
mergeResults.put(
tw.getPathString(),
new MergeResult<RawText>(Collections
.<RawText> emptyList()));
}
return true;
}
}
if (nonTree(modeO) && modeB == modeT && tw.idEqual(T_BASE, T_THEIRS)) {
// THEIRS was not changed compared to BASE. All changes must be in
// OURS. OURS is chosen.
add(tw.getRawPath(), ours, DirCacheEntry.STAGE_0);
// no checkout needed!
return true;
}
if (modeB == modeO && tw.idEqual(T_BASE, T_OURS)) {
// OURS was not changed compared to BASE. All changes must be in
// THEIRS. THEIRS is chosen.
// Check worktree before checking out THEIRS
if (isWorktreeDirty())
return false;
if (nonTree(modeT)) {
DirCacheEntry e = add(tw.getRawPath(), theirs,
DirCacheEntry.STAGE_0);
if (e != null)
toBeCheckedOut.put(tw.getPathString(), e);
return true;
} else if (modeT == 0 && modeB != 0) {
// we want THEIRS ... but THEIRS contains the deletion of the
// file
toBeCheckedOut.put(tw.getPathString(), null);
return true;
}
}
if (tw.isSubtree()) {
// file/folder conflicts: here I want to detect only file/folder
// conflict between ours and theirs. file/folder conflicts between
// base/index/workingTree and something else are not relevant or
// detected later
if (nonTree(modeO) && !nonTree(modeT)) {
if (nonTree(modeB))
add(tw.getRawPath(), base, DirCacheEntry.STAGE_1);
add(tw.getRawPath(), ours, DirCacheEntry.STAGE_2);
unmergedPaths.add(tw.getPathString());
enterSubtree = false;
return true;
}
if (nonTree(modeT) && !nonTree(modeO)) {
if (nonTree(modeB))
add(tw.getRawPath(), base, DirCacheEntry.STAGE_1);
add(tw.getRawPath(), theirs, DirCacheEntry.STAGE_3);
unmergedPaths.add(tw.getPathString());
enterSubtree = false;
return true;
}
// ours and theirs are both folders or both files (and treewalk
// tells us we are in a subtree because of index or working-dir).
// If they are both folders no content-merge is required - we can
// return here.
if (!nonTree(modeO))
return true;
// ours and theirs are both files, just fall out of the if block
// and do the content merge
}
if (nonTree(modeO) && nonTree(modeT)) {
// Check worktree before modifying files
if (isWorktreeDirty())
return false;
MergeResult<RawText> result = contentMerge(base, ours, theirs);
File of = writeMergedFile(result);
updateIndex(base, ours, theirs, result, of);
if (result.containsConflicts())
unmergedPaths.add(tw.getPathString());
modifiedFiles.add(tw.getPathString());
} else if (modeO != modeT) {
// OURS or THEIRS has been deleted
if (((modeO != 0 && !tw.idEqual(T_BASE, T_OURS)) || (modeT != 0 && !tw
.idEqual(T_BASE, T_THEIRS)))) {
add(tw.getRawPath(), base, DirCacheEntry.STAGE_1);
add(tw.getRawPath(), ours, DirCacheEntry.STAGE_2);
DirCacheEntry e = add(tw.getRawPath(), theirs,
DirCacheEntry.STAGE_3);
// OURS was deleted checkout THEIRS
if (modeO == 0) {
// Check worktree before checking out THEIRS