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.'
11 python_target_version
='3'
13 ###############################
14 ## SECTION REPEATED IN t9835 ##
15 ###############################
17 # Please note: this test calls "git-p4.py" rather than "git-p4", because the
18 # latter references a specific path so we can't easily force it to run under
19 # the python version we need to.
21 python_major_version
=$
(python
-V 2>&1 | cut
-c 8)
22 python_target_binary
=$
(which python
$python_target_version)
23 if ! test "$python_major_version" = "$python_target_version" && test "$python_target_binary"
26 PATH
="$(pwd)/temp_python:$PATH" && export PATH
27 ln -s $python_target_binary temp_python
/python
30 python_major_version
=$
(python
-V 2>&1 | cut
-c 8)
31 if ! test "$python_major_version" = "$python_target_version"
33 skip_all
="skipping python$python_target_version-specific git p4 tests; python$python_target_version not available"
37 remove_user_cache
() {
38 rm "$HOME/.gitp4-usercache.txt" || true
41 test_expect_success
'start p4d' '
45 test_expect_success
'init depot' '
49 p4_add_user "utf8_author" "ǣuthor" &&
53 p4 submit -d "first CL has some utf-8 tǣxt" &&
55 p4_add_user "latin1_author" "$(echo æuthor |
56 iconv -f utf8 -t latin1)" &&
57 P4USER=latin1_author &&
60 p4 submit -d "$(echo second CL has some latin-1 tæxt |
61 iconv -f utf8 -t latin1)" &&
63 p4_add_user "cp1252_author" "$(echo æuthœr |
64 iconv -f utf8 -t cp1252)" &&
65 P4USER=cp1252_author &&
68 p4 submit -d "$(echo third CL has sœme cp-1252 tæxt |
69 iconv -f utf8 -t cp1252)" &&
71 p4_add_user "cp850_author" "$(echo Åuthor |
72 iconv -f utf8 -t cp850)" &&
73 P4USER=cp850_author &&
76 p4 submit -d "$(echo fourth CL hÅs some cp850 text |
77 iconv -f utf8 -t cp850)"
81 test_expect_success
'clone non-utf8 repo with strict encoding' '
82 test_when_finished cleanup_git &&
83 test_when_finished remove_user_cache &&
84 test_must_fail git -c git-p4.metadataDecodingStrategy=strict p4.py clone --dest="$git" //depot@all 2>err &&
85 grep "Decoding perforce metadata failed!" err
88 test_expect_success
'check utf-8 contents with passthrough strategy' '
89 test_when_finished cleanup_git &&
90 test_when_finished remove_user_cache &&
91 git -c git-p4.metadataDecodingStrategy=passthrough p4.py clone --dest="$git" //depot@all &&
95 grep "some utf-8 tǣxt" actual &&
100 test_expect_success
'check latin-1 contents corrupted in git with passthrough strategy' '
101 test_when_finished cleanup_git &&
102 test_when_finished remove_user_cache &&
103 git -c git-p4.metadataDecodingStrategy=passthrough p4.py clone --dest="$git" //depot@all &&
107 badly_encoded_in_git=$(echo "some latin-1 tæxt" | iconv -f utf8 -t latin1) &&
108 grep "$badly_encoded_in_git" actual &&
109 bad_author_in_git="$(echo æuthor | iconv -f utf8 -t latin1)" &&
110 grep "$bad_author_in_git" actual
114 test_expect_success
'check utf-8 contents with fallback strategy' '
115 test_when_finished cleanup_git &&
116 test_when_finished remove_user_cache &&
117 git -c git-p4.metadataDecodingStrategy=fallback p4.py clone --dest="$git" //depot@all &&
121 grep "some utf-8 tǣxt" actual &&
126 test_expect_success
'check latin-1 contents with fallback strategy' '
127 test_when_finished cleanup_git &&
128 test_when_finished remove_user_cache &&
129 git -c git-p4.metadataDecodingStrategy=fallback p4.py clone --dest="$git" //depot@all &&
133 grep "some latin-1 tæxt" actual &&
138 test_expect_success
'check cp-1252 contents with fallback strategy' '
139 test_when_finished cleanup_git &&
140 test_when_finished remove_user_cache &&
141 git -c git-p4.metadataDecodingStrategy=fallback p4.py clone --dest="$git" //depot@all &&
145 grep "sœme cp-1252 tæxt" actual &&
150 test_expect_success
'check cp850 contents parsed with correct fallback' '
151 test_when_finished cleanup_git &&
152 test_when_finished remove_user_cache &&
153 git -c git-p4.metadataDecodingStrategy=fallback -c git-p4.metadataFallbackEncoding=cp850 p4.py clone --dest="$git" //depot@all &&
157 grep "hÅs some cp850 text" actual &&
162 test_expect_success
'check cp850-only contents escaped when cp1252 is fallback' '
163 test_when_finished cleanup_git &&
164 test_when_finished remove_user_cache &&
165 git -c git-p4.metadataDecodingStrategy=fallback p4.py clone --dest="$git" //depot@all &&
169 grep "h%8Fs some cp850 text" actual &&
170 grep "%8Futhor" actual
174 test_expect_success
'check cp-1252 contents on later sync after clone with fallback strategy' '
175 test_when_finished cleanup_git &&
176 test_when_finished remove_user_cache &&
177 git -c git-p4.metadataDecodingStrategy=fallback p4.py clone --dest="$git" //depot@all &&
180 P4USER=cp1252_author &&
183 p4 submit -d "$(echo later CL has sœme more cp-1252 tæxt |
184 iconv -f utf8 -t cp1252)"
189 git p4.py sync --branch=master &&
191 git log p4/master >actual &&
192 grep "sœme more cp-1252 tæxt" actual &&
197 ############################
198 ## / END REPEATED SECTION ##
199 ############################
202 test_expect_success
'fallback (both utf-8 and cp-1252 contents handled) is the default with python3' '
203 test_when_finished cleanup_git &&
204 test_when_finished remove_user_cache &&
205 git p4.py clone --dest="$git" //depot@all &&
209 grep "sœme cp-1252 tæxt" actual &&