feat(canola-git): fix subdirectory signs, add watcher and porcelain highlights #37

Merged
barrettruth merged 1 commit from feat/canola-git-subdir-status into main 2026-03-23 16:20:56 +00:00
barrettruth commented 2026-03-23 15:59:28 +00:00

Problem

git status --porcelain outputs paths relative to the repo root, but
populate_cache fed them through first_component as-is. At the repo root
this worked by coincidence; in any subdirectory the prefix mismatch meant
cache.status keys never matched entry names, so signs were silently absent.

Solution

Compute the relative prefix between the browsed directory and the repo root,
strip it from each porcelain path before first_component. Also adds three
complementary improvements:

  • .git directory watcher via vim.uv.new_fs_event — watches for
    index/HEAD changes with 300ms debounce, only invalidates when a canola
    buffer is visible. Handles worktree .git files. Provides real-time
    updates for the terminal-split workflow where neither FocusGained nor
    BufEnter fires.
  • BufEnter TTL — skips re-query if cache is <2s old, eliminating
    redundant subprocess spawns on rapid buffer switching.
  • Porcelain range-based highlightsporcelain format now renders
    index (X) and worktree (Y) characters with distinct highlight groups via
    HlRangeTuple, e.g. staged-add + unstaged-modify shows A in
    DiagnosticOk and M in DiagnosticWarn.
  • get_status() enrichment — adds index and worktree convenience
    fields so consumers don't need to parse the raw porcelain XY pair.
## Problem `git status --porcelain` outputs paths relative to the repo root, but `populate_cache` fed them through `first_component` as-is. At the repo root this worked by coincidence; in any subdirectory the prefix mismatch meant `cache.status` keys never matched entry names, so signs were silently absent. ## Solution Compute the relative prefix between the browsed directory and the repo root, strip it from each porcelain path before `first_component`. Also adds three complementary improvements: - **`.git` directory watcher** via `vim.uv.new_fs_event` — watches for `index`/`HEAD` changes with 300ms debounce, only invalidates when a canola buffer is visible. Handles worktree `.git` files. Provides real-time updates for the terminal-split workflow where neither `FocusGained` nor `BufEnter` fires. - **`BufEnter` TTL** — skips re-query if cache is <2s old, eliminating redundant subprocess spawns on rapid buffer switching. - **Porcelain range-based highlights** — `porcelain` format now renders index (X) and worktree (Y) characters with distinct highlight groups via `HlRangeTuple`, e.g. staged-add + unstaged-modify shows `A` in `DiagnosticOk` and `M` in `DiagnosticWarn`. - **`get_status()` enrichment** — adds `index` and `worktree` convenience fields so consumers don't need to parse the raw porcelain XY pair.
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
barrettruth/canola-collection!37
No description provided.