3 test_description
='git p4 metadata encoding
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.'
9 TEST_PASSES_SANITIZE_LEAK
=true
12 python_target_version
='2'
14 ###############################
15 ## SECTION REPEATED IN t9836 ##
16 ###############################
18 # Please note: this test calls "git-p4.py" rather than "git-p4", because the
19 # latter references a specific path so we can't easily force it to run under
20 # the python version we need to.
22 python_major_version
=$
(python
-V 2>&1 | cut
-c 8)
23 python_target_binary
=$
(which python
$python_target_version)
24 if ! test "$python_major_version" = "$python_target_version" && test "$python_target_binary"
27 PATH
="$(pwd)/temp_python:$PATH" && export PATH
28 ln -s $python_target_binary temp_python
/python
31 python_major_version
=$
(python
-V 2>&1 | cut
-c 8)
32 if ! test "$python_major_version" = "$python_target_version"
34 skip_all
="skipping python$python_target_version-specific git p4 tests; python$python_target_version not available"
38 remove_user_cache
() {
39 rm "$HOME/.gitp4-usercache.txt" || true
42 test_expect_success
'start p4d' '
46 test_expect_success
'init depot' '
50 p4_add_user "utf8_author" "ǣuthor" &&
54 p4 submit -d "first CL has some utf-8 tǣxt" &&
56 p4_add_user "latin1_author" "$(echo æuthor |
57 iconv -f utf8 -t latin1)" &&
58 P4USER=latin1_author &&
61 p4 submit -d "$(echo second CL has some latin-1 tæxt |
62 iconv -f utf8 -t latin1)" &&
64 p4_add_user "cp1252_author" "$(echo æuthœr |
65 iconv -f utf8 -t cp1252)" &&
66 P4USER=cp1252_author &&
69 p4 submit -d "$(echo third CL has sœme cp-1252 tæxt |
70 iconv -f utf8 -t cp1252)" &&
72 p4_add_user "cp850_author" "$(echo Åuthor |
73 iconv -f utf8 -t cp850)" &&
74 P4USER=cp850_author &&
77 p4 submit -d "$(echo fourth CL hÅs some cp850 text |
78 iconv -f utf8 -t cp850)"
82 test_expect_success
'clone non-utf8 repo with strict encoding' '
83 test_when_finished cleanup_git &&
84 test_when_finished remove_user_cache &&
85 test_must_fail git -c git-p4.metadataDecodingStrategy=strict p4.py clone --dest="$git" //depot@all 2>err &&
86 grep "Decoding perforce metadata failed!" err
89 test_expect_success
'check utf-8 contents with passthrough strategy' '
90 test_when_finished cleanup_git &&
91 test_when_finished remove_user_cache &&
92 git -c git-p4.metadataDecodingStrategy=passthrough p4.py clone --dest="$git" //depot@all &&
96 grep "some utf-8 tǣxt" actual &&
101 test_expect_success
'check latin-1 contents corrupted in git with passthrough strategy' '
102 test_when_finished cleanup_git &&
103 test_when_finished remove_user_cache &&
104 git -c git-p4.metadataDecodingStrategy=passthrough p4.py clone --dest="$git" //depot@all &&
108 badly_encoded_in_git=$(echo "some latin-1 tæxt" | iconv -f utf8 -t latin1) &&
109 grep "$badly_encoded_in_git" actual &&
110 bad_author_in_git="$(echo æuthor | iconv -f utf8 -t latin1)" &&
111 grep "$bad_author_in_git" actual
115 test_expect_success
'check utf-8 contents with fallback strategy' '
116 test_when_finished cleanup_git &&
117 test_when_finished remove_user_cache &&
118 git -c git-p4.metadataDecodingStrategy=fallback p4.py clone --dest="$git" //depot@all &&
122 grep "some utf-8 tǣxt" actual &&
127 test_expect_success
'check latin-1 contents with fallback strategy' '
128 test_when_finished cleanup_git &&
129 test_when_finished remove_user_cache &&
130 git -c git-p4.metadataDecodingStrategy=fallback p4.py clone --dest="$git" //depot@all &&
134 grep "some latin-1 tæxt" actual &&
139 test_expect_success
'check cp-1252 contents with fallback strategy' '
140 test_when_finished cleanup_git &&
141 test_when_finished remove_user_cache &&
142 git -c git-p4.metadataDecodingStrategy=fallback p4.py clone --dest="$git" //depot@all &&
146 grep "sœme cp-1252 tæxt" actual &&
151 test_expect_success
'check cp850 contents parsed with correct fallback' '
152 test_when_finished cleanup_git &&
153 test_when_finished remove_user_cache &&
154 git -c git-p4.metadataDecodingStrategy=fallback -c git-p4.metadataFallbackEncoding=cp850 p4.py clone --dest="$git" //depot@all &&
158 grep "hÅs some cp850 text" actual &&
163 test_expect_success
'check cp850-only contents escaped when cp1252 is fallback' '
164 test_when_finished cleanup_git &&
165 test_when_finished remove_user_cache &&
166 git -c git-p4.metadataDecodingStrategy=fallback p4.py clone --dest="$git" //depot@all &&
170 grep "h%8Fs some cp850 text" actual &&
171 grep "%8Futhor" actual
175 test_expect_success
'check cp-1252 contents on later sync after clone with fallback strategy' '
176 test_when_finished cleanup_git &&
177 test_when_finished remove_user_cache &&
178 git -c git-p4.metadataDecodingStrategy=fallback p4.py clone --dest="$git" //depot@all &&
181 P4USER=cp1252_author &&
184 p4 submit -d "$(echo later CL has sœme more cp-1252 tæxt |
185 iconv -f utf8 -t cp1252)"
190 git p4.py sync --branch=master &&
192 git log p4/master >actual &&
193 grep "sœme more cp-1252 tæxt" actual &&
198 ############################
199 ## / END REPEATED SECTION ##
200 ############################
202 test_expect_success
'passthrough (latin-1 contents corrupted in git) is the default with python2' '
203 test_when_finished cleanup_git &&
204 test_when_finished remove_user_cache &&
205 git -c git-p4.metadataDecodingStrategy=passthrough p4.py clone --dest="$git" //depot@all &&
209 badly_encoded_in_git=$(echo "some latin-1 tæxt" | iconv -f utf8 -t latin1) &&
210 grep "$badly_encoded_in_git" actual