@@ -19,46 +19,41 @@ or stop at the root and give up.
1919func (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}
0 commit comments