for (int i = 0; i < ents.length; i++) | for (int i = 0; i < ents.length; i++) | ||||
b.add(ents[i]); | b.add(ents[i]); | ||||
b.finish(); | b.finish(); | ||||
assertFalse(dc.hasUnmergedPaths()); | |||||
assertEquals(paths.length, dc.getEntryCount()); | assertEquals(paths.length, dc.getEntryCount()); | ||||
dc.clear(); | dc.clear(); | ||||
assertEquals(0, dc.getEntryCount()); | assertEquals(0, dc.getEntryCount()); | ||||
assertFalse(dc.hasUnmergedPaths()); | |||||
} | |||||
public void testDetectUnmergedPaths() throws Exception { | |||||
final DirCache dc = DirCache.read(db); | |||||
final DirCacheEntry[] ents = new DirCacheEntry[3]; | |||||
ents[0] = new DirCacheEntry("a", 1); | |||||
ents[0].setFileMode(FileMode.REGULAR_FILE); | |||||
ents[1] = new DirCacheEntry("a", 2); | |||||
ents[1].setFileMode(FileMode.REGULAR_FILE); | |||||
ents[2] = new DirCacheEntry("a", 3); | |||||
ents[2].setFileMode(FileMode.REGULAR_FILE); | |||||
final DirCacheBuilder b = dc.builder(); | |||||
for (int i = 0; i < ents.length; i++) | |||||
b.add(ents[i]); | |||||
b.finish(); | |||||
assertTrue(dc.hasUnmergedPaths()); | |||||
} | } | ||||
public void testFindOnEmpty() throws Exception { | public void testFindOnEmpty() throws Exception { |
throws UnmergedPathException, IOException { | throws UnmergedPathException, IOException { | ||||
return getCacheTree(true).writeTree(sortedEntries, 0, 0, ow); | return getCacheTree(true).writeTree(sortedEntries, 0, 0, ow); | ||||
} | } | ||||
/** | |||||
* Tells whether this index contains unmerged paths. | |||||
* | |||||
* @return {@code true} if this index contains unmerged paths. Means: at | |||||
* least one entry is of a stage different from 0. {@code false} | |||||
* will be returned if all entries are of stage 0. | |||||
*/ | |||||
public boolean hasUnmergedPaths() { | |||||
for (int i = 0; i < entryCnt; i++) { | |||||
if (sortedEntries[i].getStage() > 0) { | |||||
return true; | |||||
} | |||||
} | |||||
return false; | |||||
} | |||||
} | } |
import java.util.Vector; | import java.util.Vector; | ||||
import java.util.concurrent.atomic.AtomicInteger; | import java.util.concurrent.atomic.AtomicInteger; | ||||
import org.eclipse.jgit.dircache.DirCache; | |||||
import org.eclipse.jgit.errors.ConfigInvalidException; | import org.eclipse.jgit.errors.ConfigInvalidException; | ||||
import org.eclipse.jgit.errors.IncorrectObjectTypeException; | import org.eclipse.jgit.errors.IncorrectObjectTypeException; | ||||
import org.eclipse.jgit.errors.RevisionSyntaxException; | import org.eclipse.jgit.errors.RevisionSyntaxException; | ||||
return RepositoryState.REBASING_MERGE; | return RepositoryState.REBASING_MERGE; | ||||
// Both versions | // Both versions | ||||
if (new File(gitDir,"MERGE_HEAD").exists()) | |||||
if (new File(gitDir, "MERGE_HEAD").exists()) { | |||||
// we are merging - now check whether we have unmerged paths | |||||
try { | |||||
if (!DirCache.read(this).hasUnmergedPaths()) { | |||||
// no unmerged paths -> return the MERGING_RESOLVED state | |||||
return RepositoryState.MERGING_RESOLVED; | |||||
} | |||||
} catch (IOException e) { | |||||
// Can't decide whether unmerged paths exists. Return | |||||
// MERGING state to be on the safe side (in state MERGING | |||||
// you are not allow to do anything) | |||||
e.printStackTrace(); | |||||
} | |||||
return RepositoryState.MERGING; | return RepositoryState.MERGING; | ||||
} | |||||
if (new File(gitDir,"BISECT_LOG").exists()) | if (new File(gitDir,"BISECT_LOG").exists()) | ||||
return RepositoryState.BISECTING; | return RepositoryState.BISECTING; | ||||
public String getDescription() { return "Conflicts"; } | public String getDescription() { return "Conflicts"; } | ||||
}, | }, | ||||
/** | |||||
* An merge where all conflicts have been resolved. The index does not | |||||
* contain any unmerged paths. | |||||
*/ | |||||
MERGING_RESOLVED { | |||||
public boolean canCheckout() { return true; } | |||||
public boolean canResetHead() { return true; } | |||||
public boolean canCommit() { return true; } | |||||
public String getDescription() { return "Merged"; } | |||||
}, | |||||
/** | /** | ||||
* An unfinished rebase or am. Must resolve, skip or abort before normal work can take place | * An unfinished rebase or am. Must resolve, skip or abort before normal work can take place | ||||
*/ | */ |