diff options
author | Philipp Thun <philipp.thun@sap.com> | 2011-03-24 12:24:23 +0100 |
---|---|---|
committer | Philipp Thun <philipp.thun@sap.com> | 2011-03-24 12:24:23 +0100 |
commit | 0b5ad24915824a8c999bb6951b131a958e418306 (patch) | |
tree | 95efbadc7ecabf133767ccdde3c8699773be6048 /org.eclipse.jgit.test/tst | |
parent | 55b7bd247ef86c6650c9acc364f426cec38723b5 (diff) | |
download | jgit-0b5ad24915824a8c999bb6951b131a958e418306.tar.gz jgit-0b5ad24915824a8c999bb6951b131a958e418306.zip |
Introduce FAILED result for RebaseCommand
In case an underlying cherry-pick fails due to uncommitted changes, a
RebaseCommand shall fail and roll-back changes.
Change-Id: Ic22eb047fb03ac2c8391f777036b7dbf22a1b061
Signed-off-by: Philipp Thun <philipp.thun@sap.com>
Diffstat (limited to 'org.eclipse.jgit.test/tst')
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RebaseCommandTest.java | 340 |
1 files changed, 340 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RebaseCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RebaseCommandTest.java index 8486b70a77..2b7d0e5caf 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RebaseCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RebaseCommandTest.java @@ -57,6 +57,7 @@ import java.io.InputStreamReader; import org.eclipse.jgit.api.RebaseCommand.Action; import org.eclipse.jgit.api.RebaseCommand.Operation; import org.eclipse.jgit.api.RebaseResult.Status; +import org.eclipse.jgit.api.errors.JGitInternalException; import org.eclipse.jgit.api.errors.RefNotFoundException; import org.eclipse.jgit.api.errors.UnmergedPathsException; import org.eclipse.jgit.api.errors.WrongRepositoryStateException; @@ -67,6 +68,7 @@ import org.eclipse.jgit.lib.PersonIdent; import org.eclipse.jgit.lib.RefUpdate; 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.eclipse.jgit.revwalk.RevWalk; import org.junit.Before; @@ -878,6 +880,344 @@ public class RebaseCommandTest extends RepositoryTestCase { } } + @Test + public void testRebaseWithUntrackedFile() throws Exception { + // create file1, add and commit + writeTrashFile(FILE1, "file1"); + git.add().addFilepattern(FILE1).call(); + RevCommit commit = git.commit().setMessage("commit1").call(); + + // create topic branch and checkout / create file2, add and commit + createBranch(commit, "refs/heads/topic"); + checkoutBranch("refs/heads/topic"); + writeTrashFile("file2", "file2"); + git.add().addFilepattern("file2").call(); + git.commit().setMessage("commit2").call(); + + // checkout master branch / modify file1, add and commit + checkoutBranch("refs/heads/master"); + writeTrashFile(FILE1, "modified file1"); + git.add().addFilepattern(FILE1).call(); + git.commit().setMessage("commit3").call(); + + // checkout topic branch / create untracked file3 + checkoutBranch("refs/heads/topic"); + writeTrashFile("file3", "untracked file3"); + + // rebase + assertEquals(Status.OK, git.rebase().setUpstream("refs/heads/master") + .call().getStatus()); + } + + @Test + @SuppressWarnings("null") + public void testRebaseWithUnstagedTopicChange() throws Exception { + // create file1, add and commit + writeTrashFile(FILE1, "file1"); + git.add().addFilepattern(FILE1).call(); + RevCommit commit = git.commit().setMessage("commit1").call(); + + // create topic branch and checkout / create file2, add and commit + createBranch(commit, "refs/heads/topic"); + checkoutBranch("refs/heads/topic"); + writeTrashFile("file2", "file2"); + git.add().addFilepattern("file2").call(); + git.commit().setMessage("commit2").call(); + + // checkout master branch / modify file1, add and commit + checkoutBranch("refs/heads/master"); + writeTrashFile(FILE1, "modified file1"); + git.add().addFilepattern(FILE1).call(); + git.commit().setMessage("commit3").call(); + + // checkout topic branch / modify file2 + checkoutBranch("refs/heads/topic"); + writeTrashFile("file2", "unstaged file2"); + + // rebase + JGitInternalException exception = null; + try { + git.rebase().setUpstream("refs/heads/master").call(); + } catch (JGitInternalException e) { + exception = e; + } + assertNotNull(exception); + assertEquals("Checkout conflict with files: \nfile2", + exception.getMessage()); + } + + @Test + @SuppressWarnings("null") + public void testRebaseWithUncommittedTopicChange() throws Exception { + // create file1, add and commit + writeTrashFile(FILE1, "file1"); + git.add().addFilepattern(FILE1).call(); + RevCommit commit = git.commit().setMessage("commit1").call(); + + // create topic branch and checkout / create file2, add and commit + createBranch(commit, "refs/heads/topic"); + checkoutBranch("refs/heads/topic"); + writeTrashFile("file2", "file2"); + git.add().addFilepattern("file2").call(); + git.commit().setMessage("commit2").call(); + + // checkout master branch / modify file1, add and commit + checkoutBranch("refs/heads/master"); + writeTrashFile(FILE1, "modified file1"); + git.add().addFilepattern(FILE1).call(); + git.commit().setMessage("commit3").call(); + + // checkout topic branch / modify file2 and add + checkoutBranch("refs/heads/topic"); + writeTrashFile("file2", "uncommitted file2"); + git.add().addFilepattern("file2").call(); + // do not commit + + // rebase + JGitInternalException exception = null; + try { + git.rebase().setUpstream("refs/heads/master").call(); + } catch (JGitInternalException e) { + exception = e; + } + assertNotNull(exception); + assertEquals("Checkout conflict with files: \nfile2", + exception.getMessage()); + } + + @Test + @SuppressWarnings("null") + public void testRebaseWithUnstagedMasterChange() throws Exception { + // create file1, add and commit + writeTrashFile(FILE1, "file1"); + git.add().addFilepattern(FILE1).call(); + RevCommit commit = git.commit().setMessage("commit1").call(); + + // create topic branch and checkout / create file2, add and commit + createBranch(commit, "refs/heads/topic"); + checkoutBranch("refs/heads/topic"); + writeTrashFile("file2", "file2"); + git.add().addFilepattern("file2").call(); + git.commit().setMessage("commit2").call(); + + // checkout master branch / modify file1, add and commit + checkoutBranch("refs/heads/master"); + writeTrashFile(FILE1, "modified file1"); + git.add().addFilepattern(FILE1).call(); + git.commit().setMessage("commit3").call(); + + // checkout topic branch / modify file1 + checkoutBranch("refs/heads/topic"); + writeTrashFile(FILE1, "unstaged modified file1"); + + // rebase + JGitInternalException exception = null; + try { + git.rebase().setUpstream("refs/heads/master").call(); + } catch (JGitInternalException e) { + exception = e; + } + assertNotNull(exception); + assertEquals("Checkout conflict with files: \nfile1", + exception.getMessage()); + } + + @Test + @SuppressWarnings("null") + public void testRebaseWithUncommittedMasterChange() throws Exception { + // create file1, add and commit + writeTrashFile(FILE1, "file1"); + git.add().addFilepattern(FILE1).call(); + RevCommit commit = git.commit().setMessage("commit1").call(); + + // create topic branch and checkout / create file2, add and commit + createBranch(commit, "refs/heads/topic"); + checkoutBranch("refs/heads/topic"); + writeTrashFile("file2", "file2"); + git.add().addFilepattern("file2").call(); + git.commit().setMessage("commit2").call(); + + // checkout master branch / modify file1, add and commit + checkoutBranch("refs/heads/master"); + writeTrashFile(FILE1, "modified file1"); + git.add().addFilepattern(FILE1).call(); + git.commit().setMessage("commit3").call(); + + // checkout topic branch / modify file1 and add + checkoutBranch("refs/heads/topic"); + writeTrashFile(FILE1, "uncommitted modified file1"); + git.add().addFilepattern(FILE1).call(); + // do not commit + + // rebase + JGitInternalException exception = null; + try { + git.rebase().setUpstream("refs/heads/master").call(); + } catch (JGitInternalException e) { + exception = e; + } + assertNotNull(exception); + assertEquals("Checkout conflict with files: \nfile1", + exception.getMessage()); + } + + @Test + public void testRebaseWithUnstagedMasterChangeBaseCommit() throws Exception { + // create file0 + file1, add and commit + writeTrashFile("file0", "file0"); + writeTrashFile(FILE1, "file1"); + git.add().addFilepattern("file0").addFilepattern(FILE1).call(); + RevCommit commit = git.commit().setMessage("commit1").call(); + + // create topic branch and checkout / create file2, add and commit + createBranch(commit, "refs/heads/topic"); + checkoutBranch("refs/heads/topic"); + writeTrashFile("file2", "file2"); + git.add().addFilepattern("file2").call(); + git.commit().setMessage("commit2").call(); + + // checkout master branch / modify file1, add and commit + checkoutBranch("refs/heads/master"); + writeTrashFile(FILE1, "modified file1"); + git.add().addFilepattern(FILE1).call(); + git.commit().setMessage("commit3").call(); + + // checkout topic branch / modify file0 + checkoutBranch("refs/heads/topic"); + writeTrashFile("file0", "unstaged modified file0"); + + // rebase + assertEquals(Status.OK, git.rebase().setUpstream("refs/heads/master") + .call().getStatus()); + } + + @Test + public void testRebaseWithUncommittedMasterChangeBaseCommit() + throws Exception { + // create file0 + file1, add and commit + File file0 = writeTrashFile("file0", "file0"); + writeTrashFile(FILE1, "file1"); + git.add().addFilepattern("file0").addFilepattern(FILE1).call(); + RevCommit commit = git.commit().setMessage("commit1").call(); + + // create topic branch and checkout / create file2, add and commit + createBranch(commit, "refs/heads/topic"); + checkoutBranch("refs/heads/topic"); + writeTrashFile("file2", "file2"); + git.add().addFilepattern("file2").call(); + git.commit().setMessage("commit2").call(); + + // checkout master branch / modify file1, add and commit + checkoutBranch("refs/heads/master"); + writeTrashFile(FILE1, "modified file1"); + git.add().addFilepattern(FILE1).call(); + git.commit().setMessage("commit3").call(); + + // checkout topic branch / modify file0 and add + checkoutBranch("refs/heads/topic"); + write(file0, "unstaged modified file0"); + git.add().addFilepattern("file0").call(); + // do not commit + + // get current index state + String indexState = indexState(CONTENT); + + // rebase + RebaseResult result = git.rebase().setUpstream("refs/heads/master") + .call(); + assertEquals(Status.FAILED, result.getStatus()); + // staged file0 causes DIRTY_INDEX + assertEquals(1, result.getFailingPaths().size()); + assertEquals(MergeFailureReason.DIRTY_INDEX, result.getFailingPaths() + .get("file0")); + assertEquals("unstaged modified file0", read(file0)); + // index shall be unchanged + assertEquals(indexState, indexState(CONTENT)); + assertEquals(RepositoryState.SAFE, db.getRepositoryState()); + } + + @Test + public void testRebaseWithUnstagedMasterChangeOtherCommit() + throws Exception { + // create file0, add and commit + writeTrashFile("file0", "file0"); + git.add().addFilepattern("file0").call(); + git.commit().setMessage("commit0").call(); + // create file1, add and commit + writeTrashFile(FILE1, "file1"); + git.add().addFilepattern(FILE1).call(); + RevCommit commit = git.commit().setMessage("commit1").call(); + + // create topic branch and checkout / create file2, add and commit + createBranch(commit, "refs/heads/topic"); + checkoutBranch("refs/heads/topic"); + writeTrashFile("file2", "file2"); + git.add().addFilepattern("file2").call(); + git.commit().setMessage("commit2").call(); + + // checkout master branch / modify file1, add and commit + checkoutBranch("refs/heads/master"); + writeTrashFile(FILE1, "modified file1"); + git.add().addFilepattern(FILE1).call(); + git.commit().setMessage("commit3").call(); + + // checkout topic branch / modify file0 + checkoutBranch("refs/heads/topic"); + writeTrashFile("file0", "unstaged modified file0"); + + // rebase + assertEquals(Status.OK, git.rebase().setUpstream("refs/heads/master") + .call().getStatus()); + } + + @Test + public void testRebaseWithUncommittedMasterChangeOtherCommit() + throws Exception { + // create file0, add and commit + File file0 = writeTrashFile("file0", "file0"); + git.add().addFilepattern("file0").call(); + git.commit().setMessage("commit0").call(); + // create file1, add and commit + writeTrashFile(FILE1, "file1"); + git.add().addFilepattern(FILE1).call(); + RevCommit commit = git.commit().setMessage("commit1").call(); + + // create topic branch and checkout / create file2, add and commit + createBranch(commit, "refs/heads/topic"); + checkoutBranch("refs/heads/topic"); + writeTrashFile("file2", "file2"); + git.add().addFilepattern("file2").call(); + git.commit().setMessage("commit2").call(); + + // checkout master branch / modify file1, add and commit + checkoutBranch("refs/heads/master"); + writeTrashFile(FILE1, "modified file1"); + git.add().addFilepattern(FILE1).call(); + git.commit().setMessage("commit3").call(); + + // checkout topic branch / modify file0 and add + checkoutBranch("refs/heads/topic"); + write(file0, "unstaged modified file0"); + git.add().addFilepattern("file0").call(); + // do not commit + + // get current index state + String indexState = indexState(CONTENT); + + // rebase + RebaseResult result = git.rebase().setUpstream("refs/heads/master") + .call(); + assertEquals(Status.FAILED, result.getStatus()); + // staged file0 causes DIRTY_INDEX + assertEquals(1, result.getFailingPaths().size()); + assertEquals(MergeFailureReason.DIRTY_INDEX, result.getFailingPaths() + .get("file0")); + assertEquals("unstaged modified file0", read(file0)); + // index shall be unchanged + assertEquals(indexState, indexState(CONTENT)); + assertEquals(RepositoryState.SAFE, db.getRepositoryState()); + } + private int countPicks() throws IOException { int count = 0; File todoFile = new File(db.getDirectory(), |