diff options
author | Robin Stocker <robin@nibor.org> | 2012-09-22 21:27:01 +0200 |
---|---|---|
committer | Robin Stocker <robin@nibor.org> | 2012-09-23 02:41:51 +0200 |
commit | ac805874f72fe2c6193bc959865fb525e069e45e (patch) | |
tree | e594580e7d5a261f8658806c3699effc2b9ec854 /org.eclipse.jgit | |
parent | eb5b506acdd22c3e5d97d9b3efaf978659ef07f4 (diff) | |
download | jgit-ac805874f72fe2c6193bc959865fb525e069e45e.tar.gz jgit-ac805874f72fe2c6193bc959865fb525e069e45e.zip |
Refuse to checkout unmerged paths from index
Without this check, the checkout was done but the result was a "both
deleted" status when inspecting it with C Git.
Found this while working on bug 390147.
Change-Id: Ic3693f2c651827239e838bf7f37da842a7ae9707
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/api/CheckoutCommand.java | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/CheckoutCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/CheckoutCommand.java index d8efbe7a61..57f47a4968 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/CheckoutCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/CheckoutCommand.java @@ -64,6 +64,7 @@ import org.eclipse.jgit.dircache.DirCacheEditor.PathEdit; import org.eclipse.jgit.dircache.DirCacheEntry; import org.eclipse.jgit.dircache.DirCacheIterator; import org.eclipse.jgit.errors.AmbiguousObjectException; +import org.eclipse.jgit.errors.UnmergedPathException; import org.eclipse.jgit.internal.JGitText; import org.eclipse.jgit.lib.AnyObjectId; import org.eclipse.jgit.lib.Constants; @@ -284,7 +285,8 @@ public class CheckoutCommand extends GitCommand<Ref> { startWalk.setRecursive(true); if (!checkoutAllPaths) startWalk.setFilter(PathFilterGroup.createFromStrings(paths)); - boolean checkoutIndex = startCommit == null && startPoint == null; + final boolean checkoutIndex = startCommit == null + && startPoint == null; if (!checkoutIndex) startWalk.addTree(revWalk.parseCommit(getStartPoint()) .getTree()); @@ -299,6 +301,11 @@ public class CheckoutCommand extends GitCommand<Ref> { final FileMode mode = startWalk.getFileMode(0); editor.add(new PathEdit(startWalk.getPathString()) { public void apply(DirCacheEntry ent) { + if (checkoutIndex + && ent.getStage() > DirCacheEntry.STAGE_0) { + UnmergedPathException e = new UnmergedPathException(ent); + throw new JGitInternalException(e.getMessage(), e); + } ent.setObjectId(blobId); ent.setFileMode(mode); File file = new File(workTree, ent.getPathString()); |