fix: handle case where basePath is "." or current directory

Add check to skip directory change when basePath is "." or already the
current working directory. This fixes test failures with mock filesystems
that don't have "." in their directory list.

Co-authored-by: yxxhero <11087727+yxxhero@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot] 2025-11-28 13:37:50 +00:00
parent 470ce4c6fc
commit e76de84904
2 changed files with 9 additions and 3 deletions

2
go.mod
View File

@ -32,6 +32,7 @@ require (
go.yaml.in/yaml/v3 v3.0.4
golang.org/x/sync v0.18.0
golang.org/x/term v0.37.0
gopkg.in/yaml.v3 v3.0.1
helm.sh/helm/v3 v3.19.2
helm.sh/helm/v4 v4.0.1
k8s.io/apimachinery v0.34.2
@ -323,7 +324,6 @@ require (
gopkg.in/gookit/color.v1 v1.1.6 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/api v0.34.2 // indirect
k8s.io/apiextensions-apiserver v0.34.1 // indirect
k8s.io/apiserver v0.34.1 // indirect

View File

@ -139,9 +139,15 @@ func (ld *EnvironmentValuesLoader) renderInBasePath(value any, r tmpl.TextRender
return nil, fmt.Errorf("failed to get current working directory: %v", err)
}
// If basePath is "." or already the current directory, no need to change
basePath := ld.storage.basePath
if basePath == "." || basePath == cwd {
return ld.renderTemplateExpressions(value, r)
}
// Change to basePath for rendering using the filesystem abstraction
if err := ld.fs.Chdir(ld.storage.basePath); err != nil {
return nil, fmt.Errorf("failed to change to base directory %q: %v", ld.storage.basePath, err)
if err := ld.fs.Chdir(basePath); err != nil {
return nil, fmt.Errorf("failed to change to base directory %q: %v", basePath, err)
}
// Ensure we change back to the original directory