From: Thomas Bachem via GitGitGadget Date: Wed, 11 Nov 2026 22:49:03 GMT Subject: [PATCH v3 03/15] add-patch: handle NULL value for color slots Message-ID: In-Reply-To: From: Thomas Bachem With color on, a color slot without a value, such as color.interactive.prompt or color.diff.frag, makes "git add -p", "git add -i" and the other interactive patch modes segfault: init_color() passes the NULL value to color_parse(). Read the slot with repo_config_get_string_tmp(), which rejects a missing value with config_error_nonbool(), as "git diff" already does for color.diff.frag and the other diff colors. Assisted-by: Claude Fable 5.1 Signed-off-by: Thomas Bachem --- add-patch.c | 2 +- t/t3701-add-interactive.sh | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/add-patch.c b/add-patch.c index f27edcbe8d..ad581eb4ae 100644 --- a/add-patch.c +++ b/add-patch.c @@ -295,7 +295,7 @@ static void init_color(struct repository *r, if (!want_color(use_color)) dst[0] = '\0'; - else if (repo_config_get_value(r, key, &value) || + else if (repo_config_get_string_tmp(r, key, &value) || color_parse(value, dst)) strlcpy(dst, default_color, COLOR_MAXLEN); diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh index 6e120a4001..33050ccc53 100755 --- a/t/t3701-add-interactive.sh +++ b/t/t3701-add-interactive.sh @@ -815,6 +815,18 @@ test_expect_success 'colors can be overridden' ' test_cmp expect actual ' +test_expect_success 'a color without a value is rejected' ' + git reset --hard && + test_when_finished "git rm -f color-test" && + test_write_lines context old >color-test && + git add color-test && + test_write_lines context new >color-test && + + test_must_fail git -c color.interactive=always \ + -c color.interactive.prompt add -p err && + test_grep "missing value for .color.interactive.prompt." err +' + test_expect_success 'brackets appear without color' ' git reset --hard && test_when_finished "git rm -f bracket-test" && -- gitgitgadget