Updated error message for missing identity to match git

This commit is contained in:
Zach Musgrave
2021-11-09 13:28:32 -08:00
parent b3eaff2ec1
commit 42b42fcfe1
4 changed files with 33 additions and 3 deletions

View File

@@ -16,7 +16,6 @@ package cli
import (
"context"
"fmt"
"io"
"os"
"os/signal"
@@ -245,6 +244,22 @@ func CheckEnvIsValid(dEnv *env.DoltEnv) bool {
return true
}
const (
userNameRequiredError = `Author identity unknown
*** Please tell me who you are.
Run
dolt config --global user.email "you@example.com"
dolt config --global user.name "Your Name"
to set your account's default identity.
Omit --global to set the identity only in this repository.
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 {
@@ -252,13 +267,13 @@ func CheckUserNameAndEmail(dEnv *env.DoltEnv) bool {
_, err := dEnv.Config.GetString(env.UserEmailKey)
if err != nil {
PrintErrln(color.RedString(fmt.Sprintf("No config found for required key %s, use dolt config --add %s <your email>", env.UserEmailKey, env.UserEmailKey)))
PrintErr(userNameRequiredError)
ok = false
}
_, err = dEnv.Config.GetString(env.UserNameKey)
if err != nil {
PrintErrln(color.RedString(fmt.Sprintf("No config found for required key %s, use dolt config --add %s <your name>", env.UserNameKey, env.UserNameKey)))
PrintErr(userNameRequiredError)
ok = false
}

View File

@@ -91,6 +91,11 @@ func (cmd InitCmd) Exec(ctx context.Context, commandStr string, args []string, d
return 1
}
// This command creates a commit, so we need user identity
if !cli.CheckUserNameAndEmail(dEnv) {
return 1
}
name, _ := apr.GetValue(usernameParamName)
email, _ := apr.GetValue(emailParamName)
initBranch, _ := apr.GetValue(initBranchParamName)

View File

@@ -84,6 +84,11 @@ func (cmd MergeCmd) Exec(ctx context.Context, commandStr string, args []string,
return 1
}
// This command may create a commit, so we need user identity
if !cli.CheckUserNameAndEmail(dEnv) {
return 1
}
var verr errhand.VerboseError
if apr.Contains(cli.AbortParam) {
mergeActive, err := dEnv.IsMergeActive(ctx)

View File

@@ -67,6 +67,11 @@ func (cmd RevertCmd) 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
}
if apr.NArg() < 1 {
usage()
return 1