The eleventh batch
[alt-git.git] / t / t9835-git-p4-metadata-encoding-python2.sh
blobad20ffdededdc9bc3099818a7ad5747b0470c864
1 #!/bin/sh
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
10 . ./lib-git-p4.sh
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"
25 then
26 mkdir temp_python
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"
33 then
34 skip_all="skipping python$python_target_version-specific git p4 tests; python$python_target_version not available"
35 test_done
38 remove_user_cache () {
39 rm "$HOME/.gitp4-usercache.txt" || true
42 test_expect_success 'start p4d' '
43 start_p4d
46 test_expect_success 'init depot' '
48 cd "$cli" &&
50 p4_add_user "utf8_author" "ǣuthor" &&
51 P4USER=utf8_author &&
52 touch file1 &&
53 p4 add file1 &&
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 &&
59 touch file2 &&
60 p4 add file2 &&
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 &&
67 touch file3 &&
68 p4 add file3 &&
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 &&
75 touch file4 &&
76 p4 add file4 &&
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 &&
94 cd "$git" &&
95 git log >actual &&
96 grep "some utf-8 tǣxt" actual &&
97 grep "ǣuthor" 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 &&
106 cd "$git" &&
107 git log >actual &&
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 &&
120 cd "$git" &&
121 git log >actual &&
122 grep "some utf-8 tǣxt" actual &&
123 grep "ǣuthor" 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 &&
132 cd "$git" &&
133 git log >actual &&
134 grep "some latin-1 tæxt" actual &&
135 grep "æuthor" 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 &&
144 cd "$git" &&
145 git log >actual &&
146 grep "sœme cp-1252 tæxt" actual &&
147 grep "æuthœr" 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 &&
156 cd "$git" &&
157 git log >actual &&
158 grep "hÅs some cp850 text" actual &&
159 grep "Åuthor" 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 &&
168 cd "$git" &&
169 git log >actual &&
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 &&
180 cd "$cli" &&
181 P4USER=cp1252_author &&
182 touch file10 &&
183 p4 add file10 &&
184 p4 submit -d "$(echo later CL has sœme more cp-1252 tæxt |
185 iconv -f utf8 -t cp1252)"
186 ) &&
188 cd "$git" &&
190 git p4.py sync --branch=master &&
192 git log p4/master >actual &&
193 grep "sœme more cp-1252 tæxt" actual &&
194 grep "æuthœr" 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 &&
207 cd "$git" &&
208 git log >actual &&
209 badly_encoded_in_git=$(echo "some latin-1 tæxt" | iconv -f utf8 -t latin1) &&
210 grep "$badly_encoded_in_git" actual
214 test_done