10000 Fix project directory guessing is not traversing tree upward · symfony-cli/symfony-cli@77fbd5b · GitHub
[go: up one dir, main page]

Skip to content

Commit 77fbd5b

Browse files
tucksaunfabpot
authored andcommitted
Fix project directory guessing is not traversing tree upward
1 parent 66695f2 commit 77fbd5b

File tree

2 files changed

+21
-28
lines changed

2 files changed

+21
-28
lines changed

envs/local.go

Lines changed: 1 addition & 18 deletions
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: guessProjectDir(path),
51+
Dir: path,
5252
Debug: debug,
5353
}, nil
5454
}
@@ -283,20 +283,3 @@ 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-
}

local/php/symfony.go

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,34 @@ import (
44
"os"
55

66
"github.com/pkg/errors"
7+
"path/filepath"
78
)
89

910
// ComposerExecutor returns an Executor prepared to run Symfony Console.
1011
// It returns an error if no console binary is found.
1112
func SymonyConsoleExecutor(args []string) (*Executor, error) {
12-
consolePath := "bin/console"
13+
dir, err := os.Getwd()
14+
if err != nil {
15+
return nil, errors.WithStack(err)
16+
}
1317

14-
if _, err := os.Stat(consolePath); err != nil {
15-
// Fallback to app/console for projects created with older versions of Symfony
16-
consolePath = "app/console"
18+
for {
19+
for _, consolePath := range []string{"bin/console", "app/console"} {
20+
consolePath = filepath.Join(dir, consolePath)
21+
if _, err := os.Stat(consolePath); err == nil {
22+
return &Executor{
23+
BinName: "php",
24+
Args: append([]string{"php", consolePath}, args...),
25+
}, nil
26+
}
27+
}
1728

18-
if _, err2 := os.Stat(consolePath); err2 != nil {
19-
return nil, errors.WithStack(err)
29+
upDir := filepath.Dir(dir)
30+
if upDir == dir || upDir == "." {
31+
break
2032
}
33+
dir = upDir
2134
}
2235

23-
return &Executor{
24-
BinName: "php",
25-
Args: append([]string{"php", consolePath}, args...),
26-
}, nil
36+
return nil, errors.New("No console binary found")
2737
}

0 commit comments

Comments
 (0)
0