config: read boolean values the way git does by rawsun007 · Pull Request #2360 · go-git/go-git · GitHub
Skip to content

config: read boolean values the way git does - #2360

Open
rawsun007 wants to merge 1 commit into
go-git:mainfrom
rawsun007:fix/config-bool-values
Open

config: read boolean values the way git does#2360
rawsun007 wants to merge 1 commit into
go-git:mainfrom
rawsun007:fix/config-bool-values

Conversation

@rawsun007

Copy link
Copy Markdown

Git accepts yes/no/on/off and any integer for a boolean. This repository already implements that in parseConfigBool, citing git_parse_maybe_bool_text — but five keys did not use it.

Measured against git config -f <file> --type=bool --get, git 2.50.1:

value git commit.gpgsign before core.protectNTFS (already correct)
yes / Yes / on / On true unset true
no / off false unset false
2 / -1 true unset true
true / 1 / false / 0 as written correct correct
  • commit.gpgsign and tag.gpgsign used strconv.ParseBool, which rejects those spellings; the error was swallowed and the option left unset. Since unset means "use the default", a repository configured with commit.gpgsign = yes got no signing at all, with nothing reported.
  • index.skipHash and uploadarchive.allowUnreachable had the same treatment.
  • extensions.worktreeConfig compared against the literal "true", so 1, yes and on read as false.

All five now go through parseConfigBool. core.protectNTFS/protectHFS already did, which is what the new test contrasts against — same file, same value, two different answers before this change.

Behaviour worth calling out explicitly: an unreadable value (garbage) still leaves the key unset rather than erroring, exactly as before. Git errors there; go-git's contract is that the caller's default applies, and parseConfigBool's own doc comment says an empty value means unset. I did not change that, since it is a separate decision from which spellings parse.

Verification:

  • TestUnmarshalBoolValues expectations are that git config --type=bool output, not my reading of parse.c.
  • Reverting only config/config.go fails the new test on the first yes case.
  • go test -short ./... — 68 packages pass, no failures.

Note on the one pre-existing failure you may see locally: plumbing/format/gitignore's TestConformanceSuite fails on any git older than 2.52.0, exactly as your own oracleVersionHint note predicts (mine is 2.50.1). Unrelated to this change, and I left it alone — the comment says the visible disagreement is deliberate.

This is a behaviour change rather than a pure refactor, so if you would rather it went through an issue or RFC first per AI_POLICY.md, say so and I will move the write-up there.

AI disclosure per AI_POLICY.md: found and written with Claude Code (Claude Opus 5), recorded in the commit's Assisted-by: trailer. @rawsun007 authorised the DCO sign-off and reviewed the change.

Git accepts `yes`/`no`/`on`/`off` and any integer for a boolean, and this
repository already implements that in `parseConfigBool`, citing
`git_parse_maybe_bool_text`. Five keys did not use it:

  - `commit.gpgsign` and `tag.gpgsign` went through `strconv.ParseBool`, so
    `yes`, `on`, `no`, `off`, `2` and `-1` failed to parse and left the option
    unset. A repository configured with `commit.gpgsign = yes` therefore got no
    signing, silently, because unset means "use the default".
  - `index.skipHash` and `uploadarchive.allowUnreachable` had the same
    treatment.
  - `extensions.worktreeConfig` compared the value against the literal
    "true", so `1`, `yes` and `on` all read as false.

`core.protectNTFS` and `core.protectHFS` already used `parseConfigBool` and
were correct, which is what the new test contrasts against.

Expectations in TestUnmarshalBoolValues are the output of
`git config -f <file> --type=bool --get <key>` under git 2.50.1. An
unreadable value still leaves the key unset rather than erroring, so the
caller's default applies as before.

Assisted-by: Claude Code (Claude Opus 5)
Signed-off-by: Roshan Ramani <roshanramani.dev@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant