summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test
diff options
context:
space:
mode:
authorDariusz Luksza <dariusz@luksza.org>2012-10-03 09:59:30 +0200
committerChris Aniszczyk <zx@twitter.com>2012-11-19 09:40:53 -0600
commit84fb2b59d11418d2fa753d27de11775ddc18adde (patch)
treefc381912e29979174a08d4f40a3cd3c5abc1fb82 /org.eclipse.jgit.test
parent9051af3c4d870e255428b814b6b31cf7506f6ac0 (diff)
downloadjgit-84fb2b59d11418d2fa753d27de11775ddc18adde.tar.gz
jgit-84fb2b59d11418d2fa753d27de11775ddc18adde.zip
Add support for rebase interactive 'reword' command
'reword' command is used to change commit message of any commit in git history. Bug: 394575 Change-Id: Ic974e76dfd923fd6f0cb8f07d1a6fbecd9abbf31 Signed-off-by: Dariusz Luksza <dariusz@luksza.org> Signed-off-by: Chris Aniszczyk <zx@twitter.com>
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RebaseCommandTest.java58
1 files changed, 58 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 81730b93aa..07ce7606b1 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
@@ -53,10 +53,12 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
+import java.util.Iterator;
import java.util.List;
import org.eclipse.jgit.api.MergeResult.MergeStatus;
import org.eclipse.jgit.api.RebaseCommand.Action;
+import org.eclipse.jgit.api.RebaseCommand.InteractiveHandler;
import org.eclipse.jgit.api.RebaseCommand.Operation;
import org.eclipse.jgit.api.RebaseCommand.Step;
import org.eclipse.jgit.api.RebaseResult.Status;
@@ -1523,6 +1525,62 @@ public class RebaseCommandTest extends RepositoryTestCase {
assertEquals("2222222", steps.get(1).commit.name());
}
+ @Test
+ public void testParseRewordCommand() throws Exception {
+ String todo = "pick 1111111 Commit 1\n"
+ + "reword 2222222 Commit 2\n";
+ write(getTodoFile(), todo);
+
+ RebaseCommand rebaseCommand = git.rebase();
+ List<Step> steps = rebaseCommand.loadSteps();
+
+ assertEquals(2, steps.size());
+ assertEquals("1111111", steps.get(0).commit.name());
+ assertEquals("2222222", steps.get(1).commit.name());
+ assertEquals(Action.REWORD, steps.get(1).action);
+ }
+
+ @Test
+ public void testRebaseInteractiveReword() 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());
+
+ // create file2 on master
+ writeTrashFile("file2", "file2");
+ git.add().addFilepattern("file2").call();
+ git.commit().setMessage("Add file2").call();
+ assertTrue(new File(db.getWorkTree(), "file2").exists());
+
+ // update FILE1 on master
+ writeTrashFile(FILE1, "blah");
+ git.add().addFilepattern(FILE1).call();
+ git.commit().setMessage("updated file1 on master").call();
+
+ writeTrashFile("file2", "more change");
+ git.add().addFilepattern("file2").call();
+ git.commit().setMessage("update file2 on side").call();
+
+ RebaseResult res = git.rebase().setUpstream("HEAD~2")
+ .runInteractively(new InteractiveHandler() {
+ public void prepareSteps(List<Step> steps) {
+ steps.get(0).action = Action.REWORD;
+ }
+ public String modifyCommitMessage(String commit) {
+ return "rewritten commit message";
+ }
+ }).call();
+ assertTrue(new File(db.getWorkTree(), "file2").exists());
+ checkFile(new File(db.getWorkTree(), "file2"), "more change");
+ assertEquals(Status.OK, res.getStatus());
+ Iterator<RevCommit> logIterator = git.log().all().call().iterator();
+ logIterator.next(); // skip first commit;
+ String actualCommitMag = logIterator.next().getShortMessage();
+ assertEquals("rewritten commit message", actualCommitMag);
+ }
+
private File getTodoFile() {
File todoFile = new File(db.getDirectory(),
"rebase-merge/git-rebase-todo");