summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test
diff options
context:
space:
mode:
authorMathias Kinzler <mathias.kinzler@sap.com>2011-03-24 03:18:32 -0400
committerCode Review <codereview-daemon@eclipse.org>2011-03-24 03:18:32 -0400
commit55b7bd247ef86c6650c9acc364f426cec38723b5 (patch)
tree2ef61d42754eb60856c653c07cb6082a60b128dd /org.eclipse.jgit.test
parentc160293d71a3d2cf1f4a89868e2bf6c420f50cf0 (diff)
parenta21e508a318664dac23701ca29d5f0b64d36a76a (diff)
downloadjgit-55b7bd247ef86c6650c9acc364f426cec38723b5.tar.gz
jgit-55b7bd247ef86c6650c9acc364f426cec38723b5.zip
Merge "Introduce CherryPickResult"
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CherryPickCommandTest.java73
1 files changed, 73 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 88bd6acfdf..1646c7b481 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
@@ -49,9 +49,12 @@ import java.io.File;
import java.io.IOException;
import java.util.Iterator;
+import org.eclipse.jgit.api.CherryPickResult.CherryPickStatus;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.JGitInternalException;
+import org.eclipse.jgit.lib.RepositoryState;
import org.eclipse.jgit.lib.RepositoryTestCase;
+import org.eclipse.jgit.merge.ResolveMerger.MergeFailureReason;
import org.eclipse.jgit.revwalk.RevCommit;
import org.junit.Test;
@@ -99,4 +102,74 @@ public class CherryPickCommandTest extends RepositoryTestCase {
assertEquals("create a", history.next().getFullMessage());
assertFalse(history.hasNext());
}
+
+ @Test
+ public void testCherryPickDirtyIndex() throws Exception {
+ Git git = new Git(db);
+ RevCommit sideCommit = prepareCherryPick(git);
+
+ // modify and add file a
+ writeTrashFile("a", "a(modified)");
+ git.add().addFilepattern("a").call();
+ // do not commit
+
+ doCherryPickAndCheckResult(git, sideCommit,
+ MergeFailureReason.DIRTY_INDEX);
+ }
+
+ @Test
+ public void testCherryPickDirtyWorktree() throws Exception {
+ Git git = new Git(db);
+ RevCommit sideCommit = prepareCherryPick(git);
+
+ // modify file a
+ writeTrashFile("a", "a(modified)");
+ // do not add and commit
+
+ doCherryPickAndCheckResult(git, sideCommit,
+ MergeFailureReason.DIRTY_WORKTREE);
+ }
+
+ private RevCommit prepareCherryPick(final Git git) throws Exception {
+ // create, add and commit file a
+ writeTrashFile("a", "a");
+ git.add().addFilepattern("a").call();
+ RevCommit firstMasterCommit = git.commit().setMessage("first master")
+ .call();
+
+ // create and checkout side branch
+ createBranch(firstMasterCommit, "refs/heads/side");
+ checkoutBranch("refs/heads/side");
+ // modify, add and commit file a
+ writeTrashFile("a", "a(side)");
+ git.add().addFilepattern("a").call();
+ RevCommit sideCommit = git.commit().setMessage("side").call();
+
+ // checkout master branch
+ checkoutBranch("refs/heads/master");
+ // modify, add and commit file a
+ writeTrashFile("a", "a(master)");
+ git.add().addFilepattern("a").call();
+ git.commit().setMessage("second master").call();
+ return sideCommit;
+ }
+
+ private void doCherryPickAndCheckResult(final Git git,
+ final RevCommit sideCommit, final MergeFailureReason reason)
+ throws Exception {
+ // get current index state
+ String indexState = indexState(CONTENT);
+
+ // cherry-pick
+ CherryPickResult result = git.cherryPick().include(sideCommit.getId())
+ .call();
+ assertEquals(CherryPickStatus.FAILED, result.getStatus());
+ // staged file a causes DIRTY_INDEX
+ assertEquals(1, result.getFailingPaths().size());
+ assertEquals(reason, result.getFailingPaths().get("a"));
+ assertEquals("a(modified)", read(new File(db.getWorkTree(), "a")));
+ // index shall be unchanged
+ assertEquals(indexState, indexState(CONTENT));
+ assertEquals(RepositoryState.SAFE, db.getRepositoryState());
+ }
}