Skip to content

fsmonitor-watchman: fix variable reference and remove redundant code#2180

Open
ptarjan wants to merge 1 commit intogit:masterfrom
ptarjan:claude/fix-watchman-query-bug-sfbIw
Open

fsmonitor-watchman: fix variable reference and remove redundant code#2180
ptarjan wants to merge 1 commit intogit:masterfrom
ptarjan:claude/fix-watchman-query-bug-sfbIw

Conversation

@ptarjan
Copy link
Contributor

@ptarjan ptarjan commented Jan 26, 2026

The is_work_tree_watched() function in fsmonitor-watchman.sample has two bugs:

  1. Wrong variable in error check: After calling watchman_clock(), the result is stored in $o, but the code checks $output->{error} instead of $o->{error}. This means errors from the clock command are silently ignored.

  2. Double output violates protocol: When the retry path triggers (the directory wasn't initially watched), output_result() is called with the "/" flag, then launch_watchman() is called recursively which calls output_result() again. This outputs two clock tokens to stdout, but git's fsmonitor v2 protocol expects exactly one response.

Fix #1 by checking $o->{error} after watchman_clock().

Fix #2 by removing the recursive launch_watchman() call. The "/" "everything is dirty" flag already tells git to do a full scan, and git will call the hook again on the next invocation with a valid clock token.

@gitgitgadget-git
Copy link

There is an issue in commit 041f96c:
fsmonitor: fix two bugs in watchman hook retry path

  • Commit not signed off

@ptarjan ptarjan force-pushed the claude/fix-watchman-query-bug-sfbIw branch 3 times, most recently from e960026 to 116d262 Compare January 26, 2026 00:10
@ptarjan
Copy link
Contributor Author

ptarjan commented Jan 26, 2026

/submit

@gitgitgadget-git
Copy link

Submitted as pull.2180.git.git.1769391202338.gitgitgadget@gmail.com

To fetch this version into FETCH_HEAD:

git fetch https://github.com/gitgitgadget/git/ pr-git-2180/ptarjan/claude/fix-watchman-query-bug-sfbIw-v1

To fetch this version to local tag pr-git-2180/ptarjan/claude/fix-watchman-query-bug-sfbIw-v1:

git fetch --no-tags https://github.com/gitgitgadget/git/ tag pr-git-2180/ptarjan/claude/fix-watchman-query-bug-sfbIw-v1

WARNING: ptarjan has no public email address set on GitHub; GitGitGadget needs an email address to Cc: you on your contribution, so that you receive any feedback on the Git mailing list. Go to https://github.com/settings/profile to make your preferred email public to let GitGitGadget know which email address to use.

The is_work_tree_watched() function in fsmonitor-watchman.sample has
two bugs:

1. Wrong variable in error check: After calling watchman_clock(), the
   result is stored in $o, but the code checks $output->{error} instead
   of $o->{error}. This means errors from the clock command are silently
   ignored.

2. Double output violates protocol: When the retry path triggers (the
   directory wasn't initially watched), output_result() is called with
   the "/" flag, then launch_watchman() is called recursively which
   calls output_result() again. This outputs two clock tokens to stdout,
   but git's fsmonitor v2 protocol expects exactly one response.

Fix #1 by checking $o->{error} after watchman_clock().

Fix #2 by removing the recursive launch_watchman() call. The "/"
"everything is dirty" flag already tells git to do a full scan, and
git will call the hook again on the next invocation with a valid clock
token.

Apply the same fixes to the test helper scripts in t/t7519/.

Cc: Paul Tarjan <github@paulisageek.com>
Signed-off-by: Paul Tarjan <github@paulisageek.com>
@ptarjan ptarjan force-pushed the claude/fix-watchman-query-bug-sfbIw branch from 116d262 to 4c4084f Compare January 26, 2026 05:48
@ptarjan
Copy link
Contributor Author

ptarjan commented Feb 3, 2026

Is there anything more you need from me for this change?

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.

2 participants