| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,36 +10,34 @@ | |||
| 10 | 10 | import abc | |
| 11 | 11 | import configparser as cp | |
| 12 | 12 | import fnmatch | |
| 13 | - from functools import wraps | ||
| 14 | 13 | import inspect | |
| 15 | - from io import BufferedReader, IOBase | ||
| 16 | 14 | import logging | |
| 17 | 15 | import os | |
| 18 | 16 | import os.path as osp | |
| 19 | 17 | import re | |
| 20 | 18 | import sys | |
| 21 | - | ||
| 22 | - from git.compat import defenc, force_text | ||
| 23 | - from git.util import LockFile | ||
| 19 | + from functools import wraps | ||
| 20 | + from io import BufferedReader, IOBase | ||
| 24 | 21 | ||
| 25 | 22 | # typing------------------------------------------------------- | |
| 26 | - | ||
| 27 | 23 | from typing import ( | |
| 24 | + IO, | ||
| 25 | + TYPE_CHECKING, | ||
| 28 | 26 | Any, | |
| 29 | 27 | Callable, | |
| 28 | + Dict, | ||
| 30 | 29 | Generic, | |
| 31 | - IO, | ||
| 32 | 30 | List, | |
| 33 | - Dict, | ||
| 34 | 31 | Sequence, | |
| 35 | - TYPE_CHECKING, | ||
| 36 | 32 | Tuple, | |
| 37 | 33 | TypeVar, | |
| 38 | 34 | Union, | |
| 39 | 35 | cast, | |
| 40 | 36 | ) | |
| 41 | 37 | ||
| 42 | - from git.types import Lit_config_levels, ConfigLevels_Tup, PathLike, assert_never, _T | ||
| 38 | + from git.compat import defenc, force_text | ||
| 39 | + from git.types import _T, ConfigLevels_Tup, Lit_config_levels, PathLike, assert_never | ||
| 40 | + from git.util import LockFile | ||
| 43 | 41 | ||
| 44 | 42 | if TYPE_CHECKING: | |
| 45 | 43 | from io import BytesIO | |
@@ -958,9 +956,9 @@ def _string_to_value(self, valuestr: str) -> Union[int, float, str, bool]: | |||
| 958 | 956 | ||
| 959 | 957 | # Try boolean values as git uses them. | |
| 960 | 958 | vl = valuestr.lower() | |
| 961 | - if vl == "false": | ||
| 959 | + if vl in ("false", "no", "off"): | ||
| 962 | 960 | return False | |
| 963 | - if vl == "true": | ||
| 961 | + if vl in ("true", "yes", "on"): | ||
| 964 | 962 | return True | |
| 965 | 963 | ||
| 966 | 964 | if not isinstance(valuestr, str): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -167,6 +167,38 @@ def test_backslash_line_continuation(self): | |||
| 167 | 167 | key = "co" if section == "alias" else "k" | |
| 168 | 168 | self.assertEqual(config.get_value(section, key), expected) | |
| 169 | 169 | ||
| 170 | + def test_get_value_reads_git_boolean_spellings(self): | ||
| 171 | + # git accepts yes/no and on/off as well as true/false, and getboolean on | ||
| 172 | + # this class already did. get_value returned them as strings, so "no" and | ||
| 173 | + # "off" arrived as non-empty (truthy) values for a caller testing them. | ||
| 174 | + cases = [ | ||
| 175 | + (b"true", True), | ||
| 176 | + (b"TRUE", True), | ||
| 177 | + (b"yes", True), | ||
| 178 | + (b"Yes", True), | ||
| 179 | + (b"on", True), | ||
| 180 | + (b"On", True), | ||
| 181 | + (b"false", False), | ||
| 182 | + (b"no", False), | ||
| 183 | + (b"off", False), | ||
| 184 | + (b"Off", False), | ||
| 185 | + ] | ||
| 186 | + for raw, expected in cases: | ||
| 187 | + config_file = io.BytesIO(b"[core]\n\tflag = " + raw + b"\n") | ||
| 188 | + config_file.name = "boolean_spellings.config" | ||
| 189 | + config = GitConfigParser(config_file) | ||
| 190 | + config.read() | ||
| 191 | + self.assertIs(config.get_value("core", "flag"), expected, raw.decode()) | ||
| 192 | + # The two accessors must not disagree about the same value. | ||
| 193 | + self.assertIs(config.getboolean("core", "flag"), expected, raw.decode()) | ||
| 194 | + | ||
| 195 | + # A value that is not a boolean at all still comes back untouched. | ||
| 196 | + config_file = io.BytesIO(b"[core]\n\tflag = meld\n") | ||
| 197 | + config_file.name = "boolean_spellings.config" | ||
| 198 | + config = GitConfigParser(config_file) | ||
| 199 | + config.read() | ||
| 200 | + self.assertEqual(config.get_value("core", "flag"), "meld") | ||
| 201 | + | ||
| 170 | 202 | @with_rw_directory | |
| 171 | 203 | def test_comment_backslash_does_not_continue_value(self, rw_dir): | |
| 172 | 204 | config_path = osp.join(rw_dir, "config") | |
| Back | FazBrowse Home | New Git URL |
0 commit comments