@ -50,6 +50,7 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull ;
import static org.junit.Assert.assertNull ;
import static org.junit.Assert.assertTrue ;
import static org.junit.Assert.assertTrue ;
import static org.junit.Assert.fail ;
import static org.junit.Assert.fail ;
import static org.junit.Assume.assumeTrue ;
import java.io.File ;
import java.io.File ;
import java.util.Iterator ;
import java.util.Iterator ;
@ -96,11 +97,12 @@ public class MergeCommandTest extends RepositoryTestCase {
@Test
@Test
public void testMergeInItself ( ) throws Exception {
public void testMergeInItself ( ) throws Exception {
Git git = new Git ( db ) ;
try ( Git git = new Git ( db ) ) {
git . commit ( ) . setMessage ( "initial commit" ) . call ( ) ;
git . commit ( ) . setMessage ( "initial commit" ) . call ( ) ;
MergeResult result = git . merge ( ) . include ( db . exactRef ( Constants . HEAD ) ) . call ( ) ;
MergeResult result = git . merge ( ) . include ( db . exactRef ( Constants . HEAD ) ) . call ( ) ;
assertEquals ( MergeResult . MergeStatus . ALREADY_UP_TO_DATE , result . getMergeStatus ( ) ) ;
assertEquals ( MergeResult . MergeStatus . ALREADY_UP_TO_DATE , result . getMergeStatus ( ) ) ;
}
// no reflog entry written by merge
// no reflog entry written by merge
assertEquals ( "commit (initial): initial commit" ,
assertEquals ( "commit (initial): initial commit" ,
db
db
@ -112,7 +114,7 @@ public class MergeCommandTest extends RepositoryTestCase {
@Test
@Test
public void testAlreadyUpToDate ( ) throws Exception {
public void testAlreadyUpToDate ( ) throws Exception {
Git git = new Git ( db ) ;
try ( Git git = new Git ( db ) ) {
RevCommit first = git . commit ( ) . setMessage ( "initial commit" ) . call ( ) ;
RevCommit first = git . commit ( ) . setMessage ( "initial commit" ) . call ( ) ;
createBranch ( first , "refs/heads/branch1" ) ;
createBranch ( first , "refs/heads/branch1" ) ;
@ -120,6 +122,7 @@ public class MergeCommandTest extends RepositoryTestCase {
MergeResult result = git . merge ( ) . include ( db . exactRef ( "refs/heads/branch1" ) ) . call ( ) ;
MergeResult result = git . merge ( ) . include ( db . exactRef ( "refs/heads/branch1" ) ) . call ( ) ;
assertEquals ( MergeResult . MergeStatus . ALREADY_UP_TO_DATE , result . getMergeStatus ( ) ) ;
assertEquals ( MergeResult . MergeStatus . ALREADY_UP_TO_DATE , result . getMergeStatus ( ) ) ;
assertEquals ( second , result . getNewHead ( ) ) ;
assertEquals ( second , result . getNewHead ( ) ) ;
}
// no reflog entry written by merge
// no reflog entry written by merge
assertEquals ( "commit: second commit" , db
assertEquals ( "commit: second commit" , db
. getReflogReader ( Constants . HEAD ) . getLastEntry ( ) . getComment ( ) ) ;
. getReflogReader ( Constants . HEAD ) . getLastEntry ( ) . getComment ( ) ) ;
@ -129,7 +132,7 @@ public class MergeCommandTest extends RepositoryTestCase {
@Test
@Test
public void testFastForward ( ) throws Exception {
public void testFastForward ( ) throws Exception {
Git git = new Git ( db ) ;
try ( Git git = new Git ( db ) ) {
RevCommit first = git . commit ( ) . setMessage ( "initial commit" ) . call ( ) ;
RevCommit first = git . commit ( ) . setMessage ( "initial commit" ) . call ( ) ;
createBranch ( first , "refs/heads/branch1" ) ;
createBranch ( first , "refs/heads/branch1" ) ;
@ -141,6 +144,7 @@ public class MergeCommandTest extends RepositoryTestCase {
assertEquals ( MergeResult . MergeStatus . FAST_FORWARD , result . getMergeStatus ( ) ) ;
assertEquals ( MergeResult . MergeStatus . FAST_FORWARD , result . getMergeStatus ( ) ) ;
assertEquals ( second , result . getNewHead ( ) ) ;
assertEquals ( second , result . getNewHead ( ) ) ;
}
assertEquals ( "merge refs/heads/master: Fast-forward" ,
assertEquals ( "merge refs/heads/master: Fast-forward" ,
db . getReflogReader ( Constants . HEAD ) . getLastEntry ( ) . getComment ( ) ) ;
db . getReflogReader ( Constants . HEAD ) . getLastEntry ( ) . getComment ( ) ) ;
assertEquals ( "merge refs/heads/master: Fast-forward" ,
assertEquals ( "merge refs/heads/master: Fast-forward" ,
@ -149,7 +153,7 @@ public class MergeCommandTest extends RepositoryTestCase {
@Test
@Test
public void testFastForwardNoCommit ( ) throws Exception {
public void testFastForwardNoCommit ( ) throws Exception {
Git git = new Git ( db ) ;
try ( Git git = new Git ( db ) ) {
RevCommit first = git . commit ( ) . setMessage ( "initial commit" ) . call ( ) ;
RevCommit first = git . commit ( ) . setMessage ( "initial commit" ) . call ( ) ;
createBranch ( first , "refs/heads/branch1" ) ;
createBranch ( first , "refs/heads/branch1" ) ;
@ -163,6 +167,7 @@ public class MergeCommandTest extends RepositoryTestCase {
assertEquals ( MergeResult . MergeStatus . FAST_FORWARD ,
assertEquals ( MergeResult . MergeStatus . FAST_FORWARD ,
result . getMergeStatus ( ) ) ;
result . getMergeStatus ( ) ) ;
assertEquals ( second , result . getNewHead ( ) ) ;
assertEquals ( second , result . getNewHead ( ) ) ;
}
assertEquals ( "merge refs/heads/master: Fast-forward" , db
assertEquals ( "merge refs/heads/master: Fast-forward" , db
. getReflogReader ( Constants . HEAD ) . getLastEntry ( ) . getComment ( ) ) ;
. getReflogReader ( Constants . HEAD ) . getLastEntry ( ) . getComment ( ) ) ;
assertEquals ( "merge refs/heads/master: Fast-forward" , db
assertEquals ( "merge refs/heads/master: Fast-forward" , db
@ -171,8 +176,7 @@ public class MergeCommandTest extends RepositoryTestCase {
@Test
@Test
public void testFastForwardWithFiles ( ) throws Exception {
public void testFastForwardWithFiles ( ) throws Exception {
Git git = new Git ( db ) ;
try ( Git git = new Git ( db ) ) {
writeTrashFile ( "file1" , "file1" ) ;
writeTrashFile ( "file1" , "file1" ) ;
git . add ( ) . addFilepattern ( "file1" ) . call ( ) ;
git . add ( ) . addFilepattern ( "file1" ) . call ( ) ;
RevCommit first = git . commit ( ) . setMessage ( "initial commit" ) . call ( ) ;
RevCommit first = git . commit ( ) . setMessage ( "initial commit" ) . call ( ) ;
@ -194,6 +198,7 @@ public class MergeCommandTest extends RepositoryTestCase {
assertTrue ( new File ( db . getWorkTree ( ) , "file2" ) . exists ( ) ) ;
assertTrue ( new File ( db . getWorkTree ( ) , "file2" ) . exists ( ) ) ;
assertEquals ( MergeResult . MergeStatus . FAST_FORWARD , result . getMergeStatus ( ) ) ;
assertEquals ( MergeResult . MergeStatus . FAST_FORWARD , result . getMergeStatus ( ) ) ;
assertEquals ( second , result . getNewHead ( ) ) ;
assertEquals ( second , result . getNewHead ( ) ) ;
}
assertEquals ( "merge refs/heads/master: Fast-forward" ,
assertEquals ( "merge refs/heads/master: Fast-forward" ,
db . getReflogReader ( Constants . HEAD ) . getLastEntry ( ) . getComment ( ) ) ;
db . getReflogReader ( Constants . HEAD ) . getLastEntry ( ) . getComment ( ) ) ;
assertEquals ( "merge refs/heads/master: Fast-forward" ,
assertEquals ( "merge refs/heads/master: Fast-forward" ,
@ -202,8 +207,7 @@ public class MergeCommandTest extends RepositoryTestCase {
@Test
@Test
public void testMultipleHeads ( ) throws Exception {
public void testMultipleHeads ( ) throws Exception {
Git git = new Git ( db ) ;
try ( Git git = new Git ( db ) ) {
writeTrashFile ( "file1" , "file1" ) ;
writeTrashFile ( "file1" , "file1" ) ;
git . add ( ) . addFilepattern ( "file1" ) . call ( ) ;
git . add ( ) . addFilepattern ( "file1" ) . call ( ) ;
RevCommit first = git . commit ( ) . setMessage ( "initial commit" ) . call ( ) ;
RevCommit first = git . commit ( ) . setMessage ( "initial commit" ) . call ( ) ;
@ -231,12 +235,12 @@ public class MergeCommandTest extends RepositoryTestCase {
// expected this exception
// expected this exception
}
}
}
}
}
@Theory
@Theory
public void testMergeSuccessAllStrategies ( MergeStrategy mergeStrategy )
public void testMergeSuccessAllStrategies ( MergeStrategy mergeStrategy )
throws Exception {
throws Exception {
Git git = new Git ( db ) ;
try ( Git git = new Git ( db ) ) {
RevCommit first = git . commit ( ) . setMessage ( "first" ) . call ( ) ;
RevCommit first = git . commit ( ) . setMessage ( "first" ) . call ( ) ;
createBranch ( first , "refs/heads/side" ) ;
createBranch ( first , "refs/heads/side" ) ;
@ -252,6 +256,7 @@ public class MergeCommandTest extends RepositoryTestCase {
MergeResult result = git . merge ( ) . setStrategy ( mergeStrategy )
MergeResult result = git . merge ( ) . setStrategy ( mergeStrategy )
. include ( db . exactRef ( R_HEADS + MASTER ) ) . call ( ) ;
. include ( db . exactRef ( R_HEADS + MASTER ) ) . call ( ) ;
assertEquals ( MergeStatus . MERGED , result . getMergeStatus ( ) ) ;
assertEquals ( MergeStatus . MERGED , result . getMergeStatus ( ) ) ;
}
assertEquals (
assertEquals (
"merge refs/heads/master: Merge made by "
"merge refs/heads/master: Merge made by "
+ mergeStrategy . getName ( ) + "." ,
+ mergeStrategy . getName ( ) + "." ,
@ -265,8 +270,7 @@ public class MergeCommandTest extends RepositoryTestCase {
@Theory
@Theory
public void testMergeSuccessAllStrategiesNoCommit (
public void testMergeSuccessAllStrategiesNoCommit (
MergeStrategy mergeStrategy ) throws Exception {
MergeStrategy mergeStrategy ) throws Exception {
Git git = new Git ( db ) ;
try ( Git git = new Git ( db ) ) {
RevCommit first = git . commit ( ) . setMessage ( "first" ) . call ( ) ;
RevCommit first = git . commit ( ) . setMessage ( "first" ) . call ( ) ;
createBranch ( first , "refs/heads/side" ) ;
createBranch ( first , "refs/heads/side" ) ;
@ -286,11 +290,11 @@ public class MergeCommandTest extends RepositoryTestCase {
assertEquals ( db . exactRef ( Constants . HEAD ) . getTarget ( ) . getObjectId ( ) ,
assertEquals ( db . exactRef ( Constants . HEAD ) . getTarget ( ) . getObjectId ( ) ,
thirdCommit . getId ( ) ) ;
thirdCommit . getId ( ) ) ;
}
}
}
@Test
@Test
public void testContentMerge ( ) throws Exception {
public void testContentMerge ( ) throws Exception {
Git git = new Git ( db ) ;
try ( Git git = new Git ( db ) ) {
writeTrashFile ( "a" , "1\na\n3\n" ) ;
writeTrashFile ( "a" , "1\na\n3\n" ) ;
writeTrashFile ( "b" , "1\nb\n3\n" ) ;
writeTrashFile ( "b" , "1\nb\n3\n" ) ;
writeTrashFile ( "c/c/c" , "1\nc\n3\n" ) ;
writeTrashFile ( "c/c/c" , "1\nc\n3\n" ) ;
@ -331,11 +335,11 @@ public class MergeCommandTest extends RepositoryTestCase {
assertEquals ( RepositoryState . MERGING , db . getRepositoryState ( ) ) ;
assertEquals ( RepositoryState . MERGING , db . getRepositoryState ( ) ) ;
}
}
}
@Test
@Test
public void testMergeTag ( ) throws Exception {
public void testMergeTag ( ) throws Exception {
Git git = new Git ( db ) ;
try ( Git git = new Git ( db ) ) {
writeTrashFile ( "a" , "a" ) ;
writeTrashFile ( "a" , "a" ) ;
git . add ( ) . addFilepattern ( "a" ) . call ( ) ;
git . add ( ) . addFilepattern ( "a" ) . call ( ) ;
RevCommit initialCommit = git . commit ( ) . setMessage ( "initial" ) . call ( ) ;
RevCommit initialCommit = git . commit ( ) . setMessage ( "initial" ) . call ( ) ;
@ -358,11 +362,11 @@ public class MergeCommandTest extends RepositoryTestCase {
MergeResult result = git . merge ( ) . include ( tag ) . setStrategy ( MergeStrategy . RESOLVE ) . call ( ) ;
MergeResult result = git . merge ( ) . include ( tag ) . setStrategy ( MergeStrategy . RESOLVE ) . call ( ) ;
assertEquals ( MergeStatus . MERGED , result . getMergeStatus ( ) ) ;
assertEquals ( MergeStatus . MERGED , result . getMergeStatus ( ) ) ;
}
}
}
@Test
@Test
public void testMergeMessage ( ) throws Exception {
public void testMergeMessage ( ) throws Exception {
Git git = new Git ( db ) ;
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 ( ) ;
@ -387,13 +391,13 @@ public class MergeCommandTest extends RepositoryTestCase {
assertEquals ( "Merge branch 'side'\n\nConflicts:\n\ta\n" ,
assertEquals ( "Merge branch 'side'\n\nConflicts:\n\ta\n" ,
db . readMergeCommitMsg ( ) ) ;
db . readMergeCommitMsg ( ) ) ;
}
}
}
@Test
@Test
public void testMergeNonVersionedPaths ( ) throws Exception {
public void testMergeNonVersionedPaths ( ) throws Exception {
Git git = new Git ( db ) ;
try ( Git git = new Git ( db ) ) {
writeTrashFile ( "a" , "1\na\n3\n" ) ;
writeTrashFile ( "a" , "1\na\n3\n" ) ;
writeTrashFile ( "b" , "1\nb\n3\n" ) ;
writeTrashFile ( "b" , "1\nb\n3\n" ) ;
writeTrashFile ( "c/c/c" , "1\nc\n3\n" ) ;
writeTrashFile ( "c/c/c" , "1\nc\n3\n" ) ;
@ -440,11 +444,11 @@ public class MergeCommandTest extends RepositoryTestCase {
assertEquals ( RepositoryState . MERGING , db . getRepositoryState ( ) ) ;
assertEquals ( RepositoryState . MERGING , db . getRepositoryState ( ) ) ;
}
}
}
@Test
@Test
public void testMultipleCreations ( ) throws Exception {
public void testMultipleCreations ( ) throws Exception {
Git git = new Git ( db ) ;
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 ( ) ;
@ -466,11 +470,11 @@ public class MergeCommandTest extends RepositoryTestCase {
. setStrategy ( MergeStrategy . RESOLVE ) . call ( ) ;
. setStrategy ( MergeStrategy . RESOLVE ) . call ( ) ;
assertEquals ( MergeStatus . CONFLICTING , result . getMergeStatus ( ) ) ;
assertEquals ( MergeStatus . CONFLICTING , result . getMergeStatus ( ) ) ;
}
}
}
@Test
@Test
public void testMultipleCreationsSameContent ( ) throws Exception {
public void testMultipleCreationsSameContent ( ) throws Exception {
Git git = new Git ( db ) ;
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 ( ) ;
@ -501,11 +505,11 @@ public class MergeCommandTest extends RepositoryTestCase {
. getReflogReader ( db . getBranch ( ) )
. getReflogReader ( db . getBranch ( ) )
. getLastEntry ( ) . getComment ( ) ) ;
. getLastEntry ( ) . getComment ( ) ) ;
}
}
}
@Test
@Test
public void testSuccessfulContentMerge ( ) throws Exception {
public void testSuccessfulContentMerge ( ) throws Exception {
Git git = new Git ( db ) ;
try ( Git git = new Git ( db ) ) {
writeTrashFile ( "a" , "1\na\n3\n" ) ;
writeTrashFile ( "a" , "1\na\n3\n" ) ;
writeTrashFile ( "b" , "1\nb\n3\n" ) ;
writeTrashFile ( "b" , "1\nb\n3\n" ) ;
writeTrashFile ( "c/c/c" , "1\nc\n3\n" ) ;
writeTrashFile ( "c/c/c" , "1\nc\n3\n" ) ;
@ -559,11 +563,11 @@ public class MergeCommandTest extends RepositoryTestCase {
assertEquals ( RepositoryState . SAFE , db . getRepositoryState ( ) ) ;
assertEquals ( RepositoryState . SAFE , db . getRepositoryState ( ) ) ;
// test index state
// test index state
}
}
}
@Test
@Test
public void testSuccessfulContentMergeNoCommit ( ) throws Exception {
public void testSuccessfulContentMergeNoCommit ( ) throws Exception {
Git git = new Git ( db ) ;
try ( Git git = new Git ( db ) ) {
writeTrashFile ( "a" , "1\na\n3\n" ) ;
writeTrashFile ( "a" , "1\na\n3\n" ) ;
writeTrashFile ( "b" , "1\nb\n3\n" ) ;
writeTrashFile ( "b" , "1\nb\n3\n" ) ;
writeTrashFile ( "c/c/c" , "1\nc\n3\n" ) ;
writeTrashFile ( "c/c/c" , "1\nc\n3\n" ) ;
@ -609,12 +613,12 @@ public class MergeCommandTest extends RepositoryTestCase {
assertNull ( result . getNewHead ( ) ) ;
assertNull ( result . getNewHead ( ) ) ;
assertEquals ( RepositoryState . MERGING_RESOLVED , db . getRepositoryState ( ) ) ;
assertEquals ( RepositoryState . MERGING_RESOLVED , db . getRepositoryState ( ) ) ;
}
}
}
@Test
@Test
public void testSuccessfulContentMergeAndDirtyworkingTree ( )
public void testSuccessfulContentMergeAndDirtyworkingTree ( )
throws Exception {
throws Exception {
Git git = new Git ( db ) ;
try ( Git git = new Git ( db ) ) {
writeTrashFile ( "a" , "1\na\n3\n" ) ;
writeTrashFile ( "a" , "1\na\n3\n" ) ;
writeTrashFile ( "b" , "1\nb\n3\n" ) ;
writeTrashFile ( "b" , "1\nb\n3\n" ) ;
writeTrashFile ( "d" , "1\nd\n3\n" ) ;
writeTrashFile ( "d" , "1\nd\n3\n" ) ;
@ -670,11 +674,11 @@ public class MergeCommandTest extends RepositoryTestCase {
assertEquals ( RepositoryState . SAFE , db . getRepositoryState ( ) ) ;
assertEquals ( RepositoryState . SAFE , db . getRepositoryState ( ) ) ;
}
}
}
@Test
@Test
public void testSingleDeletion ( ) throws Exception {
public void testSingleDeletion ( ) throws Exception {
Git git = new Git ( db ) ;
try ( Git git = new Git ( db ) ) {
writeTrashFile ( "a" , "1\na\n3\n" ) ;
writeTrashFile ( "a" , "1\na\n3\n" ) ;
writeTrashFile ( "b" , "1\nb\n3\n" ) ;
writeTrashFile ( "b" , "1\nb\n3\n" ) ;
writeTrashFile ( "d" , "1\nd\n3\n" ) ;
writeTrashFile ( "d" , "1\nd\n3\n" ) ;
@ -725,11 +729,11 @@ public class MergeCommandTest extends RepositoryTestCase {
read ( new File ( db . getWorkTree ( ) , "c/c/c" ) ) ) ;
read ( new File ( db . getWorkTree ( ) , "c/c/c" ) ) ) ;
assertEquals ( "1\nd\n3\n" , read ( new File ( db . getWorkTree ( ) , "d" ) ) ) ;
assertEquals ( "1\nd\n3\n" , read ( new File ( db . getWorkTree ( ) , "d" ) ) ) ;
}
}
}
@Test
@Test
public void testMultipleDeletions ( ) throws Exception {
public void testMultipleDeletions ( ) throws Exception {
Git git = new Git ( db ) ;
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 ( ) ;
@ -754,11 +758,11 @@ public class MergeCommandTest extends RepositoryTestCase {
. setStrategy ( MergeStrategy . RESOLVE ) . call ( ) ;
. setStrategy ( MergeStrategy . RESOLVE ) . call ( ) ;
assertEquals ( MergeStatus . MERGED , result . getMergeStatus ( ) ) ;
assertEquals ( MergeStatus . MERGED , result . getMergeStatus ( ) ) ;
}
}
}
@Test
@Test
public void testDeletionAndConflict ( ) throws Exception {
public void testDeletionAndConflict ( ) throws Exception {
Git git = new Git ( db ) ;
try ( Git git = new Git ( db ) ) {
writeTrashFile ( "a" , "1\na\n3\n" ) ;
writeTrashFile ( "a" , "1\na\n3\n" ) ;
writeTrashFile ( "b" , "1\nb\n3\n" ) ;
writeTrashFile ( "b" , "1\nb\n3\n" ) ;
writeTrashFile ( "d" , "1\nd\n3\n" ) ;
writeTrashFile ( "d" , "1\nd\n3\n" ) ;
@ -798,11 +802,11 @@ public class MergeCommandTest extends RepositoryTestCase {
read ( new File ( db . getWorkTree ( ) , "c/c/c" ) ) ) ;
read ( new File ( db . getWorkTree ( ) , "c/c/c" ) ) ) ;
assertEquals ( "1\nd\n3\n" , read ( new File ( db . getWorkTree ( ) , "d" ) ) ) ;
assertEquals ( "1\nd\n3\n" , read ( new File ( db . getWorkTree ( ) , "d" ) ) ) ;
}
}
}
@Test
@Test
public void testDeletionOnMasterConflict ( ) throws Exception {
public void testDeletionOnMasterConflict ( ) throws Exception {
Git git = new Git ( db ) ;
try ( Git git = new Git ( db ) ) {
writeTrashFile ( "a" , "1\na\n3\n" ) ;
writeTrashFile ( "a" , "1\na\n3\n" ) ;
writeTrashFile ( "b" , "1\nb\n3\n" ) ;
writeTrashFile ( "b" , "1\nb\n3\n" ) ;
git . add ( ) . addFilepattern ( "a" ) . addFilepattern ( "b" ) . call ( ) ;
git . add ( ) . addFilepattern ( "a" ) . addFilepattern ( "b" ) . call ( ) ;
@ -830,11 +834,11 @@ public class MergeCommandTest extends RepositoryTestCase {
assertEquals ( "1\na(side)\n3\n" , read ( new File ( db . getWorkTree ( ) , "a" ) ) ) ;
assertEquals ( "1\na(side)\n3\n" , read ( new File ( db . getWorkTree ( ) , "a" ) ) ) ;
assertEquals ( "1\nb\n3\n" , read ( new File ( db . getWorkTree ( ) , "b" ) ) ) ;
assertEquals ( "1\nb\n3\n" , read ( new File ( db . getWorkTree ( ) , "b" ) ) ) ;
}
}
}
@Test
@Test
public void testDeletionOnSideConflict ( ) throws Exception {
public void testDeletionOnSideConflict ( ) throws Exception {
Git git = new Git ( db ) ;
try ( Git git = new Git ( db ) ) {
writeTrashFile ( "a" , "1\na\n3\n" ) ;
writeTrashFile ( "a" , "1\na\n3\n" ) ;
writeTrashFile ( "b" , "1\nb\n3\n" ) ;
writeTrashFile ( "b" , "1\nb\n3\n" ) ;
git . add ( ) . addFilepattern ( "a" ) . addFilepattern ( "b" ) . call ( ) ;
git . add ( ) . addFilepattern ( "a" ) . addFilepattern ( "b" ) . call ( ) ;
@ -864,14 +868,14 @@ public class MergeCommandTest extends RepositoryTestCase {
assertEquals ( 1 , result . getConflicts ( ) . size ( ) ) ;
assertEquals ( 1 , result . getConflicts ( ) . size ( ) ) ;
assertEquals ( 3 , result . getConflicts ( ) . get ( "a" ) [ 0 ] . length ) ;
assertEquals ( 3 , result . getConflicts ( ) . get ( "a" ) [ 0 ] . length ) ;
}
}
}
@Test
@Test
public void testModifiedAndRenamed ( ) throws Exception {
public void testModifiedAndRenamed ( ) throws Exception {
// this test is essentially the same as testDeletionOnSideConflict,
// this test is essentially the same as testDeletionOnSideConflict,
// however if once rename support is added this test should result in a
// however if once rename support is added this test should result in a
// successful merge instead of a conflict
// successful merge instead of a conflict
Git git = new Git ( db ) ;
try ( Git git = new Git ( db ) ) {
writeTrashFile ( "x" , "add x" ) ;
writeTrashFile ( "x" , "add x" ) ;
git . add ( ) . addFilepattern ( "x" ) . call ( ) ;
git . add ( ) . addFilepattern ( "x" ) . call ( ) ;
RevCommit initial = git . commit ( ) . setMessage ( "add x" ) . call ( ) ;
RevCommit initial = git . commit ( ) . setMessage ( "add x" ) . call ( ) ;
@ -903,11 +907,11 @@ public class MergeCommandTest extends RepositoryTestCase {
assertEquals ( 1 , d2Merge . getConflicts ( ) . size ( ) ) ;
assertEquals ( 1 , d2Merge . getConflicts ( ) . size ( ) ) ;
assertEquals ( 3 , d2Merge . getConflicts ( ) . get ( "x" ) [ 0 ] . length ) ;
assertEquals ( 3 , d2Merge . getConflicts ( ) . get ( "x" ) [ 0 ] . length ) ;
}
}
}
@Test
@Test
public void testMergeFailingWithDirtyWorkingTree ( ) throws Exception {
public void testMergeFailingWithDirtyWorkingTree ( ) throws Exception {
Git git = new Git ( db ) ;
try ( Git git = new Git ( db ) ) {
writeTrashFile ( "a" , "1\na\n3\n" ) ;
writeTrashFile ( "a" , "1\na\n3\n" ) ;
writeTrashFile ( "b" , "1\nb\n3\n" ) ;
writeTrashFile ( "b" , "1\nb\n3\n" ) ;
git . add ( ) . addFilepattern ( "a" ) . addFilepattern ( "b" ) . call ( ) ;
git . add ( ) . addFilepattern ( "a" ) . addFilepattern ( "b" ) . call ( ) ;
@ -942,11 +946,11 @@ public class MergeCommandTest extends RepositoryTestCase {
assertEquals ( RepositoryState . SAFE , db . getRepositoryState ( ) ) ;
assertEquals ( RepositoryState . SAFE , db . getRepositoryState ( ) ) ;
}
}
}
@Test
@Test
public void testMergeConflictFileFolder ( ) throws Exception {
public void testMergeConflictFileFolder ( ) throws Exception {
Git git = new Git ( db ) ;
try ( Git git = new Git ( db ) ) {
writeTrashFile ( "a" , "1\na\n3\n" ) ;
writeTrashFile ( "a" , "1\na\n3\n" ) ;
writeTrashFile ( "b" , "1\nb\n3\n" ) ;
writeTrashFile ( "b" , "1\nb\n3\n" ) ;
git . add ( ) . addFilepattern ( "a" ) . addFilepattern ( "b" ) . call ( ) ;
git . add ( ) . addFilepattern ( "a" ) . addFilepattern ( "b" ) . call ( ) ;
@ -981,11 +985,11 @@ public class MergeCommandTest extends RepositoryTestCase {
assertEquals ( RepositoryState . MERGING , db . getRepositoryState ( ) ) ;
assertEquals ( RepositoryState . MERGING , db . getRepositoryState ( ) ) ;
}
}
}
@Test
@Test
public void testSuccessfulMergeFailsDueToDirtyIndex ( ) throws Exception {
public void testSuccessfulMergeFailsDueToDirtyIndex ( ) throws Exception {
Git git = new Git ( db ) ;
try ( Git git = new Git ( db ) ) {
File fileA = writeTrashFile ( "a" , "a" ) ;
File fileA = writeTrashFile ( "a" , "a" ) ;
RevCommit initialCommit = addAllAndCommit ( git ) ;
RevCommit initialCommit = addAllAndCommit ( git ) ;
@ -1017,11 +1021,11 @@ public class MergeCommandTest extends RepositoryTestCase {
checkMergeFailedResult ( result , MergeFailureReason . DIRTY_INDEX ,
checkMergeFailedResult ( result , MergeFailureReason . DIRTY_INDEX ,
indexState , fileA ) ;
indexState , fileA ) ;
}
}
}
@Test
@Test
public void testConflictingMergeFailsDueToDirtyIndex ( ) throws Exception {
public void testConflictingMergeFailsDueToDirtyIndex ( ) throws Exception {
Git git = new Git ( db ) ;
try ( Git git = new Git ( db ) ) {
File fileA = writeTrashFile ( "a" , "a" ) ;
File fileA = writeTrashFile ( "a" , "a" ) ;
RevCommit initialCommit = addAllAndCommit ( git ) ;
RevCommit initialCommit = addAllAndCommit ( git ) ;
@ -1055,11 +1059,11 @@ public class MergeCommandTest extends RepositoryTestCase {
checkMergeFailedResult ( result , MergeFailureReason . DIRTY_INDEX ,
checkMergeFailedResult ( result , MergeFailureReason . DIRTY_INDEX ,
indexState , fileA ) ;
indexState , fileA ) ;
}
}
}
@Test
@Test
public void testSuccessfulMergeFailsDueToDirtyWorktree ( ) throws Exception {
public void testSuccessfulMergeFailsDueToDirtyWorktree ( ) throws Exception {
Git git = new Git ( db ) ;
try ( Git git = new Git ( db ) ) {
File fileA = writeTrashFile ( "a" , "a" ) ;
File fileA = writeTrashFile ( "a" , "a" ) ;
RevCommit initialCommit = addAllAndCommit ( git ) ;
RevCommit initialCommit = addAllAndCommit ( git ) ;
@ -1090,11 +1094,11 @@ public class MergeCommandTest extends RepositoryTestCase {
checkMergeFailedResult ( result , MergeFailureReason . DIRTY_WORKTREE ,
checkMergeFailedResult ( result , MergeFailureReason . DIRTY_WORKTREE ,
indexState , fileA ) ;
indexState , fileA ) ;
}
}
}
@Test
@Test
public void testConflictingMergeFailsDueToDirtyWorktree ( ) throws Exception {
public void testConflictingMergeFailsDueToDirtyWorktree ( ) throws Exception {
Git git = new Git ( db ) ;
try ( Git git = new Git ( db ) ) {
File fileA = writeTrashFile ( "a" , "a" ) ;
File fileA = writeTrashFile ( "a" , "a" ) ;
RevCommit initialCommit = addAllAndCommit ( git ) ;
RevCommit initialCommit = addAllAndCommit ( git ) ;
@ -1127,6 +1131,7 @@ public class MergeCommandTest extends RepositoryTestCase {
checkMergeFailedResult ( result , MergeFailureReason . DIRTY_WORKTREE ,
checkMergeFailedResult ( result , MergeFailureReason . DIRTY_WORKTREE ,
indexState , fileA ) ;
indexState , fileA ) ;
}
}
}
@Test
@Test
public void testMergeRemovingFolders ( ) throws Exception {
public void testMergeRemovingFolders ( ) throws Exception {
@ -1143,7 +1148,7 @@ public class MergeCommandTest extends RepositoryTestCase {
file = new File ( folder2 , "file2.txt" ) ;
file = new File ( folder2 , "file2.txt" ) ;
write ( file , "folder2--file2.txt" ) ;
write ( file , "folder2--file2.txt" ) ;
Git git = new Git ( db ) ;
try ( Git git = new Git ( db ) ) {
git . add ( ) . addFilepattern ( folder1 . getName ( ) )
git . add ( ) . addFilepattern ( folder1 . getName ( ) )
. addFilepattern ( folder2 . getName ( ) ) . call ( ) ;
. addFilepattern ( folder2 . getName ( ) ) . call ( ) ;
RevCommit commit1 = git . commit ( ) . setMessage ( "adding folders" ) . call ( ) ;
RevCommit commit1 = git . commit ( ) . setMessage ( "adding folders" ) . call ( ) ;
@ -1167,6 +1172,7 @@ public class MergeCommandTest extends RepositoryTestCase {
assertFalse ( folder1 . exists ( ) ) ;
assertFalse ( folder1 . exists ( ) ) ;
assertFalse ( folder2 . exists ( ) ) ;
assertFalse ( folder2 . exists ( ) ) ;
}
}
}
@Test
@Test
public void testMergeRemovingFoldersWithoutFastForward ( ) throws Exception {
public void testMergeRemovingFoldersWithoutFastForward ( ) throws Exception {
@ -1183,7 +1189,7 @@ public class MergeCommandTest extends RepositoryTestCase {
file = new File ( folder2 , "file2.txt" ) ;
file = new File ( folder2 , "file2.txt" ) ;
write ( file , "folder2--file2.txt" ) ;
write ( file , "folder2--file2.txt" ) ;
Git git = new Git ( db ) ;
try ( Git git = new Git ( db ) ) {
git . add ( ) . addFilepattern ( folder1 . getName ( ) )
git . add ( ) . addFilepattern ( folder1 . getName ( ) )
. addFilepattern ( folder2 . getName ( ) ) . call ( ) ;
. addFilepattern ( folder2 . getName ( ) ) . call ( ) ;
RevCommit base = git . commit ( ) . setMessage ( "adding folders" ) . call ( ) ;
RevCommit base = git . commit ( ) . setMessage ( "adding folders" ) . call ( ) ;
@ -1212,14 +1218,13 @@ public class MergeCommandTest extends RepositoryTestCase {
result . getMergeStatus ( ) ) ;
result . getMergeStatus ( ) ) ;
assertFalse ( folder1 . exists ( ) ) ;
assertFalse ( folder1 . exists ( ) ) ;
}
}
}
@Test
@Test
public void testFileModeMerge ( ) throws Exception {
public void testFileModeMerge ( ) throws Exception {
if ( ! FS . DETECTED . supportsExecute ( ) )
return ;
// Only Java6
// Only Java6
Git git = new Git ( db ) ;
assumeTrue ( FS . DETECTED . supportsExecute ( ) ) ;
try ( Git git = new Git ( db ) ) {
writeTrashFile ( "mergeableMode" , "a" ) ;
writeTrashFile ( "mergeableMode" , "a" ) ;
setExecutable ( git , "mergeableMode" , false ) ;
setExecutable ( git , "mergeableMode" , false ) ;
writeTrashFile ( "conflictingModeWithBase" , "a" ) ;
writeTrashFile ( "conflictingModeWithBase" , "a" ) ;
@ -1251,15 +1256,14 @@ public class MergeCommandTest extends RepositoryTestCase {
assertTrue ( canExecute ( git , "mergeableMode" ) ) ;
assertTrue ( canExecute ( git , "mergeableMode" ) ) ;
assertFalse ( canExecute ( git , "conflictingModeNoBase" ) ) ;
assertFalse ( canExecute ( git , "conflictingModeNoBase" ) ) ;
}
}
}
@Test
@Test
public void testFileModeMergeWithDirtyWorkTree ( ) throws Exception {
public void testFileModeMergeWithDirtyWorkTree ( ) throws Exception {
if ( ! FS . DETECTED . supportsExecute ( ) )
return ;
// Only Java6 (or set x bit in index)
// Only Java6 (or set x bit in index)
assumeTrue ( FS . DETECTED . supportsExecute ( ) ) ;
Git git = new Git ( db ) ;
try ( Git git = new Git ( db ) ) {
writeTrashFile ( "mergeableButDirty" , "a" ) ;
writeTrashFile ( "mergeableButDirty" , "a" ) ;
setExecutable ( git , "mergeableButDirty" , false ) ;
setExecutable ( git , "mergeableButDirty" , false ) ;
RevCommit initialCommit = addAllAndCommit ( git ) ;
RevCommit initialCommit = addAllAndCommit ( git ) ;
@ -1284,11 +1288,11 @@ public class MergeCommandTest extends RepositoryTestCase {
assertEquals ( MergeStatus . FAILED , result . getMergeStatus ( ) ) ;
assertEquals ( MergeStatus . FAILED , result . getMergeStatus ( ) ) ;
assertFalse ( canExecute ( git , "mergeableButDirty" ) ) ;
assertFalse ( canExecute ( git , "mergeableButDirty" ) ) ;
}
}
}
@Test
@Test
public void testSquashFastForward ( ) throws Exception {
public void testSquashFastForward ( ) throws Exception {
Git git = new Git ( db ) ;
try ( Git git = new Git ( db ) ) {
writeTrashFile ( "file1" , "file1" ) ;
writeTrashFile ( "file1" , "file1" ) ;
git . add ( ) . addFilepattern ( "file1" ) . call ( ) ;
git . add ( ) . addFilepattern ( "file1" ) . call ( ) ;
RevCommit first = git . commit ( ) . setMessage ( "initial commit" ) . call ( ) ;
RevCommit first = git . commit ( ) . setMessage ( "initial commit" ) . call ( ) ;
@ -1350,11 +1354,11 @@ public class MergeCommandTest extends RepositoryTestCase {
Status stat = git . status ( ) . call ( ) ;
Status stat = git . status ( ) . call ( ) ;
assertEquals ( Sets . of ( "file2" , "file3" ) , stat . getAdded ( ) ) ;
assertEquals ( Sets . of ( "file2" , "file3" ) , stat . getAdded ( ) ) ;
}
}
}
@Test
@Test
public void testSquashMerge ( ) throws Exception {
public void testSquashMerge ( ) throws Exception {
Git git = new Git ( db ) ;
try ( Git git = new Git ( db ) ) {
writeTrashFile ( "file1" , "file1" ) ;
writeTrashFile ( "file1" , "file1" ) ;
git . add ( ) . addFilepattern ( "file1" ) . call ( ) ;
git . add ( ) . addFilepattern ( "file1" ) . call ( ) ;
RevCommit first = git . commit ( ) . setMessage ( "initial commit" ) . call ( ) ;
RevCommit first = git . commit ( ) . setMessage ( "initial commit" ) . call ( ) ;
@ -1408,11 +1412,11 @@ public class MergeCommandTest extends RepositoryTestCase {
Status stat = git . status ( ) . call ( ) ;
Status stat = git . status ( ) . call ( ) ;
assertEquals ( Sets . of ( "file3" ) , stat . getAdded ( ) ) ;
assertEquals ( Sets . of ( "file3" ) , stat . getAdded ( ) ) ;
}
}
}
@Test
@Test
public void testSquashMergeConflict ( ) throws Exception {
public void testSquashMergeConflict ( ) throws Exception {
Git git = new Git ( db ) ;
try ( Git git = new Git ( db ) ) {
writeTrashFile ( "file1" , "file1" ) ;
writeTrashFile ( "file1" , "file1" ) ;
git . add ( ) . addFilepattern ( "file1" ) . call ( ) ;
git . add ( ) . addFilepattern ( "file1" ) . call ( ) ;
RevCommit first = git . commit ( ) . setMessage ( "initial commit" ) . call ( ) ;
RevCommit first = git . commit ( ) . setMessage ( "initial commit" ) . call ( ) ;
@ -1464,10 +1468,11 @@ public class MergeCommandTest extends RepositoryTestCase {
Status stat = git . status ( ) . call ( ) ;
Status stat = git . status ( ) . call ( ) ;
assertEquals ( Sets . of ( "file2" ) , stat . getConflicting ( ) ) ;
assertEquals ( Sets . of ( "file2" ) , stat . getConflicting ( ) ) ;
}
}
}
@Test
@Test
public void testFastForwardOnly ( ) throws Exception {
public void testFastForwardOnly ( ) throws Exception {
Git git = new Git ( db ) ;
try ( Git git = new Git ( db ) ) {
RevCommit initialCommit = git . commit ( ) . setMessage ( "initial commit" )
RevCommit initialCommit = git . commit ( ) . setMessage ( "initial commit" )
. call ( ) ;
. call ( ) ;
createBranch ( initialCommit , "refs/heads/branch1" ) ;
createBranch ( initialCommit , "refs/heads/branch1" ) ;
@ -1481,10 +1486,11 @@ public class MergeCommandTest extends RepositoryTestCase {
assertEquals ( MergeStatus . FAST_FORWARD , result . getMergeStatus ( ) ) ;
assertEquals ( MergeStatus . FAST_FORWARD , result . getMergeStatus ( ) ) ;
}
}
}
@Test
@Test
public void testNoFastForward ( ) throws Exception {
public void testNoFastForward ( ) throws Exception {
Git git = new Git ( db ) ;
try ( Git git = new Git ( db ) ) {
RevCommit initialCommit = git . commit ( ) . setMessage ( "initial commit" )
RevCommit initialCommit = git . commit ( ) . setMessage ( "initial commit" )
. call ( ) ;
. call ( ) ;
createBranch ( initialCommit , "refs/heads/branch1" ) ;
createBranch ( initialCommit , "refs/heads/branch1" ) ;
@ -1498,11 +1504,12 @@ public class MergeCommandTest extends RepositoryTestCase {
assertEquals ( MergeStatus . MERGED , result . getMergeStatus ( ) ) ;
assertEquals ( MergeStatus . MERGED , result . getMergeStatus ( ) ) ;
}
}
}
@Test
@Test
public void testNoFastForwardNoCommit ( ) throws Exception {
public void testNoFastForwardNoCommit ( ) throws Exception {
// given
// given
Git git = new Git ( db ) ;
try ( Git git = new Git ( db ) ) {
RevCommit initialCommit = git . commit ( ) . setMessage ( "initial commit" )
RevCommit initialCommit = git . commit ( ) . setMessage ( "initial commit" )
. call ( ) ;
. call ( ) ;
createBranch ( initialCommit , "refs/heads/branch1" ) ;
createBranch ( initialCommit , "refs/heads/branch1" ) ;
@ -1525,10 +1532,11 @@ public class MergeCommandTest extends RepositoryTestCase {
assertNull ( result . getNewHead ( ) ) ;
assertNull ( result . getNewHead ( ) ) ;
assertEquals ( RepositoryState . MERGING_RESOLVED , db . getRepositoryState ( ) ) ;
assertEquals ( RepositoryState . MERGING_RESOLVED , db . getRepositoryState ( ) ) ;
}
}
}
@Test
@Test
public void testFastForwardOnlyNotPossible ( ) throws Exception {
public void testFastForwardOnlyNotPossible ( ) throws Exception {
Git git = new Git ( db ) ;
try ( Git git = new Git ( db ) ) {
RevCommit initialCommit = git . commit ( ) . setMessage ( "initial commit" )
RevCommit initialCommit = git . commit ( ) . setMessage ( "initial commit" )
. call ( ) ;
. call ( ) ;
createBranch ( initialCommit , "refs/heads/branch1" ) ;
createBranch ( initialCommit , "refs/heads/branch1" ) ;
@ -1544,6 +1552,7 @@ public class MergeCommandTest extends RepositoryTestCase {
assertEquals ( MergeStatus . ABORTED , result . getMergeStatus ( ) ) ;
assertEquals ( MergeStatus . ABORTED , result . getMergeStatus ( ) ) ;
}
}
}
@Test
@Test
public void testRecursiveMergeWithConflict ( ) throws Exception {
public void testRecursiveMergeWithConflict ( ) throws Exception {
@ -1577,8 +1586,7 @@ public class MergeCommandTest extends RepositoryTestCase {
@Test
@Test
public void testMergeWithMessageOption ( ) throws Exception {
public void testMergeWithMessageOption ( ) throws Exception {
Git git = new Git ( db ) ;
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 ( ) ;
@ -1607,11 +1615,11 @@ public class MergeCommandTest extends RepositoryTestCase {
RevCommit newHead = it . next ( ) ;
RevCommit newHead = it . next ( ) ;
assertEquals ( "user message" , newHead . getFullMessage ( ) ) ;
assertEquals ( "user message" , newHead . getFullMessage ( ) ) ;
}
}
}
@Test
@Test
public void testMergeConflictWithMessageOption ( ) throws Exception {
public void testMergeConflictWithMessageOption ( ) throws Exception {
Git git = new Git ( db ) ;
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 ( ) ;
@ -1637,6 +1645,7 @@ public class MergeCommandTest extends RepositoryTestCase {
assertEquals ( "user message\n\nConflicts:\n\ta\n" ,
assertEquals ( "user message\n\nConflicts:\n\ta\n" ,
db . readMergeCommitMsg ( ) ) ;
db . readMergeCommitMsg ( ) ) ;
}
}
}
private static void setExecutable ( Git git , String path , boolean executable ) {
private static void setExecutable ( Git git , String path , boolean executable ) {
FS . DETECTED . setExecute (
FS . DETECTED . setExecute (