Open adhusson opened 1 year ago
this is implemented here, which loads from cwd + (dir(foundry.toml) | gitroot))
perhaps this should do dir(foundry.tml) + gitroot
instead?
Thank you for pointing me to the code, I was mistaken about what forge does.
For my use case, the current behaviour is enough (the important part is cwd + gitroot
). It may be good to do cwd + dir(foundry.toml) + gitroot
anyway though -- I can imagine needing that in the future.
I am applying to this issue via OnlyDust platform.
I have experience with JavaScript and Python, along with a solid understanding of Solidity. My background in open-source projects equips me to effectively implement features and contribute to documentation. I can leverage my skills to enhance the Foundry toolset, ensuring clear communication and functionality for developers.
To approach the problem, I would first locate the root directory of the current git repository by checking for the presence of the .git
folder. Then, I would traverse the parent directories starting from the current working directory to search for a .env
file up to the git root. If found, I would load its contents into the environment. Additionally, I would write tests to ensure that this functionality works as expected and update the documentation to clarify the new behavior. This implementation would enhance the Forge tool's ability to load .env
files in various project structures.
Component
Forge
Describe the feature you would like
Feature description
Mimic the default behavior of the
--root
CLI argument for loading a.env
file and consider up to the root directory of the current git repository in addition to cwd and project root.Context
Since #2604, the
.env
file is only read from 2 places (cwd & project root).When a foundry project is used as a dependency, invocations that need to use a local
.env
file will do e.g.forge script --root path/to/dependency
. But the.env
file may not be in the cwd! It may be located in the root directory of the current git repository.Example:
Here, looking one level above would load the current repo's
.env
file.Additional context
No response