git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: fsmonitor (Linux): edits in subdirectories of a renamed directory are missed

From
NRNicolas Riebesel <nicolas@adamatec.com>
Date
Dec 1, 2026, 12:55 UTC
Message-ID
<833d94b8-f313-4717-8e48-48bd35a6ab4f@adamatec.com>
In-Reply-To
<as4z1SskiPyrSKIa@vader>
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.

Show 5 quoted lines
> 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

Previous: Erik Cervin-EdinNext: Erik Cervin Edin
Message 2 of 3 in “fsmonitor (Linux): edits in subdirectories of a renamed directory are missed”
  1. Erik Cervin-EdinOct 13, 2026
  2. Nicolas RiebeselDec 1, 2026
  3. Erik Cervin EdinDec 1, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.