Skip to content

Commit 02a719f

Browse files
authored
[env] Fixed env_from bug when it is called from a subdirectory (#2355)
## Summary Fixes this bug: https://github.com/jetify-com/devbox/pull/2174/files#r1659165116 ## How was it tested? - use compiled devbox - put `export FOO = 'BBBAR'` in .env file - put the following in a devbox.json file ```json { "packages": [], "shell": { "init_hook": [ "echo 'Welcome to devbox!' > /dev/null" ], "scripts": { "test": [ "echo $FOO" ] } }, "env_from": ".env" } ``` - create a subdirectory besides devbox.json called `test` - cd test && devbox run test
1 parent 8205c25 commit 02a719f

File tree

1 file changed

+6
-3
lines changed
  • internal/devconfig/configfile

1 file changed

+6
-3
lines changed

internal/devconfig/configfile/env.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,13 @@ func (c *ConfigFile) ParseEnvsFromDotEnv() (map[string]string, error) {
2525
if !c.IsdotEnvEnabled() {
2626
return nil, fmt.Errorf("env file does not have a .env extension")
2727
}
28-
29-
file, err := os.Open(c.EnvFrom)
28+
envFileAbsPath := c.EnvFrom
29+
if !filepath.IsAbs(c.EnvFrom) {
30+
envFileAbsPath = filepath.Join(filepath.Dir(c.AbsRootPath), c.EnvFrom)
31+
}
32+
file, err := os.Open(envFileAbsPath)
3033
if err != nil {
31-
return nil, fmt.Errorf("failed to open file: %s", c.EnvFrom)
34+
return nil, fmt.Errorf("failed to open file: %s", envFileAbsPath)
3235
}
3336
defer file.Close()
3437

0 commit comments

Comments
 (0)