If I've understood things correctly then, as far as possible, a dotenv .env directive in .envrc should result in the same environment as doing source .env by hand in the shell.
However, commented out lines in .env files sourced by a dotenv directive in .envrc are processed as if they were uncommented. They should be ignored.
$ cat direnvtest/.envrc
dotenv .env
$ cat direnvtest/.env
export FOO=bar
# export FOO=baz
$ cd direnvtest/
direnv: loading ~/.direnvrc
direnv: loading .envrc
direnv: export +FOO
$ echo $FOO
baz
Note that the commented out second line of .env has been sourced.
If sourced by hand you get the correct behaviour:
$ source .env
$ echo $FOO
bar
You also get the "correct" behaviour, i.e. matching source .env in the shell, if you put source .env as a directive in .envrc.
It's a bug in the cmd_dotenv.go parser.
Thanks for the report, fixed in master
Thanks! Fixes the case I reported, but it doesn't truncate lines that have comments somewhere other than the first character:
$ cat direnvtest/.env
FOO=baz # This is a comment
$ cd direnvtest/
$ echo $FOO
baz # This is a comment
$ source .env
$ echo $FOO
baz
Should I open another issue @zimbatm?
Opps yeah, feel free to open another ticket for that. My parser is quite hacky so I don't know how fast I can get this fixed though.