Skip to content

fix(git): avoid optional status locks in watch mode#408

Merged
benvinegar merged 1 commit into
mainfrom
fix/git-watch-status-optional-locks
Jun 9, 2026
Merged

fix(git): avoid optional status locks in watch mode#408
benvinegar merged 1 commit into
mainfrom
fix/git-watch-status-optional-locks

Conversation

@benvinegar

Copy link
Copy Markdown
Member

Summary

  • Run Git's untracked-file status query with --no-optional-locks so watch polling does not refresh the index under an optional lock.
  • Add coverage for the exact status argv used by working-tree untracked discovery.
  • Document the user-visible fix in the changelog.

Fixes #398.

Testing

  • bun test src/core/git.test.ts
  • bun run typecheck
  • bun test
  • Manual watch-mode check with a wrapper git executable confirmed hunk diff --watch now invokes git --no-optional-locks status --porcelain=v1 -z --untracked-files=all for status polling.

This PR description was generated by Pi using OpenAI GPT-5

@greptile-apps

greptile-apps Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes watch-mode index contention by prepending --no-optional-locks to the git status invocation used to discover untracked files, preventing Git from refreshing the index under an optional lock during polling. buildGitStatusArgs is also exported so the new unit test can assert the exact argument list directly.

  • src/core/git.ts: --no-optional-locks is inserted as the first element of the args array (before status), making it a global Git flag; the function is exported to enable direct testing.
  • src/core/git.test.ts: A new unit test asserts the full argv produced by buildGitStatusArgs, verifying flag ordering and the presence of the new global flag.
  • CHANGELOG.md: User-visible entry added under [Unreleased] → Fixed.

Confidence Score: 5/5

Safe to merge — the change is a one-line addition of a well-established Git global flag and an export modifier, with no behavioral risk to existing callers.

The fix is minimal and correct: --no-optional-locks is placed before the subcommand as required, pathspec handling is unaffected, and the new test pins the exact argument order so any accidental reordering would be caught. All three changed files are clean.

No files require special attention.

Important Files Changed

Filename Overview
src/core/git.ts Adds --no-optional-locks as the leading global flag in buildGitStatusArgs and exports the function; placement is correct (before the subcommand) and pathspec handling is unaffected.
src/core/git.test.ts New test asserts the exact argv array including flag order; consistent with the existing test style for other buildGit* helpers.
CHANGELOG.md Changelog entry added correctly under the [Unreleased] Fixed section with an accurate user-facing description.

Sequence Diagram

sequenceDiagram
    participant WatchPoller as Watch Mode Poller
    participant listGitUntrackedFiles
    participant buildGitStatusArgs
    participant runGitText
    participant Git as git process

    WatchPoller->>listGitUntrackedFiles: poll for changes
    listGitUntrackedFiles->>buildGitStatusArgs: input (VcsCommandInput)
    buildGitStatusArgs-->>listGitUntrackedFiles: "["--no-optional-locks","status","--porcelain=v1","-z","--untracked-files=all"]"
    listGitUntrackedFiles->>runGitText: args (with --no-optional-locks)
    runGitText->>Git: "git --no-optional-locks status --porcelain=v1 -z --untracked-files=all"
    Note over Git: No optional index lock acquired
    Git-->>runGitText: NUL-separated porcelain output
    runGitText-->>listGitUntrackedFiles: stdout
    listGitUntrackedFiles-->>WatchPoller: untracked file paths
Loading

Reviews (1): Last reviewed commit: "fix(git): avoid optional status locks in..." | Re-trigger Greptile

@benvinegar benvinegar merged commit a5628d0 into main Jun 9, 2026
8 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.

hunk diff —watch creates git locks

1 participant