diff --git a/go/cmd/dolt/cli/command.go b/go/cmd/dolt/cli/command.go index f349ac4f9f..806fdaf9db 100644 --- a/go/cmd/dolt/cli/command.go +++ b/go/cmd/dolt/cli/command.go @@ -257,27 +257,26 @@ Run to set your account's default identity. Omit --global to set the identity only in this repository. -fatal: empty ident name not allowed` +fatal: empty ident name not allowed +` ) // CheckUserNameAndEmail returns true if the user name and email are set for this environment, or prints an error and // returns false if not. func CheckUserNameAndEmail(dEnv *env.DoltEnv) bool { - ok := true - _, err := dEnv.Config.GetString(env.UserEmailKey) if err != nil { PrintErr(userNameRequiredError) - ok = false + return false } _, err = dEnv.Config.GetString(env.UserNameKey) if err != nil { PrintErr(userNameRequiredError) - ok = false + return false } - return ok + return true } func (hc SubCommandHandler) printUsage(commandStr string) { diff --git a/go/cmd/dolt/commands/commit.go b/go/cmd/dolt/commands/commit.go index 0b18262a4f..dce19d64f0 100644 --- a/go/cmd/dolt/commands/commit.go +++ b/go/cmd/dolt/commands/commit.go @@ -76,6 +76,11 @@ func (cmd CommitCmd) Exec(ctx context.Context, commandStr string, args []string, help, usage := cli.HelpAndUsagePrinters(cli.GetCommandDocumentation(commandStr, commitDocs, ap)) apr := cli.ParseArgsOrDie(ap, args, help) + // This command creates a commit, so we need user identity + if !cli.CheckUserNameAndEmail(dEnv) { + return 1 + } + // Check if the -all param is provided. Stage all tables if so. allFlag := apr.Contains(cli.AllFlag) diff --git a/go/cmd/dolt/commands/config.go b/go/cmd/dolt/commands/config.go index 240dbfbdbc..b5ad5b0666 100644 --- a/go/cmd/dolt/commands/config.go +++ b/go/cmd/dolt/commands/config.go @@ -142,17 +142,27 @@ func getOperation(dEnv *env.DoltEnv, setCfgTypes *set.StrSet, args []string, pri return 1 } - cfgTypesSl := setCfgTypes.AsSlice() - for _, cfgType := range cfgTypesSl { - if _, ok := dEnv.Config.GetConfig(newCfgElement(cfgType)); !ok { - cli.PrintErrln(color.RedString("Unable to read config.")) + var cfg config.ReadableConfig + switch setCfgTypes.Size() { + case 0: + cfg = dEnv.Config + case 1: + configElement := newCfgElement(setCfgTypes.AsSlice()[0]) + var ok bool + cfg, ok = dEnv.Config.GetConfig(configElement) + if !ok { + cli.Println(color.RedString("No config found for %s", configElement.String())) return 1 } + default: + // should be impossible due to earlier checks + cli.Println(color.RedString("Cannot get more than one config scope at once")) + return 1 } - val, err := dEnv.Config.GetString(args[0]) + val, err := cfg.GetString(args[0]) if err != nil { - if err == config.ErrConfigParamNotFound { + if err != config.ErrConfigParamNotFound { cli.PrintErrln(color.RedString("Unexpected error: %s", err.Error())) } // Not found prints no error but returns status 1