diff --git a/envs/local.go b/envs/local.go index b687f7c8..f52a165d 100644 --- a/envs/local.go +++ b/envs/local.go @@ -286,8 +286,10 @@ 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")) + 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 68fd5163..519a821c 100644 --- a/envs/local_test.go +++ b/envs/local_test.go @@ -98,3 +98,55 @@ 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) +} + +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) +}
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: