Commit 5fd795a
committed
Read git's yes/no and on/off booleans in get_value
git accepts yes/no and on/off for a boolean as well as true/false
(git_parse_maybe_bool_text in parse.c), and ConfigParser.getboolean on this
class already accepted all of them. _string_to_value handled only true/false,
under a comment claiming to "try boolean values as git uses them", so the two
accessors disagreed about the same file:
value get_value() getboolean() git config --type=bool
yes 'yes' True true
no 'no' False false
on 'on' True true
off 'off' False false
Returning them as strings was worse than merely inexact. "no" and "off" are
non-empty, so a caller testing the result of get_value got True for a value
git reads as false — the inversion is silent, since nothing raises.
_string_to_value now recognises the same spellings getboolean does. A value
that is not a boolean is untouched, so "meld" is still returned as a string,
and numeric values keep their existing behavior.
Not changed here: get_value also diverges on numeric bases and suffixes
("0x10" and "1k" come back as strings, "010" as 10 where git reads octal 8).
Those change the value rather than its type and are worth their own commit.
Validation: test_get_value_reads_git_boolean_spellings covers the ten
spellings and asserts the two accessors agree; it fails on the previous
revision. test/test_config.py passes (40 passed, 2 skipped), ruff check and
ruff format are clean. test/test_repo.py errors on this clone because
init-tests-after-clone.sh has not been run, unchanged by this commit.1 parent 41c3954 commit 5fd795a
2 files changed
Lines changed: 40 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
956 | 956 | | |
957 | 957 | | |
958 | 958 | | |
959 | | - | |
| 959 | + | |
| 960 | + | |
| 961 | + | |
| 962 | + | |
| 963 | + | |
| 964 | + | |
960 | 965 | | |
961 | | - | |
| 966 | + | |
962 | 967 | | |
963 | | - | |
| 968 | + | |
964 | 969 | | |
965 | 970 | | |
966 | 971 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
167 | 167 | | |
168 | 168 | | |
169 | 169 | | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
170 | 202 | | |
171 | 203 | | |
172 | 204 | | |
| |||
0 commit comments