Git 2.45
[git/gitster.git] / t / t9836-git-p4-metadata-encoding-python3.sh
blob63350dc4b5c6262480cd0be8fd88fba714c55428
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 . ./lib-git-p4.sh
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"
24 then
25 mkdir temp_python
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"
32 then
33 skip_all="skipping python$python_target_version-specific git p4 tests; python$python_target_version not available"
34 test_done
37 remove_user_cache () {
38 rm "$HOME/.gitp4-usercache.txt" || true
41 test_expect_success 'start p4d' '
42 start_p4d
45 test_expect_success 'init depot' '
47 cd "$cli" &&
49 p4_add_user "utf8_author" "ǣuthor" &&
50 P4USER=utf8_author &&
51 touch file1 &&
52 p4 add file1 &&
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 &&
58 touch file2 &&
59 p4 add file2 &&
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 &&
66 touch file3 &&
67 p4 add file3 &&
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 &&
74 touch file4 &&
75 p4 add file4 &&
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 &&
93 cd "$git" &&
94 git log >actual &&
95 grep "some utf-8 tǣxt" actual &&
96 grep "ǣuthor" 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 &&
105 cd "$git" &&
106 git log >actual &&
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 &&
119 cd "$git" &&
120 git log >actual &&
121 grep "some utf-8 tǣxt" actual &&
122 grep "ǣuthor" 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 &&
131 cd "$git" &&
132 git log >actual &&
133 grep "some latin-1 tæxt" actual &&
134 grep "æuthor" 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 &&
143 cd "$git" &&
144 git log >actual &&
145 grep "sœme cp-1252 tæxt" actual &&
146 grep "æuthœr" 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 &&
155 cd "$git" &&
156 git log >actual &&
157 grep "hÅs some cp850 text" actual &&
158 grep "Åuthor" 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 &&
167 cd "$git" &&
168 git log >actual &&
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 &&
179 cd "$cli" &&
180 P4USER=cp1252_author &&
181 touch file10 &&
182 p4 add file10 &&
183 p4 submit -d "$(echo later CL has sœme more cp-1252 tæxt |
184 iconv -f utf8 -t cp1252)"
185 ) &&
187 cd "$git" &&
189 git p4.py sync --branch=master &&
191 git log p4/master >actual &&
192 grep "sœme more cp-1252 tæxt" actual &&
193 grep "æuthœr" 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 &&
207 cd "$git" &&
208 git log >actual &&
209 grep "sœme cp-1252 tæxt" actual &&
210 grep "æuthœr" actual
214 test_done