@ -51,6 +51,7 @@ import static org.junit.Assert.fail;
import org.eclipse.jgit.lib.Constants ;
import org.eclipse.jgit.lib.FileMode ;
import org.eclipse.jgit.lib.ObjectId ;
import org.junit.Test ;
public class DirCacheEntryTest {
@ -164,4 +165,53 @@ public class DirCacheEntryTest {
assertEquals ( "Invalid mode 40000 for path a" , err . getMessage ( ) ) ;
}
}
@Test
public void testCopyMetaDataWithStage ( ) {
copyMetaDataHelper ( false ) ;
}
@Test
public void testCopyMetaDataWithoutStage ( ) {
copyMetaDataHelper ( true ) ;
}
private void copyMetaDataHelper ( final boolean keepStage ) {
DirCacheEntry e = new DirCacheEntry ( "some/path" , DirCacheEntry . STAGE_2 ) ;
e . setAssumeValid ( false ) ;
e . setCreationTime ( 2L ) ;
e . setFileMode ( FileMode . EXECUTABLE_FILE ) ;
e . setLastModified ( 3L ) ;
e . setLength ( 100L ) ;
e . setObjectId ( ObjectId
. fromString ( "0123456789012345678901234567890123456789" ) ) ;
e . setUpdateNeeded ( true ) ;
DirCacheEntry f = new DirCacheEntry ( "someother/path" ,
DirCacheEntry . STAGE_1 ) ;
f . setAssumeValid ( true ) ;
f . setCreationTime ( 10L ) ;
f . setFileMode ( FileMode . SYMLINK ) ;
f . setLastModified ( 20L ) ;
f . setLength ( 100000000L ) ;
f . setObjectId ( ObjectId
. fromString ( "1234567890123456789012345678901234567890" ) ) ;
f . setUpdateNeeded ( true ) ;
e . copyMetaData ( f , keepStage ) ;
assertTrue ( e . isAssumeValid ( ) ) ;
assertEquals ( 10L , e . getCreationTime ( ) ) ;
assertEquals (
ObjectId . fromString ( "1234567890123456789012345678901234567890" ) ,
e . getObjectId ( ) ) ;
assertEquals ( FileMode . SYMLINK , e . getFileMode ( ) ) ;
assertEquals ( 20L , e . getLastModified ( ) ) ;
assertEquals ( 100000000L , e . getLength ( ) ) ;
if ( keepStage )
assertEquals ( DirCacheEntry . STAGE_2 , e . getStage ( ) ) ;
else
assertEquals ( DirCacheEntry . STAGE_1 , e . getStage ( ) ) ;
assertTrue ( e . isUpdateNeeded ( ) ) ;
assertEquals ( "some/path" , e . getPathString ( ) ) ;
}
}