]> Kevux Git Server - rit/commit
fsmonitor-watchman: fix variable reference and remove redundant code
authorPaul Tarjan <github@paulisageek.com>
Sat, 28 Feb 2026 17:37:57 +0000 (17:37 +0000)
committerJunio C Hamano <gitster@pobox.com>
Mon, 2 Mar 2026 16:15:18 +0000 (08:15 -0800)
commit41366e46779865164e3e8af2bac6eb95ea6f6586
treed4ce4994fef7c35baf0d304a762f2f3deb4ea1dc
parent67ad42147a7acc2af6074753ebd03d904476118f
fsmonitor-watchman: fix variable reference and remove redundant code

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.

With the recursive call removed, the $retry guard is no longer needed
since it only existed to prevent infinite recursion. Remove it.

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

Signed-off-by: Paul Tarjan <github@paulisageek.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/t7519/fsmonitor-watchman
t/t7519/fsmonitor-watchman-v2
templates/hooks/fsmonitor-watchman.sample