8000 Fix path on local envs · symfony-cli/symfony-cli@f11e67e · GitHub
[go: up one dir, main page]

Skip to content

Commit f11e67e

Browse files
committed
Fix path on local envs
1 parent 2fde8a5 commit f11e67e

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

envs/local.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func NewLocal(path string, debug bool) (*Local, error) {
4848
return nil, errors.WithStack(err)
4949
}
5050
return &Local{
51-
Dir: path,
51+
Dir: guessProjectDir(path),
5252
Debug: debug,
5353
}, nil
5454
}
@@ -283,3 +283,20 @@ func (l *Local) webServer() Envs {
283283

284284
return env
285285
}
286+
287+
func guessProjectDir(dir string) string {
288+
for {
289+
f, err := os.Stat(filepath.Join(dir, ".git"))
290+
if err == nil && f.IsDir() {
291+
return dir
292+
}
293+
294+
upDir := filepath.Dir(dir)
295+
if upDir == dir || upDir == "." {
296+
break
297+
}
298+
dir = upDir
299+
}
300+
301+
return ""
302+
}

0 commit comments

Comments
 (0)
0