Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When determining the current project, prefer the activated project before anything else. #2936

Merged
merged 1 commit into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion pkg/projectfile/projectfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -779,13 +779,21 @@ func GetProjectFilePath() (string, error) {
}

func getProjectFilePathFromEnv() (string, error) {
projectFilePath := os.Getenv(constants.ProjectEnvVarName)
var projectFilePath string

if activatedProjectDirPath := os.Getenv(constants.ActivatedStateEnvVarName); activatedProjectDirPath != "" {
projectFilePath = filepath.Join(activatedProjectDirPath, constants.ConfigFileName)
} else {
projectFilePath = os.Getenv(constants.ProjectEnvVarName)
}

if projectFilePath != "" {
if fileutils.FileExists(projectFilePath) {
return projectFilePath, nil
}
return "", &ErrorNoProjectFromEnv{locale.NewInputError("err_project_env_file_not_exist", "", projectFilePath)}
}

return "", nil
}

Expand Down
9 changes: 9 additions & 0 deletions pkg/projectfile/projectfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ func TestGetProjectFilePath(t *testing.T) {
require.Nil(t, err)
expectedPath := filepath.Join(root, "pkg", "projectfile", "testdata", constants.ConfigFileName)
assert.Equal(t, expectedPath, configPath, "Project path is properly detected")
os.Chdir(cwd) // restore

defer os.Unsetenv(constants.ProjectEnvVarName)

Expand Down Expand Up @@ -251,6 +252,14 @@ func TestGetProjectFilePath(t *testing.T) {
configPath, err = GetProjectFilePath()
assert.NoError(t, err, "GetProjectFilePath should succeed")
assert.Equal(t, expectedPath, configPath, "Project path is properly detected using default path from config")

// The activestate.yaml for an activated project should be used no matter what.
defer os.Unsetenv(constants.ActivatedStateEnvVarName)
os.Setenv(constants.ActivatedStateEnvVarName, filepath.Dir(expectedPath))
configPath, err = GetProjectFilePath()
require.Nil(t, err)
assert.Equal(t, expectedPath, configPath, "Project path is properly detected using the ActivatedStateEnvVarName")
os.Unsetenv(constants.ActivatedStateEnvVarName)
}

// TestGet the config
Expand Down
Loading