Fixed bug in init and fixed tests

This commit is contained in:
Zach Musgrave
2021-11-09 15:32:35 -08:00
parent 79c78168ea
commit fd9babb2d7
2 changed files with 26 additions and 21 deletions

View File

@@ -91,14 +91,17 @@ 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)
if len(name) == 0 || len(email) == 0 {
// This command creates a commit, so we need user identity
if !cli.CheckUserNameAndEmail(dEnv) {
return 1
}
}
name = dEnv.Config.IfEmptyUseConfig(name, env.UserNameKey)
email = dEnv.Config.IfEmptyUseConfig(email, env.UserEmailKey)
if initBranch == "" {

View File

@@ -58,25 +58,27 @@ func TestInit(t *testing.T) {
}
for _, test := range tests {
dEnv := createUninitializedEnv()
gCfg, _ := dEnv.Config.GetConfig(env.GlobalConfig)
gCfg.SetStrings(test.GlobalConfig)
t.Run(test.Name, func(t *testing.T) {
dEnv := createUninitializedEnv()
gCfg, _ := dEnv.Config.GetConfig(env.GlobalConfig)
gCfg.SetStrings(test.GlobalConfig)
result := InitCmd{}.Exec(context.Background(), "dolt init", test.Args, dEnv)
result := InitCmd{}.Exec(context.Background(), "dolt init", test.Args, dEnv)
if (result == 0) != test.ExpectSuccess {
t.Error(test.Name, "- Expected success:", test.ExpectSuccess, "result:", result == 0)
} else if test.ExpectSuccess {
// succceeded as expected
if !dEnv.HasDoltDir() {
t.Error(test.Name, "- .dolt dir should exist after initialization")
if (result == 0) != test.ExpectSuccess {
t.Error(test.Name, "- Expected success:", test.ExpectSuccess, "result:", result == 0)
} else if test.ExpectSuccess {
// succceeded as expected
if !dEnv.HasDoltDir() {
t.Error(test.Name, "- .dolt dir should exist after initialization")
}
} else {
// failed as expected
if dEnv.HasDoltDir() {
t.Error(test.Name, "- dolt directory shouldn't exist after failure to initialize")
}
}
} else {
// failed as expected
if dEnv.HasDoltDir() {
t.Error(test.Name, "- dolt directory shouldn't exist after failure to initialize")
}
}
})
}
}