support parsing numeric git configs as bool

I'm not sure if git documents it aside from 0 and 1, but any integer
can be interpreted as a bool by it. Doing the same in git-annex is good
for consistency. Also, I am planning a config that starts out as a
numeric range, but will later transition to a simple bool (hopefully),
which this interpretation supports well.
This commit is contained in:
Joey Hess 2020-11-16 10:09:25 -04:00
parent 26cf26caca
commit 0121f5f6d3
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38

View file

@ -186,6 +186,10 @@ isTrueFalse' (ConfigValue s)
| s' == "0" = Just False
| s' == "" = Just False
-- Git treats any number other than 0 as true,
-- including negative numbers.
| S8.all (\c -> isDigit c || c == '-') s' = Just True
| otherwise = Nothing
where
s' = S8.map toLower s