Merge branch 'ab/describe-tests-fix' into jch
[git] / t / t9836-git-p4-config-fallback-encoding.sh
1 #!/bin/sh
2
3 test_description='test git-p4.fallbackEncoding config'
4
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
8 . ./lib-git-p4.sh
9
10 test_expect_success 'start p4d' '
11         start_p4d
12 '
13
14 test_expect_success 'add Unicode description' '
15         cd "$cli" &&
16         echo file1 >file1 &&
17         p4 add file1 &&
18         p4 submit -d documentación
19 '
20
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.
25
26 clone_fails="$TRASH_DIRECTORY/clone_fails"
27
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
30
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 || (
35                         >"$clone_fails" &&
36                         grep "UTF-8 decoding failed. Consider using git config git-p4.fallbackEncoding" error
37                 )
38         }
39 '
40
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.
43
44 test_expect_success 'clone with git-p4.fallbackEncoding unset' '
45         git config --global --unset git-p4.fallbackEncoding &&
46         test_when_finished cleanup_git && {
47                 (
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
51                 ) ||
52                 (
53                         ! test -f "$clone_fails" &&
54                         git p4 clone --dest="$git" //depot@all 2>error
55                 )
56         }
57 '
58
59 # Whether or not "clone_fails" exists, setting git-p4.fallbackEncoding
60 # to "cp1252" should cause clone to succeed and get the right description
61
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 &&
65         (
66                 git p4 clone --dest="$git" //depot@all &&
67                 cd "$git" &&
68                 git log --oneline >log &&
69                 desc=$(head -1 log | cut -d" " -f2) &&
70                 test "$desc" = "documentación"
71         )
72 '
73
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)
78
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 &&
82         (
83                 git p4 clone --dest="$git" //depot@all &&
84                 cd "$git" &&
85                 git log --oneline >log &&
86                 desc=$(head -1 log | cut -d" " -f2) &&
87                 {
88                         (test -f "$clone_fails" &&
89                                 test "$desc" = "documentaci�n"
90                         ) ||
91                         (! test -f "$clone_fails" &&
92                                 test "$desc" = "documentación"
93                         )
94                 }
95         )
96 '
97
98 test_done