Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/git/blob/master/t/t5409-colorize-remote-messages.sh # git [Ported from github.com/git/git] Sync with Git 2.56.1 Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `git / t / t5409-colorize-remote-messages.sh` 193 lines ยท 6271 bytes Raw Blame History 1 #!/bin/sh 2 3 test_description='remote messages are colorized on the client' 4 5 . ./test-lib.sh 6 7 test_expect_success 'setup' ' 8 test_hook --setup update <<-\EOF && 9 echo error: error 10 echo ERROR: also highlighted 11 echo hint: hint 12 echo hinting: not highlighted 13 echo success: success 14 echo warning: warning 15 echo prefixerror: error 16 echo " " "error: leading space" 17 echo " " 18 echo Err 19 echo SUCCESS 20 exit 0 21 EOF 22 echo 1 >file && 23 git add file && 24 git commit -m 1 && 25 git clone . child && 26 ( 27 cd child && 28 test_commit message2 file content2 29 ) 30 ' 31 32 test_expect_success 'keywords' ' 33 git --git-dir child/.git -c color.remote=always push -f origin HEAD:refs/heads/keywords 2>output && 34 test_decode_color decoded && 35 test_grep "error: error" decoded && 36 test_grep "hint:" decoded && 37 test_grep "success:" decoded && 38 test_grep "SUCCESS" decoded && 39 test_grep "warning:" decoded 40 ' 41 42 test_expect_success 'whole words at line start' ' 43 git --git-dir child/.git -c color.remote=always push -f origin HEAD:refs/heads/whole-words 2>output && 44 test_decode_color decoded && 45 test_grep "hint:" decoded && 46 test_grep "hinting: not highlighted" decoded && 47 test_grep "prefixerror: error" decoded 48 ' 49 50 test_expect_success 'short line' ' 51 git -C child -c color.remote=always push -f origin HEAD:short-line 2>output && 52 test_decode_color decoded && 53 test_grep "remote: Err" decoded 54 ' 55 56 test_expect_success 'case-insensitive' ' 57 git --git-dir child/.git -c color.remote=always push -f origin HEAD:refs/heads/case-insensitive 2>output && 58 test_decode_color decoded && 59 test_grep "error: error" decoded && 60 test_grep "ERROR: also highlighted" decoded 61 ' 62 63 test_expect_success 'leading space' ' 64 git --git-dir child/.git -c color.remote=always push -f origin HEAD:refs/heads/leading-space 2>output && 65 test_decode_color decoded && 66 test_grep " error: leading space" decoded 67 ' 68 69 test_expect_success 'spaces only' ' 70 git -C child -c color.remote=always push -f origin HEAD:only-space 2>output && 71 test_decode_color decoded && 72 test_grep "remote: " decoded 73 ' 74 75 test_expect_success 'no coloring for redirected output' ' 76 git --git-dir child/.git push -f origin HEAD:refs/heads/redirected-output 2>output && 77 test_decode_color decoded && 78 test_grep "error: error" decoded 79 ' 80 81 test_expect_success 'push with customized color' ' 82 git --git-dir child/.git -c color.remote=always -c color.remote.error=blue push -f origin HEAD:refs/heads/customized-color 2>output && 83 test_decode_color decoded && 84 test_grep "error:" decoded && 85 test_grep "success:" decoded 86 ' 87 88 89 test_expect_success 'error in customized color' ' 90 git --git-dir child/.git -c color.remote=always -c color.remote.error=i-am-not-a-color push -f origin HEAD:refs/heads/error-customized-color 2>output && 91 test_decode_color decoded && 92 test_grep "success:" decoded 93 ' 94 95 test_expect_success 'fallback to color.ui' ' 96 git --git-dir child/.git -c color.ui=always push -f origin HEAD:refs/heads/fallback-color-ui 2>output && 97 test_decode_color decoded && 98 test_grep "error: error" decoded 99 ' 100 101 test_expect_success 'disallow (color) control sequences in sideband' ' 102 write_script .git/color-me-surprised <<-\EOF && 103 printf "error: Have you \\033[31mread\\033[m this?\\a\\n" >&2 104 exec "$@" 105 EOF 106 test_config_global uploadPack.packObjectsHook ./color-me-surprised && 107 test_commit need-at-least-one-commit && 108 109 git clone --no-local . throw-away 2>stderr && 110 test_decode_color decoded && 111 test_grep RED decoded && 112 test_grep "\\^G" stderr && 113 tr -dc "\\007" actual && 114 test_must_be_empty actual && 115 116 rm -rf throw-away && 117 git -c sideband.allowControlCharacters=false \ 118 clone --no-local . throw-away 2>stderr && 119 test_decode_color decoded && 120 test_grep ! RED decoded && 121 test_grep "\\^G" stderr && 122 123 rm -rf throw-away && 124 git -c sideband.allowControlCharacters clone --no-local . throw-away 2>stderr && 125 test_decode_color decoded && 126 test_grep RED decoded && 127 tr -dc "\\007" actual && 128 test_file_not_empty actual 129 ' 130 131 test_decode_csi() { 132 awk '{ 133 while (match($0, /\033/) != 0) { 134 printf "%sCSI ", substr($0, 1, RSTART-1); 135 $0 = substr($0, RSTART + RLENGTH, length($0) - RSTART - RLENGTH + 1); 136 } 137 print 138 }' 139 } 140 141 test_expect_success 'control sequences in sideband allowed by default' ' 142 write_script .git/color-me-surprised <<-\EOF && 143 printf "error: \\033[31mcolor\\033[m\\033[Goverwrite\\033[Gerase\\033[K\\033?25l\\n" >&2 144 exec "$@" 145 EOF 146 test_config_global uploadPack.packObjectsHook ./color-me-surprised && 147 test_commit need-at-least-one-commit-at-least && 148 149 rm -rf throw-away && 150 git clone --no-local . throw-away 2>stderr && 151 test_decode_color color-decoded && 152 test_decode_csi decoded && 153 test_grep ! "CSI \\[K" decoded && 154 test_grep ! "CSI \\[G" decoded && 155 test_grep "\\^\\[?25l" decoded && 156 157 rm -rf throw-away && 158 git -c sideband.allowControlCharacters=erase,cursor,color \ 159 clone --no-local . throw-away 2>stderr && 160 test_decode_color color-decoded && 161 test_decode_csi decoded && 162 test_grep "RED" decoded && 163 test_grep "CSI \\[K" decoded && 164 test_grep "CSI \\[G" decoded && 165 test_grep ! "\\^\\[\\[K" decoded && 166 test_grep ! "\\^\\[\\[G" decoded 167 ' 168 169 test_expect_success 'allow all control sequences for a specific URL' ' 170 write_script .git/eraser <<-\EOF && 171 printf "error: Ohai!\\r\\033[K" >&2 172 exec "$@" 173 EOF 174 test_config_global uploadPack.packObjectsHook ./eraser && 175 test_commit one-more-please && 176 177 rm -rf throw-away && 178 git clone --no-local . throw-away 2>stderr && 179 test_decode_color color-decoded && 180 test_decode_csi decoded && 181 test_grep ! "CSI \\[K" decoded && 182 test_grep "\\^\\[\\[K" decoded && 183 184 rm -rf throw-away && 185 git -c "sideband.file://.allowControlCharacters=true" \ 186 clone --no-local "file://$PWD" throw-away 2>stderr && 187 test_decode_color color-decoded && 188 test_decode_csi decoded && 189 test_grep "CSI \\[K" decoded && 190 test_grep ! "\\^\\[\\[K" decoded 191 ' 192 193 test_done