* Optionally highlight one keyword in remote output if it appears at the start
* of the line. This should be called for a single line only, which is
* passed as the first N characters of the SRC array.
+ *
+ * NEEDSWORK: use "size_t n" instead for clarity.
*/
static void maybe_colorize_sideband(struct strbuf *dest, const char *src, int n)
{
return;
}
- while (isspace(*src)) {
+ while (0 < n && isspace(*src)) {
strbuf_addch(dest, *src);
src++;
n--;
for (i = 0; i < ARRAY_SIZE(keywords); i++) {
struct keyword_entry *p = keywords + i;
int len = strlen(p->keyword);
+
+ if (n <= len)
+ continue;
/*
* Match case insensitively, so we colorize output from existing
* servers regardless of the case that they use for their
}
strbuf_add(dest, src, n);
-
}
echo warning: warning
echo prefixerror: error
echo " " "error: leading space"
+ echo " "
+ echo Err
exit 0
EOF
echo 1 >file &&
grep "prefixerror: error" decoded
'
+test_expect_success 'short line' '
+ git -C child -c color.remote=always push -f origin HEAD:short-line 2>output &&
+ test_decode_color <output >decoded &&
+ grep "remote: Err" decoded
+'
+
test_expect_success 'case-insensitive' '
git --git-dir child/.git -c color.remote=always push -f origin HEAD:refs/heads/case-insensitive 2>output &&
cat output &&
grep " <BOLD;RED>error<RESET>: leading space" decoded
'
+test_expect_success 'spaces only' '
+ git -C child -c color.remote=always push -f origin HEAD:only-space 2>output &&
+ test_decode_color <output >decoded &&
+ grep "remote: " decoded
+'
+
test_expect_success 'no coloring for redirected output' '
git --git-dir child/.git push -f origin HEAD:refs/heads/redirected-output 2>output &&
test_decode_color <output >decoded &&