Skip to content

Commit c11672f

Browse files
committed
Envs should be overridable
System-wide environment variable should have priority. That's how it works for .env files, so this is consistent. Closes #425
1 parent e086b65 commit c11672f

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
## Unreleased
44

5+
- Fixed a bug where an environment in a Taskfile was not always overridable
6+
by the system environment
7+
([#425](https://github.com/go-task/task/issues/425)).
58
- Fixed environment from .env files not being available as variables
69
([#379](https://github.com/go-task/task/issues/379)).
710

task.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,10 +397,19 @@ func getEnviron(t *taskfile.Task) []string {
397397
}
398398

399399
environ := os.Environ()
400+
400401
for k, v := range t.Env.ToCacheMap() {
401-
if s, ok := v.(string); ok {
402-
environ = append(environ, fmt.Sprintf("%s=%s", k, s))
402+
str, isString := v.(string)
403+
if !isString {
404+
continue
405+
}
406+
407+
if _, alreadySet := os.LookupEnv(k); alreadySet {
408+
continue
403409
}
410+
411+
environ = append(environ, fmt.Sprintf("%s=%s", k, str))
404412
}
413+
405414
return environ
406415
}

0 commit comments

Comments
 (0)