mirror of
https://github.com/dolthub/dolt.git
synced 2026-02-11 18:49:14 -06:00
no panic if HOME does not exist (#2148)
* no home dir exist * dolt root can be empty * move test to bottom * dir -> directory * Windows complaining about smth
This commit is contained in:
committed by
GitHub
parent
2752b0d13e
commit
47a4640e4c
@@ -236,6 +236,7 @@ func runMain() int {
|
||||
root, err := env.GetCurrentUserHomeDir()
|
||||
|
||||
if err != nil {
|
||||
cli.PrintErrln(color.RedString("Failed to load the HOME directory: %v", err))
|
||||
return 1
|
||||
}
|
||||
|
||||
|
||||
15
go/libraries/doltcore/env/paths.go
vendored
15
go/libraries/doltcore/env/paths.go
vendored
@@ -44,14 +44,21 @@ func GetCurrentUserHomeDir() (string, error) {
|
||||
if doltRootPath, ok := os.LookupEnv(doltRootPathEnvVar); ok && doltRootPath != "" {
|
||||
return doltRootPath, nil
|
||||
}
|
||||
|
||||
var home string
|
||||
if homeEnvPath, ok := os.LookupEnv(homeEnvVar); ok && homeEnvPath != "" {
|
||||
return homeEnvPath, nil
|
||||
}
|
||||
if usr, err := user.Current(); err != nil {
|
||||
home = homeEnvPath
|
||||
} else if usr, err := user.Current(); err != nil {
|
||||
return "", err
|
||||
} else {
|
||||
return usr.HomeDir, nil
|
||||
home = usr.HomeDir
|
||||
}
|
||||
|
||||
_, err := os.Stat(home)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return home, nil
|
||||
}
|
||||
|
||||
func getCredsDir(hdp HomeDirProvider) (string, error) {
|
||||
|
||||
@@ -272,3 +272,13 @@ NOT_VALID_REPO_ERROR="The current directory is not a valid dolt repository."
|
||||
run dolt checkout help
|
||||
[ "$status" -ne 0 ]
|
||||
}
|
||||
|
||||
@test "no-repo: don't panic if invalid HOME" {
|
||||
DOLT_ROOT_PATH=
|
||||
HOME=/this/is/garbage
|
||||
run dolt
|
||||
[ "$status" -eq 1 ]
|
||||
[[ ! "$output" =~ "panic" ]]
|
||||
[[ "$output" =~ "Failed to load the HOME directory" ]]
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user