Skip to content

Commit 561fdee

Browse files
authored
Merge pull request #326 from roots/more-flexible-project-detection
Project detection: drop site folder requirement
2 parents 271cf69 + 281bc78 commit 561fdee

File tree

2 files changed

+18
-27
lines changed

2 files changed

+18
-27
lines changed

trellis/detector.go

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,46 +19,41 @@ or stop at the root and give up.
1919
func (p *ProjectDetector) Detect(path string) (projectPath string, ok bool) {
2020
configPaths, _ := filepath.Glob(filepath.Join(path, GlobPattern))
2121

22-
if len(configPaths) == 0 {
23-
if p.detectTrellisCLIProject(path) {
24-
return filepath.Join(path, "trellis"), true
25-
}
22+
if len(configPaths) > 0 {
23+
return path, true
24+
}
2625

27-
parent := filepath.Dir(path)
26+
trellisPath, ok := p.detectTrellisCLIProject(path)
27+
if ok {
28+
return trellisPath, true
29+
}
2830

29-
if len(parent) == 1 && (parent == "." || os.IsPathSeparator(parent[0])) {
30-
return "", false
31-
}
31+
parent := filepath.Dir(path)
3232

33-
return p.Detect(parent)
33+
if len(parent) == 1 && (parent == "." || os.IsPathSeparator(parent[0])) {
34+
return "", false
3435
}
3536

36-
return path, true
37+
return p.Detect(parent)
3738
}
3839

39-
func (p *ProjectDetector) detectTrellisCLIProject(path string) bool {
40-
trellisPath := filepath.Join(path, "trellis")
41-
sitePath := filepath.Join(path, "site")
40+
func (p *ProjectDetector) detectTrellisCLIProject(path string) (trellisPath string, ok bool) {
41+
trellisPath = filepath.Join(path, "trellis")
4242
configPath := filepath.Join(trellisPath, ConfigDir)
4343

4444
trellisDir, err := os.Stat(trellisPath)
4545
if err != nil {
46-
return false
46+
return "", false
4747
}
4848

4949
configDir, err := os.Stat(configPath)
5050
if err != nil {
51-
return false
52-
}
53-
54-
siteDir, err := os.Stat(sitePath)
55-
if err != nil {
56-
return false
51+
return "", false
5752
}
5853

59-
if trellisDir.Mode().IsDir() && siteDir.Mode().IsDir() && configDir.Mode().IsDir() {
60-
return true
54+
if trellisDir.Mode().IsDir() && configDir.Mode().IsDir() {
55+
return trellisPath, true
6156
}
6257

63-
return false
58+
return "", false
6459
}

trellis/detector_test.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ import (
66
"testing"
77
)
88

9-
const testDir = "tmp"
10-
119
func TestDetect(t *testing.T) {
1210
testDir := t.TempDir()
1311

@@ -69,10 +67,8 @@ func TestDetectTrellisProjectStructure(t *testing.T) {
6967

7068
trellisDir := filepath.Join(testDir, "trellis")
7169
siteDir := filepath.Join(testDir, "site")
72-
7370
os.Mkdir(trellisDir, 0700)
7471
os.Mkdir(siteDir, 0700)
75-
7672
os.Mkdir(filepath.Join(trellisDir, ConfigDir), 0700)
7773

7874
devDir := filepath.Join(trellisDir, "group_vars", "development")

0 commit comments

Comments
 (0)