Skip to content

feat: add --commit flag to restart command when git HEAD changes#36

Merged
cecton merged 15 commits into
rustminded:mainfrom
yozhgoor:watch-commits
Jun 22, 2026
Merged

feat: add --commit flag to restart command when git HEAD changes#36
cecton merged 15 commits into
rustminded:mainfrom
yozhgoor:watch-commits

Conversation

@yozhgoor

@yozhgoor yozhgoor commented Jun 14, 2026

Copy link
Copy Markdown
Member

Summary

Add --commit flag to Watch that monitors git directory and restarts
command when active commit (HEAD) changes.

Closes #35

Implementation

  • Resolve git dir via git rev-parse --git-dir — handles worktrees and
    submodules transparently
  • Watch resolved git dir through existing notify watcher alongside any
    user-specified paths
  • Classify events as git vs file changes in WatchEventHandler; only
    re-check HEAD on debounce timeout when all pending changes are git-internal
  • Defer git rev-parse HEAD to after debounce period — avoids redundant
    git calls on intermediate ref writes

Behavioral changes

  • is_hidden_path no longer filters paths under explicitly-watched hidden
    directories (e.g. --commit adds .git/ to watch paths)
  • Event::ChangeDetected now carries a git: bool discriminant so the
    event loop can distinguish git-internal changes from file changes

@cecton

cecton commented Jun 16, 2026

Copy link
Copy Markdown
Member

@yozhgoor can you update your branch? I want to test it in real life but if I use it now I will lose important fixes of 0.3.5.

@yozhgoor yozhgoor requested a review from cecton June 21, 2026 09:10
cecton added 11 commits June 21, 2026 17:32
- Add Watch::is_valid_path helper to consolidate path validity checks.
- Use a peekable iterator instead of collecting valid paths into a Vec.
- Rename valids to valid_paths.
- Differentiate trace messages for ignored events.
Move the early returns into the HEAD-unchanged and HEAD-read-error
branches so that Event::ChangeDetected is sent from a single place.
Move the get_current_head() call (git rev-parse HEAD) from the file
event handler into the main event loop, so it runs at most once per
debounce cycle instead of on every individual filesystem event.

Previously, every notify event targeting the git directory spawned a
git subprocess to check whether HEAD had changed. During a single git
operation (rebase, commit, fetch) this could trigger dozens of redundant
git invocations before the debounce timer even started.

Now the event handler just records the type of change detected (file
change vs git-dir change) via two flags. After the debounce settles,
if only git-dir changes are pending and --commit is on, a single
get_current_head() call confirms whether HEAD actually changed before
spawning the build. Real file changes still bypass the HEAD check
and always trigger a build.
…it/ with --commit)

is_hidden_path was filtering out all paths whose first component (relative
to a watch path) starts with '.'. When --commit adds .git/ to
watch_paths, and a parent of .git/ is also watched, git directory changes
like .git/HEAD were silently dropped.

The fix: if the path lives under a watch path whose own last component
starts with '.', the user explicitly opted into watching it — don't treat
it as hidden.
…ngle variant

Merge two near-identical Event variants (ChangeDetected,
GitDirChangeDetected) into one with a  field.
means real file change (sets has_file_changes),  means git
directory metadata change only (triggers HEAD hash check before build).

Eliminates duplicated cancel-in-progress logic across the two match
arms while preserving the semantic distinction that controls when
the git HEAD staleness check runs.
Hardcodes metadata().workspace_root inside function,
consistent with get_current_head. Single call site
already passed same value.
Failing to read HEAD at startup means --commit cannot work.
Error now propagates via ? like resolve_git_dir, rather than
silently setting current_commit to None which causes a
spurious rebuild on first successful HEAD read.
None means !self.commit — single source of truth
eliminates redundant field check.
Previous entry described a bug fix, not a behavior change.
Entries now more accurately reflect their category.
Stale/deleted path filtering was existing behavior, not a new fix.
@cecton cecton changed the title Add --commit flag to restart on git HEAD changes feat: add --commit flag to restart command when git HEAD changes Jun 22, 2026
@cecton cecton merged commit 937dc22 into rustminded:main Jun 22, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Watch for commits instead of files

2 participants