Skip to content

Commit 7cf3b49

Browse files
derrickstoleegitster
authored andcommitted
add: check color.ui for interactive add
When 'git add -i' and 'git add -p' were converted to a builtin, they introduced a color bug: the 'color.ui' config setting is ignored. The included test demonstrates an example that is similar to the previous test, which focuses on customizing colors. Here, we are demonstrating that colors are not being used at all by comparing the raw output and the color-decoded version of that output. The fix is simple, to use git_color_default_config() as the fallback for git_add_config(). A more robust change would instead encapsulate the git_use_color_default global in methods that would check the config setting if it has not been initialized yet. Some ideas are being discussed on this front [1], but nothing has been finalized. [1] https://lore.kernel.org/git/[email protected]/ This test case naturally bisects down to 0527ccb (add -i: default to the built-in implementation, 2021-11-30), but the fix makes it clear that this would be broken even if we added the config to use the builtin earlier than this. Reported-by: Greg Alexander <[email protected]> Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0d1bd1d commit 7cf3b49

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

builtin/add.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ static int add_config(const char *var, const char *value, void *cb)
362362
return 0;
363363
}
364364

365-
return git_default_config(var, value, cb);
365+
return git_color_default_config(var, value, cb);
366366
}
367367

368368
static const char embedded_advice[] = N_(

t/t3701-add-interactive.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,21 @@ test_expect_success 'colors can be overridden' '
738738
test_cmp expect actual
739739
'
740740

741+
test_expect_success 'colors can be skipped with color.ui=false' '
742+
git reset --hard &&
743+
test_when_finished "git rm -f color-test" &&
744+
test_write_lines context old more-context >color-test &&
745+
git add color-test &&
746+
test_write_lines context new more-context another-one >color-test &&
747+
748+
test_write_lines help quit >input &&
749+
force_color git \
750+
-c color.ui=false \
751+
add -i >actual.raw <input &&
752+
test_decode_color <actual.raw >actual &&
753+
test_cmp actual.raw actual
754+
'
755+
741756
test_expect_success 'colorized diffs respect diff.wsErrorHighlight' '
742757
git reset --hard &&
743758

0 commit comments

Comments
 (0)