Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Lay2013-11-06 10:16:34 +0000
committerMatthias Sohn2013-11-08 22:43:11 +0000
commit979e3467112618cc787e161097986212eaaa4533 (patch)
treec2a3e489b488f170f7c7995d6a44db0b326886ab /org.eclipse.jgit.test
parent18069ffe8cbede40cf2524922c262b67656e7021 (diff)
downloadjgit-979e3467112618cc787e161097986212eaaa4533.tar.gz
jgit-979e3467112618cc787e161097986212eaaa4533.tar.xz
jgit-979e3467112618cc787e161097986212eaaa4533.zip
Interactive Rebase: Do actions if there were conflicts
If a commit was marked for edit, reword, squash or fixup, but the interactive rebase stopped because of a conflict, the step was not done after conflict resolution. This is done now. Change-Id: If8e7ccc50469165744f2b8a53d180f9ba0f72330 Signed-off-by: Stefan Lay <stefan.lay@sap.com> Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RebaseCommandTest.java207
1 files changed, 207 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 531e1b0e2c..241d099d19 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
@@ -2327,6 +2327,213 @@ public class RebaseCommandTest extends RepositoryTestCase {
}
+ @Test
+ public void testRebaseShouldStopForEditInCaseOfConflict()
+ throws Exception {
+ // create file1 on master
+ writeTrashFile(FILE1, FILE1);
+ git.add().addFilepattern(FILE1).call();
+ git.commit().setMessage("Add file1\nnew line").call();
+ assertTrue(new File(db.getWorkTree(), FILE1).exists());
+
+ //change file1
+ writeTrashFile(FILE1, FILE1 + "a");
+ git.add().addFilepattern(FILE1).call();
+ git.commit().setMessage("Change file1").call();
+
+ //change file1
+ writeTrashFile(FILE1, FILE1 + "b");
+ git.add().addFilepattern(FILE1).call();
+ git.commit().setMessage("Change file1").call();
+
+ RebaseResult result = git.rebase().setUpstream("HEAD~2")
+ .runInteractively(new InteractiveHandler() {
+
+ public void prepareSteps(List<RebaseTodoLine> steps) {
+ steps.remove(0);
+ steps.get(0).setAction(Action.EDIT);
+ }
+
+ public String modifyCommitMessage(String commit) {
+ return commit;
+ }
+ }).call();
+ assertEquals(Status.STOPPED, result.getStatus());
+ git.add().addFilepattern(FILE1).call();
+ result = git.rebase().setOperation(Operation.CONTINUE).call();
+ assertEquals(Status.EDIT, result.getStatus());
+
+ }
+
+ @Test
+ public void testRebaseShouldStopForRewordInCaseOfConflict()
+ throws Exception {
+ // create file1 on master
+ writeTrashFile(FILE1, FILE1);
+ git.add().addFilepattern(FILE1).call();
+ git.commit().setMessage("Add file1\nnew line").call();
+ assertTrue(new File(db.getWorkTree(), FILE1).exists());
+
+ // change file1
+ writeTrashFile(FILE1, FILE1 + "a");
+ git.add().addFilepattern(FILE1).call();
+ git.commit().setMessage("Change file1").call();
+
+ // change file1
+ writeTrashFile(FILE1, FILE1 + "b");
+ git.add().addFilepattern(FILE1).call();
+ git.commit().setMessage("Change file1").call();
+
+ RebaseResult result = git.rebase().setUpstream("HEAD~2")
+ .runInteractively(new InteractiveHandler() {
+
+ public void prepareSteps(List<RebaseTodoLine> steps) {
+ steps.remove(0);
+ steps.get(0).setAction(Action.REWORD);
+ }
+
+ public String modifyCommitMessage(String commit) {
+ return "rewritten commit message";
+ }
+ }).call();
+ assertEquals(Status.STOPPED, result.getStatus());
+ git.add().addFilepattern(FILE1).call();
+ result = git.rebase().runInteractively(new InteractiveHandler() {
+
+ public void prepareSteps(List<RebaseTodoLine> steps) {
+ steps.remove(0);
+ steps.get(0).setAction(Action.REWORD);
+ }
+
+ public String modifyCommitMessage(String commit) {
+ return "rewritten commit message";
+ }
+ }).setOperation(Operation.CONTINUE).call();
+ assertEquals(Status.OK, result.getStatus());
+ Iterator<RevCommit> logIterator = git.log().all().call().iterator();
+ String actualCommitMag = logIterator.next().getShortMessage();
+ assertEquals("rewritten commit message", actualCommitMag);
+
+ }
+
+ @Test
+ public void testRebaseShouldSquashInCaseOfConflict() throws Exception {
+ // create file1 on master
+ writeTrashFile(FILE1, FILE1);
+ git.add().addFilepattern(FILE1).call();
+ git.commit().setMessage("Add file1\nnew line").call();
+ assertTrue(new File(db.getWorkTree(), FILE1).exists());
+
+ // change file2
+ writeTrashFile("file2", "file2");
+ git.add().addFilepattern("file2").call();
+ git.commit().setMessage("Change file2").call();
+
+ // change file1
+ writeTrashFile(FILE1, FILE1 + "a");
+ git.add().addFilepattern(FILE1).call();
+ git.commit().setMessage("Change file1").call();
+
+ // change file1
+ writeTrashFile(FILE1, FILE1 + "b");
+ git.add().addFilepattern(FILE1).call();
+ git.commit().setMessage("Change file1").call();
+
+ RebaseResult result = git.rebase().setUpstream("HEAD~3")
+ .runInteractively(new InteractiveHandler() {
+
+ public void prepareSteps(List<RebaseTodoLine> steps) {
+ steps.get(0).setAction(Action.PICK);
+ steps.remove(1);
+ steps.get(1).setAction(Action.SQUASH);
+ }
+
+ public String modifyCommitMessage(String commit) {
+ return "squashed message";
+ }
+ }).call();
+ assertEquals(Status.STOPPED, result.getStatus());
+ git.add().addFilepattern(FILE1).call();
+ result = git.rebase().runInteractively(new InteractiveHandler() {
+
+ public void prepareSteps(List<RebaseTodoLine> steps) {
+ steps.get(0).setAction(Action.PICK);
+ steps.remove(1);
+ steps.get(1).setAction(Action.SQUASH);
+ }
+
+ public String modifyCommitMessage(String commit) {
+ return "squashed message";
+ }
+ }).setOperation(Operation.CONTINUE).call();
+ assertEquals(Status.OK, result.getStatus());
+ Iterator<RevCommit> logIterator = git.log().all().call().iterator();
+ String actualCommitMag = logIterator.next().getShortMessage();
+ assertEquals("squashed message", actualCommitMag);
+ }
+
+ @Test
+ public void testRebaseShouldFixupInCaseOfConflict() throws Exception {
+ // create file1 on master
+ writeTrashFile(FILE1, FILE1);
+ git.add().addFilepattern(FILE1).call();
+ git.commit().setMessage("Add file1").call();
+ assertTrue(new File(db.getWorkTree(), FILE1).exists());
+
+ // change file2
+ writeTrashFile("file2", "file2");
+ git.add().addFilepattern("file2").call();
+ git.commit().setMessage("Change file2").call();
+
+ // change file1
+ writeTrashFile(FILE1, FILE1 + "a");
+ git.add().addFilepattern(FILE1).call();
+ git.commit().setMessage("Change file1").call();
+
+ // change file1, add file3
+ writeTrashFile(FILE1, FILE1 + "b");
+ writeTrashFile("file3", "file3");
+ git.add().addFilepattern(FILE1).call();
+ git.add().addFilepattern("file3").call();
+ git.commit().setMessage("Change file1, add file3").call();
+
+ RebaseResult result = git.rebase().setUpstream("HEAD~3")
+ .runInteractively(new InteractiveHandler() {
+
+ public void prepareSteps(List<RebaseTodoLine> steps) {
+ steps.get(0).setAction(Action.PICK);
+ steps.remove(1);
+ steps.get(1).setAction(Action.FIXUP);
+ }
+
+ public String modifyCommitMessage(String commit) {
+ return commit;
+ }
+ }).call();
+ assertEquals(Status.STOPPED, result.getStatus());
+ git.add().addFilepattern(FILE1).call();
+ result = git.rebase().runInteractively(new InteractiveHandler() {
+
+ public void prepareSteps(List<RebaseTodoLine> steps) {
+ steps.get(0).setAction(Action.PICK);
+ steps.remove(1);
+ steps.get(1).setAction(Action.FIXUP);
+ }
+
+ public String modifyCommitMessage(String commit) {
+ return "commit";
+ }
+ }).setOperation(Operation.CONTINUE).call();
+ assertEquals(Status.OK, result.getStatus());
+ Iterator<RevCommit> logIterator = git.log().all().call().iterator();
+ String actualCommitMsg = logIterator.next().getShortMessage();
+ assertEquals("Change file2", actualCommitMsg);
+ actualCommitMsg = logIterator.next().getShortMessage();
+ assertEquals("Add file1", actualCommitMsg);
+ assertTrue(new File(db.getWorkTree(), "file3").exists());
+
+ }
+
private File getTodoFile() {
File todoFile = new File(db.getDirectory(), GIT_REBASE_TODO);
return todoFile;

Back to the top