diff options
author | Dariusz Luksza <dariusz@luksza.org> | 2012-10-03 10:01:54 +0200 |
---|---|---|
committer | Chris Aniszczyk <zx@twitter.com> | 2012-11-19 10:02:25 -0600 |
commit | 8eb4d926371edea2d58dc598e3ebcddacbdc326e (patch) | |
tree | 118fe269590e0aeb55c30e72bf12cfac88f4a8b6 /org.eclipse.jgit.test/tst/org/eclipse | |
parent | 84fb2b59d11418d2fa753d27de11775ddc18adde (diff) | |
download | jgit-8eb4d926371edea2d58dc598e3ebcddacbdc326e.tar.gz jgit-8eb4d926371edea2d58dc598e3ebcddacbdc326e.zip |
Add support for rebase interactive 'edit' command
The 'edit' command allows you to change arbitrary commit
content and the message of any commit in the repository.
Bug: 394577
Change-Id: I43a44782cdb10b29f13784fa75ab37fe5d4da01b
Signed-off-by: Dariusz Luksza <dariusz@luksza.org>
Signed-off-by: Chris Aniszczyk <zx@twitter.com>
Diffstat (limited to 'org.eclipse.jgit.test/tst/org/eclipse')
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RebaseCommandTest.java | 52 |
1 files changed, 52 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 07ce7606b1..ba97e905b3 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 @@ -1581,6 +1581,58 @@ public class RebaseCommandTest extends RepositoryTestCase { assertEquals("rewritten commit message", actualCommitMag); } + @Test + public void testRebaseInteractiveEdit() 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.EDIT; + } + + public String modifyCommitMessage(String commit) { + return ""; // not used + } + }).call(); + assertEquals(Status.STOPPED, res.getStatus()); + RevCommit toBeEditted = git.log().call().iterator().next(); + assertEquals("updated file1 on master", toBeEditted.getFullMessage()); + + // change file and commit with new commit message + writeTrashFile("file1", "edited"); + git.commit().setAll(true).setAmend(true) + .setMessage("edited commit message").call(); + // resume rebase + res = git.rebase().setOperation(Operation.CONTINUE).call(); + + checkFile(new File(db.getWorkTree(), "file1"), "edited"); + assertEquals(Status.OK, res.getStatus()); + Iterator<RevCommit> logIterator = git.log().all().call().iterator(); + logIterator.next(); // skip first commit; + String actualCommitMag = logIterator.next().getShortMessage(); + assertEquals("edited commit message", actualCommitMag); + } + private File getTodoFile() { File todoFile = new File(db.getDirectory(), "rebase-merge/git-rebase-todo"); |