@@ -974,34 +974,73 @@ cat_github_output() {
974974 assert_line --partial " another-subdirectory/new-file-3.txt"
975975}
976976
977- @test " fails to detect crlf change in files and does not detect change or commit changes " {
977+ @test " detects if crlf in files change and does not create commit" {
978978 # Set autocrlf to true
979979 cd " ${FAKE_LOCAL_REPOSITORY} "
980980 git config core.autocrlf true
981981 run git config --get-all core.autocrlf
982982 assert_line " true"
983983
984984 # Add more .txt files
985- touch " ${FAKE_LOCAL_REPOSITORY} " /new-file-2.txt
986- touch " ${FAKE_LOCAL_REPOSITORY} " /new-file-3.txt
985+ echo -ne " crlf test1\r\n " > " ${FAKE_LOCAL_REPOSITORY} " /new-file-2.txt
986+ echo -ne " crlf test1\n " > " ${FAKE_LOCAL_REPOSITORY} " /new-file-3.txt
987987
988988 # Run git-auto-commit to add new files to repository
989989 run git_auto_commit
990990
991991 # Change control characters in files
992- sed ' s/^M$// ' " ${FAKE_LOCAL_REPOSITORY} " /new-file-2.txt
993- sed ' s/$/^M/ ' " ${FAKE_LOCAL_REPOSITORY} " /new-file-3.txt
992+ echo -ne " crlf test1\n " > " ${FAKE_LOCAL_REPOSITORY} " /new-file-2.txt
993+ echo -ne " crlf test1\r\n " > " ${FAKE_LOCAL_REPOSITORY} " /new-file-3.txt
994994
995995 # Run git-auto-commit to commit the 2 changes files
996996 run git_auto_commit
997997
998998 assert_success
999999
1000- # Changes are not detected
1000+ refute_line --partial " 2 files changed, 2 insertions(+), 2 deletions(-)"
1001+ assert_line --partial " warning: in the working copy of 'new-file-2.txt', LF will be replaced by CRLF the next time Git touches it"
1002+
10011003 assert_line --partial " Working tree clean. Nothing to commit."
1004+ assert_line --partial " new-file-2.txt"
1005+ assert_line --partial " new-file-3.txt"
1006+
1007+ # Changes are not detected
1008+ run cat_github_output
1009+ assert_line " changes_detected=false"
1010+ }
1011+
1012+ @test " detects if crlf in files change and creates commit if the actual content of the files change" {
1013+ # Set autocrlf to true
1014+ cd " ${FAKE_LOCAL_REPOSITORY} "
1015+ git config core.autocrlf true
1016+ run git config --get-all core.autocrlf
1017+ assert_line " true"
1018+
1019+ # Add more .txt files
1020+ echo -ne " crlf test1\r\n" > " ${FAKE_LOCAL_REPOSITORY} " /new-file-2.txt
1021+ echo -ne " crlf test1\n" > " ${FAKE_LOCAL_REPOSITORY} " /new-file-3.txt
10021022
1003- refute_line --partial " new-file-2.txt"
1004- refute_line --partial " new-file-3.txt"
1023+ # Run git-auto-commit to add new files to repository
1024+ run git_auto_commit
1025+
1026+ # Change control characters in files
1027+ echo -ne " crlf test2\n" > " ${FAKE_LOCAL_REPOSITORY} " /new-file-2.txt
1028+ echo -ne " crlf test2\r\n" > " ${FAKE_LOCAL_REPOSITORY} " /new-file-3.txt
1029+
1030+ # Run git-auto-commit to commit the 2 changes files
1031+ run git_auto_commit
1032+
1033+ assert_success
1034+
1035+ assert_line --partial " 2 files changed, 2 insertions(+), 2 deletions(-)"
1036+ assert_line --partial " warning: in the working copy of 'new-file-2.txt', LF will be replaced by CRLF the next time Git touches it"
1037+
1038+ assert_line --partial " new-file-2.txt"
1039+ assert_line --partial " new-file-3.txt"
1040+
1041+ # Changes are detected
1042+ run cat_github_output
1043+ assert_line " changes_detected=true"
10051044}
10061045
10071046
0 commit comments