From: Abhishek Agarwal <agab0323@gmail.com>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>,
Patrick Steinhardt <ps@pks.im>,
Paul Tarjan <github@paulisageek.com>,
Erik Cervin-Edin <erik@cervined.in>,
John Mellor <johnme@google.com>,
Nicolas Riebesel <nicolas@adamatec.com>
Subject: [PATCH 3/3] fsmonitor: watch directories moved into the worktree on Linux
Date: Sun, 6 Dec 2026 12:30:45 +0530 [thread overview]
Message-ID: <20261206070045.12607-4-agab0323@gmail.com> (raw)
In-Reply-To: <20261206070045.12607-1-agab0323@gmail.com>
A directory moved into the worktree from outside arrives as an
IN_MOVED_TO event without a matching IN_MOVED_FROM. rename_dir() then
only logs "no matching cookie", and while register_inotify() adds
watches for the subdirectories, nothing adds one for the directory
itself. Changes to files directly in it are never reported, so "git
status" does not show them, and according to the report [1], "git
checkout" and "git rm" do not notice them either and can discard them.
Add the watch in that case, too.
[1] https://lore.kernel.org/git/CAG_kaUYEjQhiPMatcPXr00q3oO77BM2Mu7KUZyP0aSGGwKTsJA@mail.gmail.com/
Reported-by: John Mellor <johnme@google.com>
Signed-off-by: Abhishek Agarwal <agab0323@gmail.com>
---
compat/fsmonitor/fsm-listen-linux.c | 3 +++
t/t7527-builtin-fsmonitor.sh | 15 +++++++++++++++
2 files changed, 18 insertions(+)
diff --git a/compat/fsmonitor/fsm-listen-linux.c b/compat/fsmonitor/fsm-listen-linux.c
index df91714f76..f57efc56cb 100644
--- a/compat/fsmonitor/fsm-listen-linux.c
+++ b/compat/fsmonitor/fsm-listen-linux.c
@@ -325,6 +325,9 @@ static void rename_dir(uint32_t cookie, const char *path,
/* Directory was moved from outside the watch tree */
trace_printf_key(&trace_fsmonitor,
"no matching cookie for rename to '%s'", path);
+ if (add_watch(path, data))
+ trace_printf_key(&trace_fsmonitor,
+ "failed to add watch for '%s'", path);
}
}
diff --git a/t/t7527-builtin-fsmonitor.sh b/t/t7527-builtin-fsmonitor.sh
index b7041e1825..ea1c7b8106 100755
--- a/t/t7527-builtin-fsmonitor.sh
+++ b/t/t7527-builtin-fsmonitor.sh
@@ -1508,4 +1508,19 @@ test_expect_success 'edits below a renamed directory are reported' '
test_cmp expect actual
'
+test_expect_success 'edits in a directory moved in from outside are seen' '
+ test_when_finished "stop_daemon_delete_repo into && rm -rf outside" &&
+ start_watching into &&
+ mkdir -p outside/pkg/sub &&
+ echo a >outside/pkg/top &&
+ echo a >outside/pkg/sub/file &&
+ mv outside/pkg into/pkg &&
+ git -C into add pkg &&
+ git -C into commit -q -m add &&
+ echo b >>into/pkg/top &&
+ echo " M pkg/top" >expect &&
+ git -C into status --porcelain >actual &&
+ test_cmp expect actual
+'
+
test_done
--
2.56.0
prev parent reply other threads:[~2026-12-06 7:01 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-06 7:00 [PATCH 0/3] fsmonitor: fix rename handling in the Linux listener Abhishek Agarwal
2026-12-06 7:00 ` [PATCH 1/3] fsmonitor: remove the right reverse entry of a watch on Linux Abhishek Agarwal
2026-12-06 7:00 ` [PATCH 2/3] fsmonitor: keep watch paths below a renamed directory up to date Abhishek Agarwal
2026-12-06 7:00 ` Abhishek Agarwal [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261206070045.12607-4-agab0323@gmail.com \
--to=agab0323@gmail.com \
--cc=erik@cervined.in \
--cc=git@vger.kernel.org \
--cc=github@paulisageek.com \
--cc=gitster@pobox.com \
--cc=johnme@google.com \
--cc=nicolas@adamatec.com \
--cc=ps@pks.im \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox