diff options
Diffstat (limited to 'org.eclipse.jgit')
3 files changed, 43 insertions, 1 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCache.java b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCache.java index 189787dd9e..3a8abc1a73 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCache.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCache.java @@ -784,4 +784,20 @@ public class DirCache { throws UnmergedPathException, IOException { 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; + } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java index e2d3da6bc2..9f4bb100f8 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java @@ -60,6 +60,7 @@ import java.util.Set; import java.util.Vector; import java.util.concurrent.atomic.AtomicInteger; +import org.eclipse.jgit.dircache.DirCache; import org.eclipse.jgit.errors.ConfigInvalidException; import org.eclipse.jgit.errors.IncorrectObjectTypeException; import org.eclipse.jgit.errors.RevisionSyntaxException; @@ -1117,8 +1118,22 @@ public class Repository { return RepositoryState.REBASING_MERGE; // 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; + } + if (new File(gitDir,"BISECT_LOG").exists()) return RepositoryState.BISECTING; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/RepositoryState.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/RepositoryState.java index 6159839b13..901d1b516b 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/RepositoryState.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/RepositoryState.java @@ -74,6 +74,17 @@ public enum RepositoryState { }, /** + * 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 */ REBASING { |