Customizing the error message for dolt init when a sql-server is already running from the directory

This commit is contained in:
Jason Fulghum
2024-05-17 11:44:06 -07:00
parent c490affcbb
commit 59b61de70e
2 changed files with 13 additions and 0 deletions
+6
View File
@@ -104,6 +104,12 @@ func (cmd InitCmd) Exec(ctx context.Context, commandStr string, args []string, d
types.Format_Default = types.Format_DOLT
}
if dEnv.HasDoltSqlServerInfo() {
cli.PrintErrln(color.RedString("Detected that a Dolt sql-server is running from this directory. " +
"Stop the sql-server before initializing this directory as a Dolt database."))
return 1
}
name, _ := apr.GetValue(usernameParamName)
email, _ := apr.GetValue(emailParamName)
initBranch, _ := apr.GetValue(initBranchParamName)
+7
View File
@@ -303,6 +303,13 @@ func (dEnv *DoltEnv) HasDoltDataDir() bool {
return exists && isDir
}
// HasDoltSqlServerInfo returns true if this Dolt environment has a sql-server.info file, indicating
// that a sql-server is running from this Dolt environment.
func (dEnv *DoltEnv) HasDoltSqlServerInfo() bool {
exists, _ := dEnv.FS.Exists(filepath.Join(dbfactory.DoltDir, "sql-server.info"))
return exists
}
func (dEnv *DoltEnv) HasDoltTempTableDir() bool {
tmpDir, err := dEnv.TempTableFilesDir()
if err != nil {