Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix project directory guessing is not traversing tree upward #555

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 1 addition & 18 deletions envs/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func NewLocal(path string, debug bool) (*Local, error) {
return nil, errors.WithStack(err)
}
return &Local{
Dir: guessProjectDir(path),
Dir: path,
Debug: debug,
}, nil
}
Expand Down Expand Up @@ -283,20 +283,3 @@ func (l *Local) webServer() Envs {

return env
}

func guessProjectDir(dir string) string {
for {
f, err := os.Stat(filepath.Join(dir, ".git"))
if err == nil && f.IsDir() {
return dir
}

upDir := filepath.Dir(dir)
if upDir == dir || upDir == "." {
break
}
dir = upDir
}

return ""
}
30 changes: 20 additions & 10 deletions local/php/symfony.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,34 @@ import (
"os"

"github.com/pkg/errors"
"path/filepath"
)

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

if _, err := os.Stat(consolePath); err != nil {
// Fallback to app/console for projects created with older versions of Symfony
consolePath = "app/console"
for {
for _, consolePath := range []string{"bin/console", "app/console"} {
consolePath = filepath.Join(dir, consolePath)
if _, err := os.Stat(consolePath); err == nil {
return &Executor{
BinName: "php",
Args: append([]string{"php", consolePath}, args...),
}, nil
}
}

if _, err2 := os.Stat(consolePath); err2 != nil {
return nil, errors.WithStack(err)
upDir := filepath.Dir(dir)
if upDir == dir || upDir == "." {
break
}
dir = upDir
}

return &Executor{
BinName: "php",
Args: append([]string{"php", consolePath}, args...),
}, nil
return nil, errors.New("No console binary found")
}
Loading