From 5ab60313829834a88caf2e60ef8463016b6fe08d Mon Sep 17 00:00:00 2001 From: Mallory Adams Date: Wed, 8 Jul 2020 08:35:22 -0400 Subject: [PATCH] Do not traverse through git repositories (#6) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This makes `git list` a lot faster (10 minutes to under 2 minutes in one test) and displays more useful information. Example of `git list` from before this change demonstrating that `git list` was hiding the information about the main repository in favour of showing information about a `composer` dependency: ``` ├── iguana-extras │   └── vendor │   └── dxw │   └── iguana HEAD ok │ master ok ``` Example from after this change: ``` ├── iguana-extras master [ 1 untracked ] │ feature/readme no upstream │ feature/update-iguana no upstream │ fix/php-cs-fixer no upstream ``` --- pkg/io/io.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pkg/io/io.go b/pkg/io/io.go index df81c92..9bfac0d 100644 --- a/pkg/io/io.go +++ b/pkg/io/io.go @@ -5,6 +5,7 @@ import ( "fmt" "io/ioutil" "os" + "path/filepath" "strings" "syscall" @@ -101,10 +102,19 @@ func (r *RepoFinder) Find() ([]string, error) { } func (r *RepoFinder) walkCb(path string, ent *godirwalk.Dirent) error { + // Do not traverse .git directories if ent.IsDir() && ent.Name() == ".git" { r.repos = append(r.repos, strings.TrimSuffix(path, ".git")) return ErrSkipNode } + // Do not traverse directories containing a .git directory + if ent.IsDir() { + _, err := os.Stat(filepath.Join(path, ".git")) + if err == nil { + r.repos = append(r.repos, strings.TrimSuffix(path, ".git")) + return ErrSkipNode + } + } return nil }