Skip to content

Commit

Permalink
[env] Fixed env_from bug when it is called from a subdirectory (#2355)
Browse files Browse the repository at this point in the history
## 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
  • Loading branch information
mohsenari authored Oct 16, 2024
1 parent 8205c25 commit 02a719f
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions internal/devconfig/configfile/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@ func (c *ConfigFile) ParseEnvsFromDotEnv() (map[string]string, error) {
if !c.IsdotEnvEnabled() {
return nil, fmt.Errorf("env file does not have a .env extension")
}

file, err := os.Open(c.EnvFrom)
envFileAbsPath := c.EnvFrom
if !filepath.IsAbs(c.EnvFrom) {
envFileAbsPath = filepath.Join(filepath.Dir(c.AbsRootPath), c.EnvFrom)
}
file, err := os.Open(envFileAbsPath)
if err != nil {
return nil, fmt.Errorf("failed to open file: %s", c.EnvFrom)
return nil, fmt.Errorf("failed to open file: %s", envFileAbsPath)
}
defer file.Close()

Expand Down

0 comments on commit 02a719f

Please sign in to comment.