diff options
author | Thomas Wolf <thomas.wolf@paranor.ch> | 2022-01-18 00:37:33 +0100 |
---|---|---|
committer | Matthias Sohn <matthias.sohn@sap.com> | 2022-02-02 14:40:58 +0100 |
commit | 035d24097dacc88c54be6349234feeda7447c372 (patch) | |
tree | 76261860d9fbf6caeb16730f5d1c4f81e950c096 /org.eclipse.jgit.test/tst | |
parent | 92158af52e3c438ecfef3cf3fab2126b1f77cd75 (diff) | |
download | jgit-035d24097dacc88c54be6349234feeda7447c372.tar.gz jgit-035d24097dacc88c54be6349234feeda7447c372.zip |
RebaseCommand: fix commit message in "fixup" case
JGit accumulated in MESSAGE_FIXUP commit messages of a fixup sequence,
just like it did in MESSAGE_SQUASH, and on the last step of a sequence
of fixups used that file, after stripping all comment lines, as the
commit message. That also stripped any lines from the original commit
message that happened to start with the comment character.
This is not how this is supposed to work. MESSAGE_FIXUP must contain
the original commit message of the base commit that is amended, and
the file contains the verbatim commit message for the final fixup.[1]
Change the implementation accordingly, and add new tests.
[1] https://github.com/git/git/blob/df3c41adeb/sequencer.c#L86 ff.
Bug: 513726
Change-Id: I885a2b7f10d6c74460a8693aa6cbf867ee0494a1
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
Diffstat (limited to 'org.eclipse.jgit.test/tst')
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RebaseCommandTest.java | 34 |
1 files changed, 28 insertions, 6 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 86239023dc..c64ff0b1c3 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 @@ -2927,8 +2927,8 @@ public class RebaseCommandTest extends RepositoryTestCase { } } - @Test - public void testRebaseInteractiveFixupWithBlankLines() throws Exception { + private void simpleFixup(String firstMessage, String secondMessage) + throws Exception { // create file1 on master writeTrashFile(FILE1, FILE1); git.add().addFilepattern(FILE1).call(); @@ -2938,13 +2938,13 @@ public class RebaseCommandTest extends RepositoryTestCase { // create file2 on master writeTrashFile("file2", "file2"); git.add().addFilepattern("file2").call(); - git.commit().setMessage("Add file2").call(); + git.commit().setMessage(firstMessage).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.commit().setMessage(secondMessage).call(); git.rebase().setUpstream("HEAD~2") .runInteractively(new InteractiveHandler() { @@ -2968,9 +2968,31 @@ public class RebaseCommandTest extends RepositoryTestCase { try (RevWalk walk = new RevWalk(db)) { ObjectId headId = db.resolve(Constants.HEAD); RevCommit headCommit = walk.parseCommit(headId); - assertEquals("Add file2", - headCommit.getFullMessage()); + assertEquals(firstMessage, headCommit.getFullMessage()); } + + } + + @Test + public void testRebaseInteractiveFixupWithBlankLines() throws Exception { + simpleFixup("Add file2", "updated file1 on master\n\nsome text"); + } + + @Test + public void testRebaseInteractiveFixupWithBlankLines2() throws Exception { + simpleFixup("Add file2\n\nBody\n", + "updated file1 on master\n\nsome text"); + } + + @Test + public void testRebaseInteractiveFixupWithHash() throws Exception { + simpleFixup("#Add file2", "updated file1 on master"); + } + + @Test + public void testRebaseInteractiveFixupWithHash2() throws Exception { + simpleFixup("#Add file2\n\nHeader has hash\n", + "#updated file1 on master"); } @Test(expected = InvalidRebaseStepException.class) |