on main help sign in
fix: only enable watcher for git repos (#1060)
commite2e952b1ab297774145897de1c0d28eebda13bb3 authorRaphael Amorim <rapha850@gmail.com> dateTue 16 Sep 2025, 20:10 (1 year ago) parenta9d3080
1 file changed+19−3
internal/app/app.go+19−3
internal/app/app.go+19−3
@@ -7,6 +7,8 @@ import (
77 "fmt"
88 "log/slog"
99 "maps"
10+ "os/exec"
11+ "strings"
1012 "sync"
1113 "time"
1214
@@ -54,6 +56,16 @@ type App struct {
5456 cleanupFuncs []func() error
5557}
5658
59+// isGitRepo checks if the current directory is a git repository
60+func isGitRepo() bool {
61+ bts, err := exec.CommandContext(
62+ context.Background(),
63+ "git", "rev-parse",
64+ "--is-inside-work-tree",
65+ ).CombinedOutput()
66+ return err == nil && strings.TrimSpace(string(bts)) == "true"
67+}
68+
5769// New initializes a new applcation instance.
5870func New(ctx context.Context, conn *sql.DB, cfg *config.Config) (*App, error) {
5971 q := db.New(conn)
@@ -86,9 +98,13 @@ func New(ctx context.Context, conn *sql.DB, cfg *config.Config) (*App, error) {
8698
8799 app.setupEvents()
88100
89− // Start the global watcher
90− if err := watcher.Start(); err != nil {
91− return nil, fmt.Errorf("app: %w", err)
101+ // Start the global watcher only if this is a git repository
102+ if isGitRepo() {
103+ if err := watcher.Start(); err != nil {
104+ return nil, fmt.Errorf("app: %w", err)
105+ }
106+ } else {
107+ slog.Warn("Not starting global watcher: not a git repository")
92108 }
93109
94110 // Initialize LSP clients in the background.