Skip to content

Commit

Permalink
Detect only directories that are git repos
Browse files Browse the repository at this point in the history
Notes:
- using the more efficient `WalkDir` function
- skip walking directories when detected a repo
  • Loading branch information
carhartl committed Oct 21, 2024
1 parent c70bea8 commit 0971d57
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions cmd/git-unsaved/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,17 @@ func (m model) View() string {

func getRepos(sub chan repoMsg) tea.Cmd {
return func() tea.Msg {
err := filepath.Walk(".", func(path string, info fs.FileInfo, err error) error {
err := filepath.WalkDir(".", func(path string, d fs.DirEntry, err error) error {
if err != nil {
return err
}
if info.IsDir() {
// TODO: filter for git repos
if d.IsDir() && filepath.Base(path) == ".git" {
abspath, err := filepath.Abs(path)
if err != nil {
return err
}
sub <- repoMsg{repo: repo{path: abspath}}
sub <- repoMsg{repo: repo{path: filepath.Dir(abspath)}}
return fs.SkipDir
}
return nil
})
Expand Down

0 comments on commit 0971d57

Please sign in to comment.