t / t5409-colorize-remote-messages.shon commit sideband: highlight keywords in remote sideband output (bf1a11f)
   1#!/bin/sh
   2
   3test_description='remote messages are colorized on the client'
   4
   5. ./test-lib.sh
   6
   7test_expect_success 'setup' '
   8        mkdir .git/hooks &&
   9        write_script .git/hooks/update <<-\EOF &&
  10        echo error: error
  11        echo ERROR: also highlighted
  12        echo hint: hint
  13        echo hinting: not highlighted
  14        echo success: success
  15        echo warning: warning
  16        echo prefixerror: error
  17        echo " " "error: leading space"
  18        exit 0
  19        EOF
  20        echo 1 >file &&
  21        git add file &&
  22        git commit -m 1 &&
  23        git clone . child &&
  24        (
  25                cd child &&
  26                test_commit message2 file content2
  27        )
  28'
  29
  30test_expect_success 'keywords' '
  31        git --git-dir child/.git -c color.remote=always push -f origin HEAD:refs/heads/keywords 2>output &&
  32        test_decode_color <output >decoded &&
  33        grep "<BOLD;RED>error<RESET>: error" decoded &&
  34        grep "<YELLOW>hint<RESET>:" decoded &&
  35        grep "<BOLD;GREEN>success<RESET>:" decoded &&
  36        grep "<BOLD;YELLOW>warning<RESET>:" decoded
  37'
  38
  39test_expect_success 'whole words at line start' '
  40        git --git-dir child/.git -c color.remote=always push -f origin HEAD:refs/heads/whole-words 2>output &&
  41        test_decode_color <output >decoded &&
  42        grep "<YELLOW>hint<RESET>:" decoded &&
  43        grep "hinting: not highlighted" decoded &&
  44        grep "prefixerror: error" decoded
  45'
  46
  47test_expect_success 'case-insensitive' '
  48        git --git-dir child/.git -c color.remote=always push -f origin HEAD:refs/heads/case-insensitive 2>output &&
  49        cat output &&
  50        test_decode_color <output >decoded &&
  51        grep "<BOLD;RED>error<RESET>: error" decoded &&
  52        grep "<BOLD;RED>ERROR<RESET>: also highlighted" decoded
  53'
  54
  55test_expect_success 'leading space' '
  56        git --git-dir child/.git -c color.remote=always push -f origin HEAD:refs/heads/leading-space 2>output &&        cat output &&
  57        test_decode_color <output >decoded &&
  58        grep "  <BOLD;RED>error<RESET>: leading space" decoded
  59'
  60
  61test_expect_success 'no coloring for redirected output' '
  62        git --git-dir child/.git push -f origin HEAD:refs/heads/redirected-output 2>output &&
  63        test_decode_color <output >decoded &&
  64        grep "error: error" decoded
  65'
  66
  67test_expect_success 'push with customized color' '
  68        git --git-dir child/.git -c color.remote=always -c color.remote.error=blue push -f origin HEAD:refs/heads/customized-color 2>output &&
  69        test_decode_color <output >decoded &&
  70        grep "<BLUE>error<RESET>:" decoded &&
  71        grep "<BOLD;GREEN>success<RESET>:" decoded
  72'
  73
  74
  75test_expect_success 'error in customized color' '
  76        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 &&
  77        test_decode_color <output >decoded &&
  78        grep "<BOLD;GREEN>success<RESET>:" decoded
  79'
  80
  81test_expect_success 'fallback to color.ui' '
  82        git --git-dir child/.git -c color.ui=always push -f origin HEAD:refs/heads/fallback-color-ui 2>output &&
  83        test_decode_color <output >decoded &&
  84        grep "<BOLD;RED>error<RESET>: error" decoded
  85'
  86
  87test_done