@ -54,6 +54,7 @@ import static org.junit.Assume.assumeTrue;
import java.io.File ;
import java.io.File ;
import java.util.Iterator ;
import java.util.Iterator ;
import java.util.regex.Pattern ;
import org.eclipse.jgit.api.MergeCommand.FastForwardMode ;
import org.eclipse.jgit.api.MergeCommand.FastForwardMode ;
import org.eclipse.jgit.api.MergeResult.MergeStatus ;
import org.eclipse.jgit.api.MergeResult.MergeStatus ;
@ -1584,9 +1585,7 @@ public class MergeCommandTest extends RepositoryTestCase {
assertEquals ( MergeStatus . CONFLICTING , result . getMergeStatus ( ) ) ;
assertEquals ( MergeStatus . CONFLICTING , result . getMergeStatus ( ) ) ;
}
}
@Test
private Ref prepareSuccessfulMerge ( Git git ) throws Exception {
public void testMergeWithMessageOption ( ) throws Exception {
try ( Git git = new Git ( db ) ) {
writeTrashFile ( "a" , "1\na\n3\n" ) ;
writeTrashFile ( "a" , "1\na\n3\n" ) ;
git . add ( ) . addFilepattern ( "a" ) . call ( ) ;
git . add ( ) . addFilepattern ( "a" ) . call ( ) ;
RevCommit initialCommit = git . commit ( ) . setMessage ( "initial" ) . call ( ) ;
RevCommit initialCommit = git . commit ( ) . setMessage ( "initial" ) . call ( ) ;
@ -1604,7 +1603,13 @@ public class MergeCommandTest extends RepositoryTestCase {
git . add ( ) . addFilepattern ( "c" ) . call ( ) ;
git . add ( ) . addFilepattern ( "c" ) . call ( ) ;
git . commit ( ) . setMessage ( "main" ) . call ( ) ;
git . commit ( ) . setMessage ( "main" ) . call ( ) ;
Ref sideBranch = db . exactRef ( "refs/heads/side" ) ;
return db . exactRef ( "refs/heads/side" ) ;
}
@Test
public void testMergeWithMessageOption ( ) throws Exception {
try ( Git git = new Git ( db ) ) {
Ref sideBranch = prepareSuccessfulMerge ( git ) ;
git . merge ( ) . include ( sideBranch ) . setStrategy ( MergeStrategy . RESOLVE )
git . merge ( ) . include ( sideBranch ) . setStrategy ( MergeStrategy . RESOLVE )
. setMessage ( "user message" ) . call ( ) ;
. setMessage ( "user message" ) . call ( ) ;
@ -1617,6 +1622,43 @@ public class MergeCommandTest extends RepositoryTestCase {
}
}
}
}
@Test
public void testMergeWithChangeId ( ) throws Exception {
try ( Git git = new Git ( db ) ) {
Ref sideBranch = prepareSuccessfulMerge ( git ) ;
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" ) . setInsertChangeId ( true ) . call ( ) ;
assertNull ( db . readMergeCommitMsg ( ) ) ;
Iterator < RevCommit > it = git . log ( ) . call ( ) . iterator ( ) ;
RevCommit newHead = it . next ( ) ;
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 ( ) ) ;
}
}
@Test
@Test
public void testMergeConflictWithMessageOption ( ) throws Exception {
public void testMergeConflictWithMessageOption ( ) throws Exception {
try ( Git git = new Git ( db ) ) {
try ( Git git = new Git ( db ) ) {