|
|
|
@ -76,6 +76,18 @@ public class CherryPickCommandTest extends RepositoryTestCase {
|
|
|
|
|
@Test |
|
|
|
|
public void testCherryPick() throws IOException, JGitInternalException, |
|
|
|
|
GitAPIException { |
|
|
|
|
doTestCherryPick(false); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testCherryPickNoCommit() throws IOException, |
|
|
|
|
JGitInternalException, GitAPIException { |
|
|
|
|
doTestCherryPick(true); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void doTestCherryPick(boolean noCommit) throws IOException, |
|
|
|
|
JGitInternalException, |
|
|
|
|
GitAPIException { |
|
|
|
|
Git git = new Git(db); |
|
|
|
|
|
|
|
|
|
writeTrashFile("a", "first line\nsec. line\nthird line\n"); |
|
|
|
@ -102,13 +114,16 @@ public class CherryPickCommandTest extends RepositoryTestCase {
|
|
|
|
|
git.add().addFilepattern("a").call(); |
|
|
|
|
git.commit().setMessage("enhanced a").call(); |
|
|
|
|
|
|
|
|
|
git.cherryPick().include(fixingA).call(); |
|
|
|
|
CherryPickResult pickResult = git.cherryPick().include(fixingA) |
|
|
|
|
.setNoCommit(noCommit).call(); |
|
|
|
|
|
|
|
|
|
assertEquals(CherryPickStatus.OK, pickResult.getStatus()); |
|
|
|
|
assertFalse(new File(db.getWorkTree(), "b").exists()); |
|
|
|
|
checkFile(new File(db.getWorkTree(), "a"), |
|
|
|
|
"first line\nsecond line\nthird line\nfeature++\n"); |
|
|
|
|
Iterator<RevCommit> history = git.log().call().iterator(); |
|
|
|
|
assertEquals("fixed a", history.next().getFullMessage()); |
|
|
|
|
if (!noCommit) |
|
|
|
|
assertEquals("fixed a", history.next().getFullMessage()); |
|
|
|
|
assertEquals("enhanced a", history.next().getFullMessage()); |
|
|
|
|
assertEquals("create a", history.next().getFullMessage()); |
|
|
|
|
assertFalse(history.hasNext()); |
|
|
|
@ -205,6 +220,35 @@ public class CherryPickCommandTest extends RepositoryTestCase {
|
|
|
|
|
assertEquals(RepositoryState.SAFE, db.getRepositoryState()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testCherryPickConflictResolutionNoCOmmit() throws Exception { |
|
|
|
|
Git git = new Git(db); |
|
|
|
|
RevCommit sideCommit = prepareCherryPick(git); |
|
|
|
|
|
|
|
|
|
CherryPickResult result = git.cherryPick().include(sideCommit.getId()) |
|
|
|
|
.setNoCommit(true).call(); |
|
|
|
|
|
|
|
|
|
assertEquals(CherryPickStatus.CONFLICTING, result.getStatus()); |
|
|
|
|
assertTrue(db.readDirCache().hasUnmergedPaths()); |
|
|
|
|
String expected = "<<<<<<< master\na(master)\n=======\na(side)\n>>>>>>> 527460a side\n"; |
|
|
|
|
assertEquals(expected, read("a")); |
|
|
|
|
assertTrue(new File(db.getDirectory(), Constants.MERGE_MSG).exists()); |
|
|
|
|
assertEquals("side\n\nConflicts:\n\ta\n", db.readMergeCommitMsg()); |
|
|
|
|
assertFalse(new File(db.getDirectory(), Constants.CHERRY_PICK_HEAD) |
|
|
|
|
.exists()); |
|
|
|
|
assertEquals(RepositoryState.SAFE, db.getRepositoryState()); |
|
|
|
|
|
|
|
|
|
// Resolve
|
|
|
|
|
writeTrashFile("a", "a"); |
|
|
|
|
git.add().addFilepattern("a").call(); |
|
|
|
|
|
|
|
|
|
assertEquals(RepositoryState.SAFE, db.getRepositoryState()); |
|
|
|
|
|
|
|
|
|
git.commit().setOnly("a").setMessage("resolve").call(); |
|
|
|
|
|
|
|
|
|
assertEquals(RepositoryState.SAFE, db.getRepositoryState()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testCherryPickConflictReset() throws Exception { |
|
|
|
|
Git git = new Git(db); |
|
|
|
|