* fsmonitor (Linux): edits in subdirectories of a renamed directory are missed
@ 2026-10-13 13:39 Erik Cervin-Edin
2026-12-01 12:55 ` Nicolas Riebesel
0 siblings, 1 reply; 3+ messages in thread
From: Erik Cervin-Edin @ 2026-10-13 13:39 UTC (permalink / raw)
To: git; +Cc: Paul Tarjan, Patrick Steinhardt
What did you do before the bug happened? (Steps to reproduce your issue)
With the built-in fsmonitor daemon on Linux, I renamed a directory that
has a subdirectory, then edited a file in each:
git init repro && cd repro
git config core.fsmonitor true
mkdir -p old/pkg/sub new
echo a >old/pkg/top.txt
echo a >old/pkg/sub/f.txt
git add . && git commit -qm init
git status --short # starts the daemon
git mv old/pkg new/pkg
git commit -qm move
echo b >>new/pkg/top.txt
echo b >>new/pkg/sub/f.txt
GIT_TRACE_FSMONITOR=1 git status --short
What did you expect to happen? (Expected behavior)
Both edited files listed as modified:
M new/pkg/sub/f.txt
M new/pkg/top.txt
What happened instead? (Actual behavior)
Only the file directly in the renamed directory is listed. The daemon
reports the edit in the subdirectory under its path from before the
rename:
fsmonitor_refresh_callback 'new/pkg/top.txt' (pos 1)
fsmonitor_refresh_callback INV: 'new/pkg/top.txt'
fsmonitor_refresh_callback CNT: 1
fsmonitor_refresh_callback 'old/pkg/sub/f.txt' (pos -3)
M new/pkg/top.txt
`git -c core.fsmonitor=false status --short` lists both files.
What's different between what you expected and what actually happened?
Changes anywhere below a subdirectory of a renamed directory are
missing from status and diff, with no warning. It is not a
race: later edits in that subdirectory, made well after the rename, are
missed too. It persists until something invalidates the fsmonitor
state. I hit it moving a source package: 19 of 56 edited files were
missing from `git status`, all in subdirectories of the moved
directory, and a commit made from that status would have left them
out.
Anything else you want to add:
I believe the cause is in add_watch() in
compat/fsmonitor/fsm-listen-linux.c. An inotify watch follows the
directory's inode, so the subdirectories of a renamed directory are
still watched. When the rename is processed, they are registered again
under their new paths with IN_MASK_CREATE, inotify_add_watch() fails
with EEXIST, and add_watch() returns early without updating the
descriptor-to-path map. Only the renamed directory's own entry gets its
new path.
Patrick Steinhardt asked about exactly this in review of v5 of the
Linux listener:
https://lore.kernel.org/git/aZ1bRQv9Cjke298f@pks.im/
> In case the watch already exists, can't it be the case that we
> have raced e.g. during a rename? [...] If we then see EEXIST we
> wouldn't update the hash map and thus keep the old path intact.
As far as I can see that question was not answered on the list, and
v15 of the series still returns early on EEXIST. It turns out to be
deterministic rather than a race.
[System Info]
git version:
git version 2.56.0.rc2.275.gfcaf1f5383
cpu: x86_64
built from commit: fcaf1f5383f52c5ebd5e2df3ea023601e2084b10
sizeof-long: 8
sizeof-size_t: 8
shell-path: /bin/sh
rust: enabled
feature: fsmonitor--daemon
gettext: enabled
libcurl: 8.18.0
OpenSSL: OpenSSL 3.5.8 25 Aug 2026
zlib-ng: 2.3.3
SHA-1: SHA1_DC
SHA-256: SHA256_BLK
default-ref-storage-format: files
default-hash: sha1
uname: Linux 7.2.9-200.fc44.x86_64 #1 SMP PREEMPT_DYNAMIC Sat Oct 3 19:59:55 UTC 2026 x86_64
compiler info: gnuc: 16.2
libc info: glibc: 2.43
$SHELL (typically, interactive shell): /bin/bash
[Enabled Hooks]
not run from a git repository - no hooks to show
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: fsmonitor (Linux): edits in subdirectories of a renamed directory are missed
2026-10-13 13:39 fsmonitor (Linux): edits in subdirectories of a renamed directory are missed Erik Cervin-Edin
@ 2026-12-01 12:55 ` Nicolas Riebesel
2026-12-01 18:44 ` Erik Cervin Edin
0 siblings, 1 reply; 3+ messages in thread
From: Nicolas Riebesel @ 2026-12-01 12:55 UTC (permalink / raw)
To: Erik Cervin-Edin; +Cc: git, Paul Tarjan, Patrick Steinhardt
Hi Erik,
On Tue, 13 Oct 2026 15:39:28 +0200, Erik Cervin-Edin wrote:
> With the built-in fsmonitor daemon on Linux, I renamed a directory that
> has a subdirectory, then edited a file in each:
[...]
> Only the file directly in the renamed directory is listed. The daemon
> reports the edit in the subdirectory under its path from before the
> rename
I can confirm this with the released git 2.56.0 (NixOS, x86_64,
core.fsmonitor=true set globally), using a slightly smaller
reproduction:
git init repro && cd repro
mkdir -p old/sub
echo a >old/top.txt
echo a >old/sub/f.txt
git add . && git commit -qm init
git status --short # starts the daemon
git mv old new
git commit -qm rename
echo b >>new/top.txt
echo b >>new/sub/f.txt
GIT_TRACE_FSMONITOR=1 git status --short
Only "M new/top.txt" is listed; the trace shows the edit in the
subdirectory reported as 'old/sub/f.txt'.
"git -c core.fsmonitor=false status --short" lists both files.
> Changes anywhere below a subdirectory of a renamed directory are
> missing from status and diff, with no warning.
This bit me in practice as well: after renaming a directory, a whole
series of later edits in its subdirectories was silently missing from
"git add -A". The resulting commits did not build, while the working
tree did, so nothing looked wrong until the commits were checked out
on their own.
> I believe the cause is in add_watch() in
> compat/fsmonitor/fsm-listen-linux.c. [...] When the rename is
> processed, they are registered again under their new paths with
> IN_MASK_CREATE, inotify_add_watch() fails with EEXIST, and add_watch()
> returns early without updating the descriptor-to-path map.
I came to the same conclusion reading the code on master: after
rename_dir(), register_inotify() recurses into the subdirectories and
calls add_watch() for each new path, which hits the EEXIST early
return, so the watch descriptors of the subdirectories keep their old
paths.
As far as I can tell, master has no change to fsm-listen-linux.c since
the series was merged, and t7527's "rename directory" test only checks
the rename event itself, not later edits below the renamed directory,
so this is not covered.
Until this is fixed, setting core.fsmonitor=false in affected
repositories is the only workaround I am aware of; restarting the
daemon helps only until the next directory rename.
Thanks,
Nicolas Riebesel
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: fsmonitor (Linux): edits in subdirectories of a renamed directory are missed
2026-12-01 12:55 ` Nicolas Riebesel
@ 2026-12-01 18:44 ` Erik Cervin Edin
0 siblings, 0 replies; 3+ messages in thread
From: Erik Cervin Edin @ 2026-12-01 18:44 UTC (permalink / raw)
To: Nicolas Riebesel; +Cc: git, Paul Tarjan, Patrick Steinhardt
On 01/12/26 13:55, Nicolas Riebesel wrote:
> Until this is fixed, setting core.fsmonitor=false in affected
> repositories is the only workaround I am aware of; restarting the
> daemon helps only until the next directory rename.
FWIW, I've found core.fsmonitor=false a sane default and only turn it on
when it's needed.
git-update-index(1) specifies:
> FILE SYSTEM MONITOR
> This feature is intended to speed up git operations for repos
> that have large working directories.
I suspect "large" varies by your OS. I can only guess that "large" here
means large monolithic style repos, or things like the kernel.
When the fsmonitor hook was introduced, Ben Peart wrote [1]:
> Due to the overhead of calling out to Watchman, on very small repos
> (<10K files) the overhead exceeds the savings. Once repos hit 10K files
> the savings kick in and for repos beyond that, the savings are dramatic.
[1]: https://lore.kernel.org/git/20170915192043.4516-1-benpeart@microsoft.com/
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-12-01 18:45 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-13 13:39 fsmonitor (Linux): edits in subdirectories of a renamed directory are missed Erik Cervin-Edin
2026-12-01 12:55 ` Nicolas Riebesel
2026-12-01 18:44 ` Erik Cervin Edin
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.