3 test_description='test git-p4.fallbackEncoding config'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
10 test_expect_success 'start p4d' '
14 test_expect_success 'add Unicode description' '
18 p4 submit -d documentación
21 # Unicode descriptions cause "git p4 clone" to crash with a UnicodeDecodeError in some
22 # environments. This test determines if that is the case in our environment. If so,
23 # we create a file called "clone_fails". In subsequent tests, we check whether that
24 # file exists to determine what behavior to expect.
26 clone_fails="$TRASH_DIRECTORY/clone_fails"
28 # If clone fails with git-p4.fallbackEncoding set to "none", create the "clone_fails" file,
29 # and make sure the error message is correct
31 test_expect_success 'clone with git-p4.fallbackEncoding set to "none"' '
32 git config --global git-p4.fallbackEncoding none &&
33 test_when_finished cleanup_git && {
34 git p4 clone --dest="$git" //depot@all 2>error || (
36 grep "UTF-8 decoding failed. Consider using git config git-p4.fallbackEncoding" error
41 # If clone fails with git-p4.fallbackEncoding set to "none", it should also fail when it's unset,
42 # also with the correct error message. Otherwise the clone should succeed.
44 test_expect_success 'clone with git-p4.fallbackEncoding unset' '
45 git config --global --unset git-p4.fallbackEncoding &&
46 test_when_finished cleanup_git && {
48 test -f "$clone_fails" &&
49 test_must_fail git p4 clone --dest="$git" //depot@all 2>error &&
50 grep "UTF-8 decoding failed. Consider using git config git-p4.fallbackEncoding" error
53 ! test -f "$clone_fails" &&
54 git p4 clone --dest="$git" //depot@all 2>error
59 # Whether or not "clone_fails" exists, setting git-p4.fallbackEncoding
60 # to "cp1252" should cause clone to succeed and get the right description
62 test_expect_success 'clone with git-p4.fallbackEncoding set to "cp1252"' '
63 git config --global git-p4.fallbackEncoding cp1252 &&
64 test_when_finished cleanup_git &&
66 git p4 clone --dest="$git" //depot@all &&
68 git log --oneline >log &&
69 desc=$(head -1 log | cut -d" " -f2) &&
70 test "$desc" = "documentación"
74 # Setting git-p4.fallbackEncoding to "replace" should always cause clone to succeed.
75 # If "clone_fails" exists, the description should contain the Unicode replacement
76 # character, otherwise the description should be correct (since we're on a system that
77 # doesn't have the Unicode issue)
79 test_expect_success 'clone with git-p4.fallbackEncoding set to "replace"' '
80 git config --global git-p4.fallbackEncoding replace &&
81 test_when_finished cleanup_git &&
83 git p4 clone --dest="$git" //depot@all &&
85 git log --oneline >log &&
86 desc=$(head -1 log | cut -d" " -f2) &&
88 (test -f "$clone_fails" &&
89 test "$desc" = "documentaci�n"
91 (! test -f "$clone_fails" &&
92 test "$desc" = "documentación"