Merge "CheckoutCommand: Fix checking out ours/theirs when no base stage exists" into stable-3.6
This commit is contained in:
commit
80b1da1aae
|
@ -43,6 +43,7 @@
|
||||||
package org.eclipse.jgit.api;
|
package org.eclipse.jgit.api;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -276,6 +277,39 @@ public void testCheckoutTheirs() throws Exception {
|
||||||
assertStageOneToThree(FILE1);
|
assertStageOneToThree(FILE1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCheckoutOursWhenNoBase() throws Exception {
|
||||||
|
String file = "added.txt";
|
||||||
|
|
||||||
|
git.checkout().setCreateBranch(true).setName("side")
|
||||||
|
.setStartPoint(initialCommit).call();
|
||||||
|
writeTrashFile(file, "Added on side");
|
||||||
|
git.add().addFilepattern(file).call();
|
||||||
|
RevCommit side = git.commit().setMessage("Commit on side").call();
|
||||||
|
|
||||||
|
git.checkout().setName("master").call();
|
||||||
|
writeTrashFile(file, "Added on master");
|
||||||
|
git.add().addFilepattern(file).call();
|
||||||
|
git.commit().setMessage("Commit on master").call();
|
||||||
|
|
||||||
|
git.merge().include(side).call();
|
||||||
|
assertEquals(RepositoryState.MERGING, db.getRepositoryState());
|
||||||
|
|
||||||
|
DirCache cache = DirCache.read(db.getIndexFile(), db.getFS());
|
||||||
|
assertEquals("Expected add/add file to not have base stage",
|
||||||
|
DirCacheEntry.STAGE_2, cache.getEntry(file).getStage());
|
||||||
|
|
||||||
|
assertTrue(read(file).startsWith("<<<<<<< HEAD"));
|
||||||
|
|
||||||
|
git.checkout().setStage(Stage.OURS).addPath(file).call();
|
||||||
|
|
||||||
|
assertEquals("Added on master", read(file));
|
||||||
|
|
||||||
|
cache = DirCache.read(db.getIndexFile(), db.getFS());
|
||||||
|
assertEquals("Expected conflict stages to still exist after checkout",
|
||||||
|
DirCacheEntry.STAGE_2, cache.getEntry(file).getStage());
|
||||||
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalStateException.class)
|
@Test(expected = IllegalStateException.class)
|
||||||
public void testStageNotPossibleWithBranch() throws Exception {
|
public void testStageNotPossibleWithBranch() throws Exception {
|
||||||
git.checkout().setStage(Stage.OURS).setStartPoint("master").call();
|
git.checkout().setStage(Stage.OURS).setStartPoint("master").call();
|
||||||
|
|
|
@ -405,14 +405,17 @@ private void checkoutPathsFromIndex(TreeWalk treeWalk, DirCache dc)
|
||||||
DirCacheIterator dci = new DirCacheIterator(dc);
|
DirCacheIterator dci = new DirCacheIterator(dc);
|
||||||
treeWalk.addTree(dci);
|
treeWalk.addTree(dci);
|
||||||
|
|
||||||
|
String previousPath = null;
|
||||||
|
|
||||||
final ObjectReader r = treeWalk.getObjectReader();
|
final ObjectReader r = treeWalk.getObjectReader();
|
||||||
DirCacheEditor editor = dc.editor();
|
DirCacheEditor editor = dc.editor();
|
||||||
while (treeWalk.next()) {
|
while (treeWalk.next()) {
|
||||||
DirCacheEntry entry = dci.getDirCacheEntry();
|
String path = treeWalk.getPathString();
|
||||||
// Only add one edit per path
|
// Only add one edit per path
|
||||||
if (entry != null && entry.getStage() > DirCacheEntry.STAGE_1)
|
if (path.equals(previousPath))
|
||||||
continue;
|
continue;
|
||||||
editor.add(new PathEdit(treeWalk.getPathString()) {
|
|
||||||
|
editor.add(new PathEdit(path) {
|
||||||
public void apply(DirCacheEntry ent) {
|
public void apply(DirCacheEntry ent) {
|
||||||
int stage = ent.getStage();
|
int stage = ent.getStage();
|
||||||
if (stage > DirCacheEntry.STAGE_0) {
|
if (stage > DirCacheEntry.STAGE_0) {
|
||||||
|
@ -429,6 +432,8 @@ public void apply(DirCacheEntry ent) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
previousPath = path;
|
||||||
}
|
}
|
||||||
editor.commit();
|
editor.commit();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue