Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8570e11

Browse filesBrowse files
authored
Merge pull request #555 from symfony-cli/project-dir-fix
Fix project directory guessing is not traversing tree upward
2 parents 0728657 + 77fbd5b commit 8570e11
Copy full SHA for 8570e11

File tree

2 files changed

+21
-28
lines changed
Filter options

2 files changed

+21
-28
lines changed

‎envs/local.go

Copy file name to clipboardExpand all lines: envs/local.go
+1-18Lines 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

Copy file name to clipboardExpand all lines: local/php/symfony.go
+20-10Lines 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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.