@@ -318,26 +318,30 @@ func runGenerateDirenvCmd(cmd *cobra.Command, flags *generateCmdFlags) error {
318
318
// working directory when provided to this function. However, since the config file will ultimately
319
319
// be relative to the .envrc file, we need to determine the relative path from envrcDir to configDir.
320
320
func determineDirenvDirs (configDir , envrcDir string ) (string , string , error ) {
321
- // If envrcDir is specified, use it as the directory for .envrc and
322
- // then determine configDir relative to that.
323
- if envrcDir != "" {
324
- if configDir == "" {
325
- return "" , envrcDir , nil
326
- }
327
-
328
- relativeConfigDir , err := filepath .Rel (envrcDir , configDir )
329
- if err != nil {
330
- return "" , "" , errors .Wrapf (err , "failed to determine relative path from %s to %s" , envrcDir , configDir )
331
- }
332
-
333
- // If the relative path is ".", it means configDir is the same as envrcDir.
334
- if relativeConfigDir == "." {
335
- relativeConfigDir = ""
336
- }
337
-
338
- return relativeConfigDir , envrcDir , nil
339
- }
340
321
// If envrcDir is not specified, we will use the configDir as the location for .envrc. This is
341
322
// for backward compatibility (prior to the --envrc-dir flag being introduced).
342
- return "" , configDir , nil
323
+ if envrcDir == "" {
324
+ return "" , configDir , nil
325
+ }
326
+
327
+ // If no configDir is specified, it will be assumed to be in the same directory as the .envrc file
328
+ // which means we can just return an empty configDir.
329
+ if configDir == "" {
330
+ return "" , envrcDir , nil
331
+ }
332
+
333
+ relativeConfigDir , err := filepath .Rel (envrcDir , configDir )
334
+ if err != nil {
335
+ return "" , "" , errors .Wrapf (err , "failed to determine relative path from %s to %s" , envrcDir , configDir )
336
+ }
337
+
338
+ // If the relative path is ".", it means configDir is the same as envrcDir. Leaving it as "."
339
+ // will result in the .envrc containing "--config .", which is fine, but unnecessary and also
340
+ // a change from the previous behavior. So we will return an empty string for relativeConfigDir
341
+ // which will result in the .envrc file not containing the "--config" flag at all.
342
+ if relativeConfigDir == "." {
343
+ relativeConfigDir = ""
344
+ }
345
+
346
+ return relativeConfigDir , envrcDir , nil
343
347
}
0 commit comments