diff options
author | Robin Stocker <robin@nibor.org> | 2011-04-03 19:37:55 +0200 |
---|---|---|
committer | Chris Aniszczyk <caniszczyk@gmail.com> | 2011-04-06 13:28:10 -0500 |
commit | 6e10aa42e90a25b82f00f0c27574f57ffa9e4a25 (patch) | |
tree | e2bf294858e9a16220df5ab54508d94267c14109 /org.eclipse.jgit.test | |
parent | fbf35fea4ec254339f9b0eee7865eb6ccfe22700 (diff) | |
download | jgit-6e10aa42e90a25b82f00f0c27574f57ffa9e4a25.tar.gz jgit-6e10aa42e90a25b82f00f0c27574f57ffa9e4a25.zip |
Add CHERRY_PICK_HEAD for cherry-pick conflicts
Add handling of CHERRY_PICK_HEAD file in .git (similar to MERGE_HEAD),
which is written in case of a conflicting cherry-pick merge.
It is used so that Repository.getRepositoryState can return the new
states CHERRY_PICKING and CHERRY_PICKING_RESOLVED. These states, as well
as CHERRY_PICK_HEAD can be used in EGit to properly show the merge tool.
Also, in case of a conflict, MERGE_MSG is written with the original
commit message and a "Conflicts" section appended. This way, the
cherry-picked message is not lost and can later be re-used in the commit
dialog.
Bug: 339092
Change-Id: I947967fdc2f1d55016c95106b104c2afcc9797a1
Signed-off-by: Robin Stocker <robin@nibor.org>
Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CherryPickCommandTest.java | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CherryPickCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CherryPickCommandTest.java index 1646c7b481..94af81e812 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CherryPickCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CherryPickCommandTest.java @@ -44,14 +44,17 @@ package org.eclipse.jgit.api; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; import java.io.File; import java.io.IOException; import java.util.Iterator; import org.eclipse.jgit.api.CherryPickResult.CherryPickStatus; +import org.eclipse.jgit.api.ResetCommand.ResetType; import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.api.errors.JGitInternalException; +import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.RepositoryState; import org.eclipse.jgit.lib.RepositoryTestCase; import org.eclipse.jgit.merge.ResolveMerger.MergeFailureReason; @@ -130,6 +133,55 @@ public class CherryPickCommandTest extends RepositoryTestCase { MergeFailureReason.DIRTY_WORKTREE); } + @Test + public void testCherryPickConflictResolution() throws Exception { + Git git = new Git(db); + RevCommit sideCommit = prepareCherryPick(git); + + CherryPickResult result = git.cherryPick().include(sideCommit.getId()) + .call(); + + assertEquals(CherryPickStatus.CONFLICTING, result.getStatus()); + assertTrue(new File(db.getDirectory(), Constants.MERGE_MSG).exists()); + assertEquals("side\n\nConflicts:\n\ta\n", db.readMergeCommitMsg()); + assertTrue(new File(db.getDirectory(), Constants.CHERRY_PICK_HEAD) + .exists()); + assertEquals(sideCommit.getId(), db.readCherryPickHead()); + assertEquals(RepositoryState.CHERRY_PICKING, db.getRepositoryState()); + + // Resolve + writeTrashFile("a", "a"); + git.add().addFilepattern("a").call(); + + assertEquals(RepositoryState.CHERRY_PICKING_RESOLVED, + 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); + + RevCommit sideCommit = prepareCherryPick(git); + + CherryPickResult result = git.cherryPick().include(sideCommit.getId()) + .call(); + + assertEquals(CherryPickStatus.CONFLICTING, result.getStatus()); + assertEquals(RepositoryState.CHERRY_PICKING, db.getRepositoryState()); + assertTrue(new File(db.getDirectory(), Constants.CHERRY_PICK_HEAD) + .exists()); + + git.reset().setMode(ResetType.MIXED).setRef("HEAD").call(); + + assertEquals(RepositoryState.SAFE, db.getRepositoryState()); + assertFalse(new File(db.getDirectory(), Constants.CHERRY_PICK_HEAD) + .exists()); + } + private RevCommit prepareCherryPick(final Git git) throws Exception { // create, add and commit file a writeTrashFile("a", "a"); |