Skip to content

feat: detect git worktrees (opt-in toggle) #24

@steven-pribilinskiy

Description

@steven-pribilinskiy

Problem

git-scope only detects regular git repositories — directories that contain a .git/ folder. Linked git worktrees (created with git worktree add) are skipped entirely, because in a worktree the .git entry is a file containing a gitdir: pointer to the main repo's worktrees/<name>/ directory, not a directory.

This is a real gap for anyone who uses worktrees for parallel branches (e.g. one tree per in-flight feature). Today those trees are invisible in the dashboard and don't contribute to the dirty/clean totals — so a worktree with uncommitted changes is silently missed.

Where it lives

internal/scan/scan.go walks the tree and only matches when:

if d.IsDir() && d.Name() == ".git" {

A worktree's .git entry is d.Type().IsRegular(), so the walker never records it as a repo.

Proposed change

Add opt-in worktree support:

  1. Config flag includeWorktrees: false (default) in ~/.config/git-scope/config.yml.
  2. CLI flag --worktrees for one-shot enable.
  3. TUI keybinding to toggle live (e.g. uppercase W — lowercase w is already taken by the workspace switcher). The toggle controls both visibility AND the totals (📁 N repos, dirty/clean counts) so the table and stats stay consistent.
  4. Scanner: when enabled, also detect .git files (regular files) and treat their parent directory as a repo. git status --porcelain=v2 works in worktrees identically, so internal/gitstatus doesn't need changes.
  5. Model: add an IsWorktree bool field on Repo (omitempty) so the TUI can render a small marker (e.g. next to the name) and so scripted consumers of git-scope scan JSON can distinguish them.
  6. Cache: include the flag in cache validity so toggling forces a fresh scan instead of returning the wrong set from disk.

Why opt-in

  • Default behaviour stays identical — no surprise count changes for current users.
  • Worktree-heavy workflows can be a minority; some users keep many worktrees and don't want them inflating the dashboard.
  • A toggle (key + flag + config) lets each user pick their default and override per-session.

UX

Stats bar today:

📁 12 repos   ● 3 dirty   ✓ 9 clean

With the toggle on:

📁 19 repos (12 + 7 wt)   ● 5 dirty   ✓ 14 clean

Help bar gains: W toggle worktrees.

Happy to send a PR — already have a fork ready.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions