add check for nonsense variables in config

This commit is contained in:
Stephanie You
2023-12-15 17:32:00 -08:00
parent c54e6b7b3a
commit b19af8f57e
2 changed files with 37 additions and 0 deletions

View File

@@ -461,6 +461,24 @@ func runMain() int {
return 1
}
globalConfig.Iter(func(name, val string) (stop bool) {
if _, ok := commands.ConfigOptions[name]; !ok {
cli.Println(color.YellowString("Warning: Unknown global config option '%s'. Use `dolt config --global --unset %s` to remove.", name, name))
}
return false
})
// try verifying contents of local config
localConfig, ok := dEnv.Config.GetConfig(env.LocalConfig)
if ok {
localConfig.Iter(func(name, val string) (stop bool) {
if _, ok := commands.ConfigOptions[name]; !ok {
cli.Println(color.YellowString("Warning: Unknown local config option '%s'. Use `dolt config --local --unset %s` to remove.", name, name))
}
return false
})
}
apr, remainingArgs, subcommandName, err := parseGlobalArgsAndSubCommandName(globalConfig, args)
if err == argparser.ErrHelp {
doltCommand.PrintUsage("dolt")

View File

@@ -53,6 +53,25 @@ teardown() {
[[ "$output" =~ "Config successfully updated" ]] || false
}
@test "config: warning on cli commands if config has nonsense variables" {
dolt config --global --add user.name steph # need to create config_global.json first
echo '{"global":"foo"}' > $DOLT_ROOT_PATH/.dolt/config_global.json
run dolt version
[ "$status" -eq 0 ]
[[ "$output" =~ "Warning: Unknown global config option 'global'. Use \`dolt config --global --unset global\` to remove." ]] || false
dolt config --global --add user.email "you@example.com"
dolt config --global --add user.name "Your Name"
dolt init
dolt config --local --add user.name steph # need to create config.json first
echo '{"local":"bar"}' > .dolt/config.json
run dolt config --list
[ "$status" -eq 0 ]
[[ "$output" =~ "Warning: Unknown global config option 'global'. Use \`dolt config --global --unset global\` to remove." ]] || false
[[ "$output" =~ "Warning: Unknown local config option 'local'. Use \`dolt config --local --unset local\` to remove." ]] || false
}
@test "config: set a global config variable" {
run dolt config --global --add user.name steph
[ "$status" -eq 0 ]