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 40eb49404..c5829ec96 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 @@ -2347,7 +2347,7 @@ public String modifyCommitMessage(String commit) { assertFalse(messageFixupFile.exists()); assertTrue(messageSquashFile.exists()); assertEquals( - "# This is a combination of 2 commits.\n# This is the 2nd commit message:\nupdated file1 on master\nnew line\n# The first commit's message is:\nAdd file2\nnew line", + "# This is a combination of 2 commits.\n# The first commit's message is:\nAdd file2\nnew line\n# This is the 2nd commit message:\nupdated file1 on master\nnew line", commit); try { @@ -2426,7 +2426,7 @@ public String modifyCommitMessage(String commit) { assertFalse(messageFixupFile.exists()); assertTrue(messageSquashFile.exists()); assertEquals( - "# This is a combination of 3 commits.\n# This is the 3rd commit message:\nupdated file1 on master\nnew line\n# This is the 2nd commit message:\nAdd file2\nnew line\n# The first commit's message is:\nAdd file1\nnew line", + "# This is a combination of 3 commits.\n# The first commit's message is:\nAdd file1\nnew line\n# This is the 2nd commit message:\nAdd file2\nnew line\n# This is the 3rd commit message:\nupdated file1 on master\nnew line", commit); try { @@ -2441,7 +2441,7 @@ public String modifyCommitMessage(String commit) { fail(t.getMessage()); } - return "# This is a combination of 3 commits.\n# This is the 3rd commit message:\nupdated file1 on master\nnew line\n# This is the 2nd commit message:\nAdd file2\nnew line\n# The first commit's message is:\nAdd file1\nnew line"; + return "# This is a combination of 3 commits.\n# The first commit's message is:\nAdd file1\nnew line\n# This is the 2nd commit message:\nAdd file2\nnew line\n# This is the 3rd commit message:\nupdated file1 on master\nnew line"; } }).call(); @@ -2454,7 +2454,7 @@ public String modifyCommitMessage(String commit) { ObjectId head2Id = db.resolve(Constants.HEAD + "^1"); RevCommit head1Commit = walk.parseCommit(head2Id); assertEquals( - "updated file1 on master\nnew line\nAdd file2\nnew line\nAdd file1\nnew line", + "Add file1\nnew line\nAdd file2\nnew line\nupdated file1 on master\nnew line", head1Commit.getFullMessage()); } @@ -2508,7 +2508,7 @@ public String modifyCommitMessage(String commit) { assertFalse(messageFixupFile.exists()); assertTrue(messageSquashFile.exists()); assertEquals( - "# This is a combination of 3 commits.\n# This is the 3rd commit message:\nupdated file1 on master\nnew line\n# The 2nd commit message will be skipped:\n# Add file2\n# new line\n# The first commit's message is:\nAdd file1\nnew line", + "# This is a combination of 3 commits.\n# The first commit's message is:\nAdd file1\nnew line\n# The 2nd commit message will be skipped:\n# Add file2\n# new line\n# This is the 3rd commit message:\nupdated file1 on master\nnew line", commit); try { diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java index 330902c84..3b8491742 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java @@ -621,6 +621,9 @@ private static String composeSquashMessage(boolean isSquash, sb.setLength(0); sb.append("# This is a combination of ").append(count) .append(" commits.\n"); + // Add the previous message without header (i.e first line) + sb.append(currSquashMessage.substring(currSquashMessage.indexOf("\n") + 1)); + sb.append("\n"); if (isSquash) { sb.append("# This is the ").append(count).append(ordinal) .append(" commit message:\n"); @@ -631,9 +634,6 @@ private static String composeSquashMessage(boolean isSquash, sb.append(commitToPick.getFullMessage().replaceAll("([\n\r])", "$1# ")); } - // Add the previous message without header (i.e first line) - sb.append("\n"); - sb.append(currSquashMessage.substring(currSquashMessage.indexOf("\n") + 1)); return sb.toString(); }