mirror of
https://gerrit.googlesource.com/git-repo
synced 2026-07-16 05:36:59 +00:00
35bbf701d0
Per the git documentation for color.ui [1], setting color.ui to "true" (or "yes") should behave identically to "auto", enabling color only when output is written to a terminal or an active pager. Previously, repo was equating "true" and "yes" with "always", which caused color escape codes to be emitted unconditionally, even when output was piped or redirected. Replace the duplicated string-matching logic in SetDefaultColoring and Coloring.__init__ with a single CONFIG_TO_COLOR_SETTING dict that maps all git color config values to their behavior. This makes the mapping easy to verify against the git docs and impossible to get out of sync between the two call sites. Added tests for SetDefaultColoring and Coloring.__init__ covering all color mode values (auto, true, yes, always, never, no, false), case insensitivity, TTY vs pipe behavior, active pager detection, and unrecognised input. [1] https://git-scm.com/docs/git-config#Documentation/git-config.txt-colorui Bug: 295841573 Change-Id: I8a04b9c7e4154de37ed7518c010233039e0afdc9 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/602981 Tested-by: Brian Gan <brgan@google.com> Reviewed-by: Gavin Mak <gavinmak@google.com> Commit-Queue: Brian Gan <brgan@google.com>
Repo Tests
There is a mixture of pytest & Python unittest in here. We adopted pytest later on but didn't migrate existing tests (since they still work). New tests should be written using pytest only.
File layout
test_xxx.py: Unittests for thexxxmodule in the main repo codebase. Modules that are in subdirs normalize the/into_. For example, test_error.py is for the error.py module, and test_subcmds_forall.py is for the subcmds/forall.py module.- conftest.py: Custom pytest fixtures for sharing.
- utils_for_test.py: Helpers for sharing in tests.