feat: add --commit flag to restart command when git HEAD changes#36
Merged
Conversation
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. |
- 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.
--commit flag to restart on git HEAD changes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add
--commitflag toWatchthat monitors git directory and restartscommand when active commit (HEAD) changes.
Closes #35
Implementation
git rev-parse --git-dir— handles worktrees andsubmodules transparently
notifywatcher alongside anyuser-specified paths
WatchEventHandler; onlyre-check HEAD on debounce timeout when all pending changes are git-internal
git rev-parse HEADto after debounce period — avoids redundantgit calls on intermediate ref writes
Behavioral changes
is_hidden_pathno longer filters paths under explicitly-watched hiddendirectories (e.g.
--commitadds.git/to watch paths)Event::ChangeDetectednow carries agit: booldiscriminant so theevent loop can distinguish git-internal changes from file changes