From 7651fbc87498a30ecc2545a8038aa06d9a6d897a Mon Sep 17 00:00:00 2001 From: Alex Jank Date: Tue, 17 Dec 2024 11:28:48 +0100 Subject: [PATCH 1/2] feat(local): guess project dir based on presence of .symfony.local.yaml --- envs/local.go | 5 +++-- envs/local_test.go | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/envs/local.go b/envs/local.go index b687f7c8..79ad5d07 100644 --- a/envs/local.go +++ b/envs/local.go @@ -286,8 +286,9 @@ func (l *Local) webServer() Envs { func guessProjectDir(dir string) string { for { - f, err := os.Stat(filepath.Join(dir, ".git")) - if err == nil && f.IsDir() { + gitDir, gitDirErr := os.Stat(filepath.Join(dir, ".git")) + cliConfigFile, cliConfigFileErr := os.Stat(filepath.Join(dir, ".symfony.local.yaml")) + if (gitDirErr == nil && gitDir.IsDir()) || (cliConfigFileErr == nil && !cliConfigFile.IsDir()) { return dir } diff --git a/envs/local_test.go b/envs/local_test.go index 68fd5163..1c98c3f3 100644 --- a/envs/local_test.go +++ b/envs/local_test.go @@ -98,3 +98,40 @@ func (s *LocalSuite) TestRelationships(c *C) { "PGHOST": "127.0.0.1", }) } + +func (s *LocalSuite) TestProjectDirGuessingMissingGitAndConfig(c *C) { + l, err := NewLocal("testdata/project", false) + expectedLocalDir, err := filepath.Abs(".") + expectedLocalDir = filepath.Dir(expectedLocalDir) + c.Assert(err, IsNil) + c.Assert(l.Dir, Equals, expectedLocalDir) +} + +func (s *LocalSuite) TestGitProjectDirGuessing(c *C) { + os.Rename("testdata/project/git", "testdata/project/.git") + defer os.Rename("testdata/project/.git", "testdata/project/git") + homedir.Reset() + os.Setenv("HOME", "testdata/project") + defer homedir.Reset() + + l, err := NewLocal("testdata/project", false) + + expectedLocalDir, err := filepath.Abs("testdata/project") + c.Assert(err, IsNil) + c.Assert(l.Dir, Equals, expectedLocalDir) +} + +func (s *LocalSuite) TestConfigProjectDirGuessing(c *C) { + configFilePath := "testdata/project/.symfony.local.yaml" + os.WriteFile(configFilePath, make([]byte, 0), 0644) + defer os.Remove(configFilePath) + homedir.Reset() + os.Setenv("HOME", "testdata/project") + defer homedir.Reset() + + l, err := NewLocal("testdata/project", false) + + expectedLocalDir, err := filepath.Abs("testdata/project") + c.Assert(err, IsNil) + c.Assert(l.Dir, Equals, expectedLocalDir) +} From 8f3289d164a0f26f0cbb50127f76d86f5a92609e Mon Sep 17 00:00:00 2001 From: Alex Jank Date: Thu, 19 Dec 2024 11:22:49 +0100 Subject: [PATCH 2/2] feat(local): guess project dir based on presence of symfony.lock see #550 for discussion --- envs/local.go | 3 ++- envs/local_test.go | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/envs/local.go b/envs/local.go index 79ad5d07..f52a165d 100644 --- a/envs/local.go +++ b/envs/local.go @@ -288,7 +288,8 @@ func guessProjectDir(dir string) string { for { gitDir, gitDirErr := os.Stat(filepath.Join(dir, ".git")) cliConfigFile, cliConfigFileErr := os.Stat(filepath.Join(dir, ".symfony.local.yaml")) - if (gitDirErr == nil && gitDir.IsDir()) || (cliConfigFileErr == nil && !cliConfigFile.IsDir()) { + symfonyLockFile, symfonyLockFileErr := os.Stat(filepath.Join(dir, "symfony.lock")) + if (gitDirErr == nil && gitDir.IsDir()) || (cliConfigFileErr == nil && !cliConfigFile.IsDir()) || (symfonyLockFileErr == nil && !symfonyLockFile.IsDir()) { return dir } diff --git a/envs/local_test.go b/envs/local_test.go index 1c98c3f3..519a821c 100644 --- a/envs/local_test.go +++ b/envs/local_test.go @@ -135,3 +135,18 @@ func (s *LocalSuite) TestConfigProjectDirGuessing(c *C) { c.Assert(err, IsNil) c.Assert(l.Dir, Equals, expectedLocalDir) } + +func (s *LocalSuite) TestSymfonyLockProjectDirGuessing(c *C) { + configFilePath := "testdata/project/symfony.lock" + os.WriteFile(configFilePath, make([]byte, 0), 0644) + defer os.Remove(configFilePath) + homedir.Reset() + os.Setenv("HOME", "testdata/project") + defer homedir.Reset() + + l, err := NewLocal("testdata/project", false) + + expectedLocalDir, err := filepath.Abs("testdata/project") + c.Assert(err, IsNil) + c.Assert(l.Dir, Equals, expectedLocalDir) +} pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy