diff --git a/go/cmd/dolt/dolt.go b/go/cmd/dolt/dolt.go index d2ecddfe0d..1390473a4a 100644 --- a/go/cmd/dolt/dolt.go +++ b/go/cmd/dolt/dolt.go @@ -510,6 +510,11 @@ func runMain() int { return 1 } + if dEnv.CfgLoadErr != nil { + cli.PrintErrln(color.RedString("Failed to load the global config. %v", dEnv.CfgLoadErr)) + return 1 + } + strMetricsDisabled := dEnv.Config.GetStringOrDefault(config.MetricsDisabled, "false") var metricsEmitter events.Emitter metricsEmitter = events.NewFileEmitter(homeDir, dbfactory.DoltDir) @@ -520,10 +525,6 @@ func runMain() int { events.SetGlobalCollector(events.NewCollector(doltversion.Version, metricsEmitter)) - if dEnv.CfgLoadErr != nil { - cli.PrintErrln(color.RedString("Failed to load the global config. %v", dEnv.CfgLoadErr)) - return 1 - } globalConfig, ok := dEnv.Config.GetConfig(env.GlobalConfig) if !ok { cli.PrintErrln(color.RedString("Failed to get global config")) diff --git a/integration-tests/bats/no-repo.bats b/integration-tests/bats/no-repo.bats index 7b19c59983..3a030fbb70 100755 --- a/integration-tests/bats/no-repo.bats +++ b/integration-tests/bats/no-repo.bats @@ -422,3 +422,46 @@ NOT_VALID_REPO_ERROR="The current directory is not a valid dolt repository." [ "$status" -eq 1 ] [[ "$output" =~ "Unknown Command notarealcommand" ]] || false } + +@test "no-repo: the global dolt directory is not accessible due to permissions" { + noPermissionsDir=$(mktemp -d -t noPermissions-XXXX) + chmod 000 $noPermissionsDir + DOLT_ROOT_PATH=$noPermissionsDir + + run dolt version + [ "$status" -eq 1 ] + [[ "$output" =~ "Failed to load the global config" ]] || false + [[ "$output" =~ "permission denied" ]] || false + + run dolt sql + [ "$status" -eq 1 ] + [[ "$output" =~ "Failed to load the global config" ]] || false + [[ "$output" =~ "permission denied" ]] || false + + run dolt sql-server + [ "$status" -eq 1 ] + [[ "$output" =~ "Failed to load the global config" ]] || false + [[ "$output" =~ "permission denied" ]] || false +} + +@test "no-repo: the global dolt directory is accessible, but not writable" { + noPermissionsDir=$(mktemp -d -t noPermissions-XXXX) + chmod 000 $noPermissionsDir + chmod a+x $noPermissionsDir + DOLT_ROOT_PATH=$noPermissionsDir + + run dolt version + [ "$status" -eq 1 ] + [[ "$output" =~ "Failed to load the global config" ]] || false + [[ "$output" =~ "permission denied" ]] || false + + run dolt sql + [ "$status" -eq 1 ] + [[ "$output" =~ "Failed to load the global config" ]] || false + [[ "$output" =~ "permission denied" ]] || false + + run dolt sql-server + [ "$status" -eq 1 ] + [[ "$output" =~ "Failed to load the global config" ]] || false + [[ "$output" =~ "permission denied" ]] || false +}