@ -16,6 +16,7 @@ import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame ;
import static org.junit.Assert.assertSame ;
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.Date ;
import java.util.Date ;
@ -600,40 +601,63 @@ public class CommitCommandTest extends RepositoryTestCase {
}
}
}
}
@Test
private void nonNormalizedIndexTest ( boolean executable ) throws Exception {
public void commitWithAutoCrlfAndNonNormalizedIndex ( ) throws Exception {
String mode = executable ? "100755" : "100644" ;
try ( Git git = new Git ( db ) ) {
try ( Git git = new Git ( db ) ) {
// Commit a file with CR/LF into the index
// Commit a file with CR/LF into the index
FileBasedConfig config = db . getConfig ( ) ;
FileBasedConfig config = db . getConfig ( ) ;
config . setString ( "core" , null , "autocrlf" , "false" ) ;
config . setString ( "core" , null , "autocrlf" , "false" ) ;
config . save ( ) ;
config . save ( ) ;
writeTrashFile ( "file.txt" , "line 1\r\nline 2\r\n" ) ;
File testFile = writeTrashFile ( "file.txt" , "line 1\r\nline 2\r\n" ) ;
if ( executable ) {
FS . DETECTED . setExecute ( testFile , true ) ;
}
git . add ( ) . addFilepattern ( "file.txt" ) . call ( ) ;
git . add ( ) . addFilepattern ( "file.txt" ) . call ( ) ;
git . commit ( ) . setMessage ( "Initial" ) . call ( ) ;
git . commit ( ) . setMessage ( "Initial" ) . call ( ) ;
assertEquals (
assertEquals (
"[file.txt, mode:100644, content:line 1\r\nline 2\r\n]" ,
"[file.txt, mode:" + mode
+ ", content:line 1\r\nline 2\r\n]" ,
indexState ( CONTENT ) ) ;
indexState ( CONTENT ) ) ;
config . setString ( "core" , null , "autocrlf" , "true" ) ;
config . setString ( "core" , null , "autocrlf" , "true" ) ;
config . save ( ) ;
config . save ( ) ;
writeTrashFile ( "file.txt" , "line 1\r\nline 1.5\r\nline 2\r\n" ) ;
writeTrashFile ( "file.txt" , "line 1\r\nline 1.5\r\nline 2\r\n" ) ;
writeTrashFile ( "file2.txt" , "new\r\nfile\r\n" ) ;
testFile = writeTrashFile ( "file2.txt" , "new\r\nfile\r\n" ) ;
if ( executable ) {
FS . DETECTED . setExecute ( testFile , true ) ;
}
git . add ( ) . addFilepattern ( "file.txt" ) . addFilepattern ( "file2.txt" )
git . add ( ) . addFilepattern ( "file.txt" ) . addFilepattern ( "file2.txt" )
. call ( ) ;
. call ( ) ;
git . commit ( ) . setMessage ( "Second" ) . call ( ) ;
git . commit ( ) . setMessage ( "Second" ) . call ( ) ;
assertEquals (
assertEquals (
"[file.txt, mode:100644, content:line 1\r\nline 1.5\r\nline 2\r\n]"
"[file.txt, mode:" + mode
+ "[file2.txt, mode:100644, content:new\nfile\n]" ,
+ ", content:line 1\r\nline 1.5\r\nline 2\r\n]"
+ "[file2.txt, mode:" + mode
+ ", content:new\nfile\n]" ,
indexState ( CONTENT ) ) ;
indexState ( CONTENT ) ) ;
writeTrashFile ( "file2.txt" , "new\r\nfile\r\ncontent\r\n" ) ;
writeTrashFile ( "file2.txt" , "new\r\nfile\r\ncontent\r\n" ) ;
git . add ( ) . addFilepattern ( "file2.txt" ) . call ( ) ;
git . add ( ) . addFilepattern ( "file2.txt" ) . call ( ) ;
git . commit ( ) . setMessage ( "Third" ) . call ( ) ;
git . commit ( ) . setMessage ( "Third" ) . call ( ) ;
assertEquals (
assertEquals (
"[file.txt, mode:100644, content:line 1\r\nline 1.5\r\nline 2\r\n]"
"[file.txt, mode:" + mode
+ "[file2.txt, mode:100644, content:new\nfile\ncontent\n]" ,
+ ", content:line 1\r\nline 1.5\r\nline 2\r\n]"
+ "[file2.txt, mode:" + mode
+ ", content:new\nfile\ncontent\n]" ,
indexState ( CONTENT ) ) ;
indexState ( CONTENT ) ) ;
}
}
}
}
@Test
public void commitWithAutoCrlfAndNonNormalizedIndex ( ) throws Exception {
nonNormalizedIndexTest ( false ) ;
}
@Test
public void commitExecutableWithAutoCrlfAndNonNormalizedIndex ( )
throws Exception {
assumeTrue ( FS . DETECTED . supportsExecute ( ) ) ;
nonNormalizedIndexTest ( true ) ;
}
@Test
@Test
public void testDeletionConflictWithAutoCrlf ( ) throws Exception {
public void testDeletionConflictWithAutoCrlf ( ) throws Exception {
try ( Git git = new Git ( db ) ) {
try ( Git git = new Git ( db ) ) {