diff options
author | Thomas Wolf <thomas.wolf@paranor.ch> | 2018-04-06 23:58:34 +0200 |
---|---|---|
committer | Matthias Sohn <matthias.sohn@sap.com> | 2018-04-18 23:33:37 +0200 |
commit | 42e69409d796421bb1353279cfae463b19a43fe9 (patch) | |
tree | de508687a383408f897e7f5c6c24b488def53b6f /org.eclipse.jgit.test | |
parent | cbb2e65dbcf4c4cf9751184f07d5bc4e58bf17e5 (diff) | |
download | jgit-42e69409d796421bb1353279cfae463b19a43fe9.tar.gz jgit-42e69409d796421bb1353279cfae463b19a43fe9.zip |
Handle Gerrit Change-Ids for merge commits
Otherwise successful, non-conflicting merges will never get a
Gerrit Change-Id.
Bug: 358206
Change-Id: I9b599ad01d9f7332200c1d81a1ba6ce5ef990ab5
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/api/MergeCommandTest.java | 72 |
1 files changed, 57 insertions, 15 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/MergeCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/MergeCommandTest.java index 4b23349fa6..6f7df4bd84 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/MergeCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/MergeCommandTest.java @@ -54,6 +54,7 @@ import static org.junit.Assume.assumeTrue; import java.io.File; import java.util.Iterator; +import java.util.regex.Pattern; import org.eclipse.jgit.api.MergeCommand.FastForwardMode; import org.eclipse.jgit.api.MergeResult.MergeStatus; @@ -1584,36 +1585,77 @@ public class MergeCommandTest extends RepositoryTestCase { assertEquals(MergeStatus.CONFLICTING, result.getMergeStatus()); } + private Ref prepareSuccessfulMerge(Git git) throws Exception { + writeTrashFile("a", "1\na\n3\n"); + git.add().addFilepattern("a").call(); + RevCommit initialCommit = git.commit().setMessage("initial").call(); + + createBranch(initialCommit, "refs/heads/side"); + checkoutBranch("refs/heads/side"); + + writeTrashFile("b", "1\nb\n3\n"); + git.add().addFilepattern("b").call(); + git.commit().setMessage("side").call(); + + checkoutBranch("refs/heads/master"); + + writeTrashFile("c", "1\nc\n3\n"); + git.add().addFilepattern("c").call(); + git.commit().setMessage("main").call(); + + return db.exactRef("refs/heads/side"); + } + @Test public void testMergeWithMessageOption() throws Exception { try (Git git = new Git(db)) { - writeTrashFile("a", "1\na\n3\n"); - git.add().addFilepattern("a").call(); - RevCommit initialCommit = git.commit().setMessage("initial").call(); + Ref sideBranch = prepareSuccessfulMerge(git); - createBranch(initialCommit, "refs/heads/side"); - checkoutBranch("refs/heads/side"); + git.merge().include(sideBranch).setStrategy(MergeStrategy.RESOLVE) + .setMessage("user message").call(); - writeTrashFile("b", "1\nb\n3\n"); - git.add().addFilepattern("b").call(); - git.commit().setMessage("side").call(); + assertNull(db.readMergeCommitMsg()); - checkoutBranch("refs/heads/master"); + Iterator<RevCommit> it = git.log().call().iterator(); + RevCommit newHead = it.next(); + assertEquals("user message", newHead.getFullMessage()); + } + } - writeTrashFile("c", "1\nc\n3\n"); - git.add().addFilepattern("c").call(); - git.commit().setMessage("main").call(); + @Test + public void testMergeWithChangeId() throws Exception { + try (Git git = new Git(db)) { + Ref sideBranch = prepareSuccessfulMerge(git); - Ref sideBranch = db.exactRef("refs/heads/side"); + git.merge().include(sideBranch).setStrategy(MergeStrategy.RESOLVE) + .setInsertChangeId(true).call(); + + assertNull(db.readMergeCommitMsg()); + + Iterator<RevCommit> it = git.log().call().iterator(); + RevCommit newHead = it.next(); + String commitMessage = newHead.getFullMessage(); + assertTrue(Pattern.compile("\nChange-Id: I[0-9a-fA-F]{40}\n") + .matcher(commitMessage).find()); + } + } + + @Test + public void testMergeWithMessageAndChangeId() throws Exception { + try (Git git = new Git(db)) { + Ref sideBranch = prepareSuccessfulMerge(git); git.merge().include(sideBranch).setStrategy(MergeStrategy.RESOLVE) - .setMessage("user message").call(); + .setMessage("user message").setInsertChangeId(true).call(); assertNull(db.readMergeCommitMsg()); Iterator<RevCommit> it = git.log().call().iterator(); RevCommit newHead = it.next(); - assertEquals("user message", newHead.getFullMessage()); + String commitMessage = newHead.getFullMessage(); + assertTrue(commitMessage.startsWith("user message\n\n")); + assertTrue(Pattern.compile("\nChange-Id: I[0-9a-fA-F]{40}\n") + .matcher(commitMessage).find()); } } |