Skip to content

widget: Git status #8

Closed
Closed

Description

@unhappychoice

Intent

Self/project context. cd into a git repo → splash shows the state of the working tree at a glance, so you don't have to type `git status` as the first command of every session.

Fetcher kind + safety

  • `Fetcher` (cached). Reading a git directory is local I/O but non-trivial on huge repos; TTL ~30s keeps the splash snappy while still reflecting most real-world edits.
  • `Safety::Safe`. Reads the repo under CWD only, no network, no exec.

Data source

`git2` crate (libgit2 binding). Subprocess `git` is a fallback but adds a process spawn per fetch and makes porting to non-POSIX systems annoying. No subprocess escalation concern since `Safety::Safe` and we don't call custom hooks.

Payload shape

`Body::Entries` with one entry per metric:

key value status
`branch` `feat/realtime-fetcher` —
`dirty` `3 staged, 1 unstaged, 2 untracked` `Warn` if dirty
`ahead_behind` `↑2 ↓0` `Warn` if behind
`stash` `1 stash` — (omit if 0)

Renderer: default `table` / `entries`. Compact mode for small slots via `format = "compact"` option that collapses to a single-line string.

Config schema sketch

```toml
[[widgets]]
id = "git"
fetcher = "git_status"

[widgets.git_status]
repo_root = "." # default: walk up from CWD
ahead_behind_against = "origin/main" # remote-tracking branch; default: upstream of HEAD
show = ["branch", "dirty", "ahead_behind", "stash"] # ordering / filter
```

Design questions

  • Repo detection: walk up from CWD vs explicit path. Default = walk-up so `cd` into a subdir still finds the repo.
  • Detached HEAD: show commit SHA + closest tag instead of branch.
  • Bare repos: skip (render empty) — nothing actionable to show.
  • Worktrees: treat a worktree as a normal repo; `git_worktrees` is a separate candidate widget.
  • No upstream configured: `ahead_behind` is just `—` instead of an error.
  • `ahead_behind` cost: requires a remote-tracking ref, no network call. Cheap.

Related widgets (see #41)

  • git_branch (subset; often redundant with this)
  • git_ahead_behind (subset)
  • git_stash_count (subset)
  • git_recent_commits — separate widget, different payload shape (timeline)
  • git_commits_sparkline — separate widget, different payload shape

Out of scope

  • Hook into `chpwd` / pre-commit to invalidate cache instantly. Nice but not needed — 30s TTL plus the daemon refresh on cd is enough.
  • Multi-repo rollups. If users want that, they can wire multiple instances of this widget.

Activity

  1. added this to the v1.0 milestone on Apr 21, 2026
  2. unhappychoice commented on Apr 21, 2026

    @unhappychoice
    OwnerAuthor

    Consolidating into catalog #41. Individual widget issues turned out to be premature commitments — priority isn't fixed yet and detailed specs belong alongside the PR that actually ships the widget. Progress tracked as checkboxes in #41 instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    widget

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions