Skip to content

config: reject keys with an empty subsection#2341

Draft
HaraldNordgren wants to merge 1 commit into
git:masterfrom
HaraldNordgren:config-reject-empty-subsection
Draft

config: reject keys with an empty subsection#2341
HaraldNordgren wants to merge 1 commit into
git:masterfrom
HaraldNordgren:config-reject-empty-subsection

Conversation

@HaraldNordgren

@HaraldNordgren HaraldNordgren commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Reject section..key style keys with an empty subsection at write time, since the config parser cannot read them back and a single bad git config could otherwise break later reads like git status.

Special case for alias, but maybe that shouldn't be there.

@dscho

dscho commented Jun 16, 2026

Copy link
Copy Markdown
Member

@HaraldNordgren wait, I do have a use case for those. Empty subsections allow "dotted aliases" like git .r. I think you will need a much more compelling cover letter if you want to defend this idea to render those existing use cases dysfunctional.

@HaraldNordgren HaraldNordgren force-pushed the config-reject-empty-subsection branch from 06e27d8 to d954594 Compare June 16, 2026 08:29
@HaraldNordgren HaraldNordgren marked this pull request as draft June 16, 2026 08:49
@HaraldNordgren HaraldNordgren force-pushed the config-reject-empty-subsection branch from d954594 to 665ca9f Compare June 16, 2026 08:49
@HaraldNordgren

Copy link
Copy Markdown
Contributor Author

Thanks @dscho!

Is alias special here, so we could run this for every other case you think?

@HaraldNordgren HaraldNordgren force-pushed the config-reject-empty-subsection branch 8 times, most recently from 5b01513 to be3e567 Compare June 16, 2026 09:49
@dscho

dscho commented Jun 16, 2026

Copy link
Copy Markdown
Member

Thanks @dscho!

Is alias special here, so we could run this for every other case you think?

You could special-case alias. But I don't think that this kind of complicating things serves us well. Exhibit A: Git itself. Look at the many special-casings that all had merit, and cumulatively result in this horribly inconsistent user experience. "It's easy! Just do X. Except in case B, do Y. And if that fails because of C, do X again, then it'll work! Easy." Same here. "This is prohibited". "But why does it work with aliases?" "Because aliases are special." "That makes no sense!" "Well, it is what it is." Is the kind of frustrating conversation I foresee if you push this through. Git is full of these convoluted argumentations. Let's not make it worse.

@HaraldNordgren

HaraldNordgren commented Jun 16, 2026

Copy link
Copy Markdown
Contributor Author

@dscho I ran this and all of a sudden my git status was broken.

I could fix it, but can we really expect a new user to handle this?

❯ git config branch.$(rev-parse --abbrev-ref HEAD).pushRemote upstream # Forgot 'git' before rev-parse
zsh: command not found: rev-parse

❯ git status
On branch fetch-prune-local-branches
fatal: bad config variable 'branch..pushremote' in file '.git/config' at line 274

@dscho

dscho commented Jun 16, 2026

Copy link
Copy Markdown
Member

❯ git config branch.$(rev-parse --abbrev-ref HEAD).pushRemote upstream # Forgot 'git' before rev-parse
zsh: command not found: rev-parse

Rather than encouraging such invocations, why not make life with Git simpler for a change and implement a companion of the git branch --set-upstream-to option?

No amount of added complexity in Git can prevent complicated command-lines from being footguns for the user. Therefore, I would like to encourage you to optimize for improved user experience and footgun reduction rather than for complicated command-lines.

@HaraldNordgren

Copy link
Copy Markdown
Contributor Author

@dscho That's a interesting idea!

So --set-upstream-to updates the config itself? I never thought about that!

@dscho

dscho commented Jun 16, 2026

Copy link
Copy Markdown
Member

So --set-upstream-to updates the config itself?

It sure does :-)

@HaraldNordgren

Copy link
Copy Markdown
Contributor Author

@dscho Thinking about this again, branch is not special in this case so implementing a --set-push-remote-to doesn't solve the core issue.

My point was that a user can easily set a config that will break their setup. I wonder if even alias should be treated specially. I guess that a user that needs that can set it themselves via config?

No amount of added complexity in Git can prevent complicated command-lines from being footguns for the user.

One step at a time we can make Git better for everyone 😃

A key like "branch..pushremote" has an empty subsection. For
name-keyed sections such as branch, remote, and submodule the
subsection is the name of a thing, so an empty one is unusable, and
reading it back made commands such as "git status" die with "bad
config variable".

Make "git config" reject writing a key with an empty subsection. The
alias section is exempt, since its subsection is a free-form alias
name rather than a lookup key, and an empty one is allowed there.

Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com>
@HaraldNordgren HaraldNordgren force-pushed the config-reject-empty-subsection branch from be3e567 to 36f4084 Compare July 12, 2026 18:43
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.

2 participants