| 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='git p4 metadata encoding |
| 4 | |
| 5 | This test checks that the import process handles inconsistent text |
| 6 | encoding in p4 metadata (author names, commit messages, etc) without |
| 7 | failing, and produces maximally sane output in git.' |
| 8 | |
| 9 | . ./lib-git-p4.sh |
| 10 | |
| 11 | ############################### |
| 12 | ## SECTION REPEATED IN t9835 ## |
| 13 | ############################### |
| 14 | |
| 15 | EXTRA_PATH="$(pwd)/temp_python" |
| 16 | mkdir "$EXTRA_PATH" |
| 17 | PATH="$EXTRA_PATH:$PATH" |
| 18 | export PATH |
| 19 | |
| 20 | # These tests are specific to Python 3. Write a custom script that executes |
| 21 | # git-p4 directly with the Python 3 interpreter to ensure that we use that |
| 22 | # version even if Git was compiled with Python 2. |
| 23 | test_lazy_prereq P4_PYTHON3 ' |
| 24 | python_target_binary=$(which python3) && |
| 25 | test -n "$python_target_binary" && |
| 26 | write_script "$EXTRA_PATH"/git-p4-python3 <<-EOF && |
| 27 | exec "$python_target_binary" "$(git --exec-path)/git-p4" "\$@" |
| 28 | EOF |
| 29 | ( git p4-python3 || true ) >err && |
| 30 | test_grep "valid commands" err |
| 31 | ' |
| 32 | |
| 33 | if ! test_have_prereq P4_PYTHON3 |
| 34 | then |
| 35 | skip_all="skipping python3 git p4 tests; python3 not available" |
| 36 | test_done |
| 37 | fi |
| 38 | |
| 39 | remove_user_cache () { |
| 40 | rm "$HOME/.gitp4-usercache.txt" || true |
| 41 | } |
| 42 | |
| 43 | test_expect_success 'start p4d' ' |
| 44 | start_p4d |
| 45 | ' |
| 46 | |
| 47 | test_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 | |
| 83 | test_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-python3 clone --dest="$git" //depot@all 2>err && |
| 87 | test_grep "Decoding perforce metadata failed!" err |
| 88 | ' |
| 89 | |
| 90 | test_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-python3 clone --dest="$git" //depot@all && |
| 94 | ( |
| 95 | cd "$git" && |
| 96 | git log >actual && |
| 97 | test_grep "some utf-8 tǣxt" actual && |
| 98 | test_grep "ǣuthor" actual |
| 99 | ) |
| 100 | ' |
| 101 | |
| 102 | test_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-python3 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 | test_grep "$badly_encoded_in_git" actual && |
| 111 | bad_author_in_git="$(echo æuthor | iconv -f utf8 -t latin1)" && |
| 112 | test_grep "$bad_author_in_git" actual |
| 113 | ) |
| 114 | ' |
| 115 | |
| 116 | test_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-python3 clone --dest="$git" //depot@all && |
| 120 | ( |
| 121 | cd "$git" && |
| 122 | git log >actual && |
| 123 | test_grep "some utf-8 tǣxt" actual && |
| 124 | test_grep "ǣuthor" actual |
| 125 | ) |
| 126 | ' |
| 127 | |
| 128 | test_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-python3 clone --dest="$git" //depot@all && |
| 132 | ( |
| 133 | cd "$git" && |
| 134 | git log >actual && |
| 135 | test_grep "some latin-1 tæxt" actual && |
| 136 | test_grep "æuthor" actual |
| 137 | ) |
| 138 | ' |
| 139 | |
| 140 | test_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-python3 clone --dest="$git" //depot@all && |
| 144 | ( |
| 145 | cd "$git" && |
| 146 | git log >actual && |
| 147 | test_grep "sœme cp-1252 tæxt" actual && |
| 148 | test_grep "æuthœr" actual |
| 149 | ) |
| 150 | ' |
| 151 | |
| 152 | test_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-python3 clone --dest="$git" //depot@all && |
| 156 | ( |
| 157 | cd "$git" && |
| 158 | git log >actual && |
| 159 | test_grep "hÅs some cp850 text" actual && |
| 160 | test_grep "Åuthor" actual |
| 161 | ) |
| 162 | ' |
| 163 | |
| 164 | test_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-python3 clone --dest="$git" //depot@all && |
| 168 | ( |
| 169 | cd "$git" && |
| 170 | git log >actual && |
| 171 | test_grep "h%8Fs some cp850 text" actual && |
| 172 | test_grep "%8Futhor" actual |
| 173 | ) |
| 174 | ' |
| 175 | |
| 176 | test_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-python3 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-python3 sync --branch=master && |
| 192 | |
| 193 | git log p4/master >actual && |
| 194 | test_grep "sœme more cp-1252 tæxt" actual && |
| 195 | test_grep "æuthœr" actual |
| 196 | ) |
| 197 | ' |
| 198 | |
| 199 | ############################ |
| 200 | ## / END REPEATED SECTION ## |
| 201 | ############################ |
| 202 | |
| 203 | |
| 204 | test_expect_success 'fallback (both utf-8 and cp-1252 contents handled) is the default with python3' ' |
| 205 | test_when_finished cleanup_git && |
| 206 | test_when_finished remove_user_cache && |
| 207 | git p4-python3 clone --dest="$git" //depot@all && |
| 208 | ( |
| 209 | cd "$git" && |
| 210 | git log >actual && |
| 211 | test_grep "sœme cp-1252 tæxt" actual && |
| 212 | test_grep "æuthœr" actual |
| 213 | ) |
| 214 | ' |
| 215 | |
| 216 | test_done |