Git fork
at reftables-rust 215 lines 6.2 kB view raw
1#!/bin/sh 2 3test_description='git p4 metadata encoding 4 5This test checks that the import process handles inconsistent text 6encoding in p4 metadata (author names, commit messages, etc) without 7failing, and produces maximally sane output in git.' 8 9. ./lib-git-p4.sh 10 11############################### 12## SECTION REPEATED IN t9836 ## 13############################### 14 15EXTRA_PATH="$(pwd)/temp_python" 16mkdir "$EXTRA_PATH" 17PATH="$EXTRA_PATH:$PATH" 18export PATH 19 20# These tests are specific to Python 2. Write a custom script that executes 21# git-p4 directly with the Python 2 interpreter to ensure that we use that 22# version even if Git was compiled with Python 3. 23test_lazy_prereq P4_PYTHON2 ' 24 python_target_binary=$(which python2) && 25 test -n "$python_target_binary" && 26 write_script "$EXTRA_PATH"/git-p4-python2 <<-EOF && 27 exec "$python_target_binary" "$(git --exec-path)/git-p4" "\$@" 28 EOF 29 ( git p4-python2 || true ) >err && 30 test_grep "valid commands" err 31' 32 33if ! test_have_prereq P4_PYTHON2 34then 35 skip_all="skipping python2 git p4 tests; python2 not available" 36 test_done 37fi 38 39remove_user_cache () { 40 rm "$HOME/.gitp4-usercache.txt" || true 41} 42 43test_expect_success 'start p4d' ' 44 start_p4d 45' 46 47test_expect_success 'init depot' ' 48 ( 49 cd "$cli" && 50 51 p4_add_user "utf8_author" "ǣuthor" && 52 P4USER=utf8_author && 53 touch file1 && 54 p4 add file1 && 55 p4 submit -d "first CL has some utf-8 tǣxt" && 56 57 p4_add_user "latin1_author" "$(echo æuthor | 58 iconv -f utf8 -t latin1)" && 59 P4USER=latin1_author && 60 touch file2 && 61 p4 add file2 && 62 p4 submit -d "$(echo second CL has some latin-1 tæxt | 63 iconv -f utf8 -t latin1)" && 64 65 p4_add_user "cp1252_author" "$(echo æuthœr | 66 iconv -f utf8 -t cp1252)" && 67 P4USER=cp1252_author && 68 touch file3 && 69 p4 add file3 && 70 p4 submit -d "$(echo third CL has sœme cp-1252 tæxt | 71 iconv -f utf8 -t cp1252)" && 72 73 p4_add_user "cp850_author" "$(echo Åuthor | 74 iconv -f utf8 -t cp850)" && 75 P4USER=cp850_author && 76 touch file4 && 77 p4 add file4 && 78 p4 submit -d "$(echo fourth CL hÅs some cp850 text | 79 iconv -f utf8 -t cp850)" 80 ) 81' 82 83test_expect_success 'clone non-utf8 repo with strict encoding' ' 84 test_when_finished cleanup_git && 85 test_when_finished remove_user_cache && 86 test_must_fail git -c git-p4.metadataDecodingStrategy=strict p4-python2 clone --dest="$git" //depot@all 2>err && 87 grep "Decoding perforce metadata failed!" err 88' 89 90test_expect_success 'check utf-8 contents with passthrough strategy' ' 91 test_when_finished cleanup_git && 92 test_when_finished remove_user_cache && 93 git -c git-p4.metadataDecodingStrategy=passthrough p4-python2 clone --dest="$git" //depot@all && 94 ( 95 cd "$git" && 96 git log >actual && 97 grep "some utf-8 tǣxt" actual && 98 grep "ǣuthor" actual 99 ) 100' 101 102test_expect_success 'check latin-1 contents corrupted in git with passthrough strategy' ' 103 test_when_finished cleanup_git && 104 test_when_finished remove_user_cache && 105 git -c git-p4.metadataDecodingStrategy=passthrough p4-python2 clone --dest="$git" //depot@all && 106 ( 107 cd "$git" && 108 git log >actual && 109 badly_encoded_in_git=$(echo "some latin-1 tæxt" | iconv -f utf8 -t latin1) && 110 grep "$badly_encoded_in_git" actual && 111 bad_author_in_git="$(echo æuthor | iconv -f utf8 -t latin1)" && 112 grep "$bad_author_in_git" actual 113 ) 114' 115 116test_expect_success 'check utf-8 contents with fallback strategy' ' 117 test_when_finished cleanup_git && 118 test_when_finished remove_user_cache && 119 git -c git-p4.metadataDecodingStrategy=fallback p4-python2 clone --dest="$git" //depot@all && 120 ( 121 cd "$git" && 122 git log >actual && 123 grep "some utf-8 tǣxt" actual && 124 grep "ǣuthor" actual 125 ) 126' 127 128test_expect_success 'check latin-1 contents with fallback strategy' ' 129 test_when_finished cleanup_git && 130 test_when_finished remove_user_cache && 131 git -c git-p4.metadataDecodingStrategy=fallback p4-python2 clone --dest="$git" //depot@all && 132 ( 133 cd "$git" && 134 git log >actual && 135 grep "some latin-1 tæxt" actual && 136 grep "æuthor" actual 137 ) 138' 139 140test_expect_success 'check cp-1252 contents with fallback strategy' ' 141 test_when_finished cleanup_git && 142 test_when_finished remove_user_cache && 143 git -c git-p4.metadataDecodingStrategy=fallback p4-python2 clone --dest="$git" //depot@all && 144 ( 145 cd "$git" && 146 git log >actual && 147 grep "sœme cp-1252 tæxt" actual && 148 grep "æuthœr" actual 149 ) 150' 151 152test_expect_success 'check cp850 contents parsed with correct fallback' ' 153 test_when_finished cleanup_git && 154 test_when_finished remove_user_cache && 155 git -c git-p4.metadataDecodingStrategy=fallback -c git-p4.metadataFallbackEncoding=cp850 p4-python2 clone --dest="$git" //depot@all && 156 ( 157 cd "$git" && 158 git log >actual && 159 grep "hÅs some cp850 text" actual && 160 grep "Åuthor" actual 161 ) 162' 163 164test_expect_success 'check cp850-only contents escaped when cp1252 is fallback' ' 165 test_when_finished cleanup_git && 166 test_when_finished remove_user_cache && 167 git -c git-p4.metadataDecodingStrategy=fallback p4-python2 clone --dest="$git" //depot@all && 168 ( 169 cd "$git" && 170 git log >actual && 171 grep "h%8Fs some cp850 text" actual && 172 grep "%8Futhor" actual 173 ) 174' 175 176test_expect_success 'check cp-1252 contents on later sync after clone with fallback strategy' ' 177 test_when_finished cleanup_git && 178 test_when_finished remove_user_cache && 179 git -c git-p4.metadataDecodingStrategy=fallback p4-python2 clone --dest="$git" //depot@all && 180 ( 181 cd "$cli" && 182 P4USER=cp1252_author && 183 touch file10 && 184 p4 add file10 && 185 p4 submit -d "$(echo later CL has sœme more cp-1252 tæxt | 186 iconv -f utf8 -t cp1252)" 187 ) && 188 ( 189 cd "$git" && 190 191 git p4-python2 sync --branch=master && 192 193 git log p4/master >actual && 194 grep "sœme more cp-1252 tæxt" actual && 195 grep "æuthœr" actual 196 ) 197' 198 199############################ 200## / END REPEATED SECTION ## 201############################ 202 203test_expect_success 'passthrough (latin-1 contents corrupted in git) is the default with python2' ' 204 test_when_finished cleanup_git && 205 test_when_finished remove_user_cache && 206 git -c git-p4.metadataDecodingStrategy=passthrough p4-python2 clone --dest="$git" //depot@all && 207 ( 208 cd "$git" && 209 git log >actual && 210 badly_encoded_in_git=$(echo "some latin-1 tæxt" | iconv -f utf8 -t latin1) && 211 grep "$badly_encoded_in_git" actual 212 ) 213' 214 215test_done