diff options
-rw-r--r-- | color.c | 6 | ||||
-rwxr-xr-x | t/t3701-add-interactive.sh | 14 | ||||
-rwxr-xr-x | t/t4026-color.sh | 7 | ||||
-rwxr-xr-x | t/t4202-log.sh | 2 |
4 files changed, 25 insertions, 4 deletions
@@ -212,8 +212,10 @@ int color_parse_mem(const char *value, int value_len, char *dst) len--; } - if (!len) - return -1; + if (!len) { + dst[0] = '\0'; + return 0; + } if (!strncasecmp(ptr, "reset", len)) { xsnprintf(dst, end - dst, GIT_COLOR_RESET); diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh index deae948..5ffe78e 100755 --- a/t/t3701-add-interactive.sh +++ b/t/t3701-add-interactive.sh @@ -380,4 +380,18 @@ test_expect_success 'patch mode ignores unmerged entries' ' test_cmp expected diff ' +test_expect_success 'diffs can be colorized' ' + git reset --hard && + + # force color even though the test script has no terminal + test_config color.ui always && + + echo content >test && + printf y | git add -p >output 2>&1 && + + # We do not want to depend on the exact coloring scheme + # git uses for diffs, so just check that we saw some kind of color. + grep "$(printf "\\033")" output +' + test_done diff --git a/t/t4026-color.sh b/t/t4026-color.sh index ec78c5e..671e951 100755 --- a/t/t4026-color.sh +++ b/t/t4026-color.sh @@ -6,10 +6,11 @@ test_description='Test diff/status color escape codes' . ./test-lib.sh +ESC=$(printf '\033') color() { actual=$(git config --get-color no.such.slot "$1") && - test "$actual" = "$2" + test "$actual" = "${2:+$ESC}$2" } invalid_color() @@ -21,6 +22,10 @@ test_expect_success 'reset' ' color "reset" "[m" ' +test_expect_success 'empty color is empty' ' + color "" "" +' + test_expect_success 'attribute before color name' ' color "bold red" "[1;31m" ' diff --git a/t/t4202-log.sh b/t/t4202-log.sh index 0aeabed..1edbb1e 100755 --- a/t/t4202-log.sh +++ b/t/t4202-log.sh @@ -329,7 +329,7 @@ cat > expect.colors <<\EOF EOF test_expect_success 'log --graph with merge with log.graphColors' ' - test_config log.graphColors ",, blue,invalid-color, cyan, red , " && + test_config log.graphColors " blue,invalid-color, cyan, red , " && git log --color=always --graph --date-order --pretty=tformat:%s | test_decode_color | sed "s/ *\$//" >actual && test_cmp expect.colors actual |