]> source.dussan.org Git - jgit.git/commitdiff
Fix FIXUP error for blank lines in interactive rebase 66/18666/3
authorStefan Lay <stefan.lay@sap.com>
Thu, 21 Nov 2013 13:00:30 +0000 (14:00 +0100)
committerGerrit Code Review @ Eclipse.org <gerrit@eclipse.org>
Fri, 22 Nov 2013 21:50:44 +0000 (16:50 -0500)
Empty lines of discarded commit messages were added to the commit
message because they were not commented out properly.

Bug: 422246
Change-Id: I263e8a6b30a3392d8b4f09c0695505068a0a485d
Signed-off-by: Stefan Lay <stefan.lay@sap.com>
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RebaseCommandTest.java
org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java

index a3d652b73785d5cf04b8a3bb4c7eddc04fe0ca60..2c9fce8186a8dbed38aef92ec72e93256dec0e6f 100644 (file)
@@ -2250,6 +2250,44 @@ public class RebaseCommandTest extends RepositoryTestCase {
                                head1Commit.getFullMessage());
        }
 
+       @Test
+       public void testRebaseInteractiveFixupWithBlankLines() 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());
+
+               // 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\n\nsome text").call();
+
+               git.rebase().setUpstream("HEAD~2")
+                               .runInteractively(new InteractiveHandler() {
+
+                                       public void prepareSteps(List<RebaseTodoLine> steps) {
+                                               steps.get(1).setAction(Action.FIXUP);
+                                       }
+
+                                       public String modifyCommitMessage(String commit) {
+                                               fail("No callback to modify commit message expected for single fixup");
+                                               return commit;
+                                       }
+                               }).call();
+
+               RevWalk walk = new RevWalk(db);
+               ObjectId headId = db.resolve(Constants.HEAD);
+               RevCommit headCommit = walk.parseCommit(headId);
+               assertEquals("Add file2",
+                               headCommit.getFullMessage());
+       }
 
        @Test(expected = InvalidRebaseStepException.class)
        public void testRebaseInteractiveFixupFirstCommitShouldFail()
index 8ae51d74ce62db64939bcd51068daeebd82cc8c4..d077cff15649afb00c27f851e2a2e9ec4e991392 100644 (file)
@@ -550,7 +550,7 @@ public class RebaseCommand extends GitCommand<RebaseResult> {
                } else {
                        sb.append("# The ").append(count).append(ordinal)
                                        .append(" commit message will be skipped:\n# ");
-                       sb.append(commitToPick.getFullMessage().replaceAll("([\n\r]+)",
+                       sb.append(commitToPick.getFullMessage().replaceAll("([\n\r])",
                                        "$1# "));
                }
                // Add the previous message without header (i.e first line)