From 77fbd5b89c4c62ecbf26ec770af0abbc77079a02 Mon Sep 17 00:00:00 2001 From: Tugdual Saunier Date: Thu, 28 Nov 2024 19:34:02 +0100 Subject: [PATCH] Fix project directory guessing is not traversing tree upward --- envs/local.go | 19 +------------------ local/php/symfony.go | 30 ++++++++++++++++++++---------- 2 files changed, 21 insertions(+), 28 deletions(-) diff --git a/envs/local.go b/envs/local.go index b687f7c8..2eee8089 100644 --- a/envs/local.go +++ b/envs/local.go @@ -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 } @@ -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 "" -} diff --git a/local/php/symfony.go b/local/php/symfony.go index 14e83c22..4ae705f0 100644 --- a/local/php/symfony.go +++ b/local/php/symfony.go @@ -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") }