]> git.ipfire.org Git - thirdparty/git.git/commitdiff
fsmonitor--daemon: allow --super-prefix argument
authorJeff Hostetler <jeffhost@microsoft.com>
Thu, 26 May 2022 21:47:23 +0000 (21:47 +0000)
committerJunio C Hamano <gitster@pobox.com>
Thu, 26 May 2022 22:59:28 +0000 (15:59 -0700)
Create a test in t7527 to verify that we get a stray warning from
`git fsmonitor--daemon start` when indirectly called from
`git submodule absorbgitdirs`.

Update `git fsmonitor--daemon` to take (and ignore) the `--super-prefix`
argument to suppress the warning.

When we have:

1. a submodule with a `sub/.git/` directory (rather than a `sub/.git`
file).

2. `core.fsmonitor` is turned on in the submodule, but the daemon is
not yet started in the submodule.

3. and someone does a `git submodule absorbgitdirs` in the super.

Git will recursively invoke `git submodule--helper absorb-git-dirs`
in the submodule.  This will read the index and may attempt to start
the fsmonitor--daemon with the `--super-prefix` argument.

`git fsmonitor--daemon start` does not accept the `--super-prefix`
argument and causes a warning to be issued.

This does not cause a problem because the `refresh_index()` code
assumes a trivial response if the daemon does not start.

The net-net is a harmelss, but stray warning.  Lets eliminate the
warning.

Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
git.c
t/t7527-builtin-fsmonitor.sh

diff --git a/git.c b/git.c
index 3d8e48cf555a5d1d56abd4d093145e6a9f77db94..e6fdac1f8e31958dbf9a1d258b435af8e5210081 100644 (file)
--- a/git.c
+++ b/git.c
@@ -537,7 +537,7 @@ static struct cmd_struct commands[] = {
        { "format-patch", cmd_format_patch, RUN_SETUP },
        { "fsck", cmd_fsck, RUN_SETUP },
        { "fsck-objects", cmd_fsck, RUN_SETUP },
-       { "fsmonitor--daemon", cmd_fsmonitor__daemon, RUN_SETUP },
+       { "fsmonitor--daemon", cmd_fsmonitor__daemon, SUPPORT_SUPER_PREFIX | RUN_SETUP },
        { "gc", cmd_gc, RUN_SETUP },
        { "get-tar-commit-id", cmd_get_tar_commit_id, NO_PARSEOPT },
        { "grep", cmd_grep, RUN_SETUP_GENTLY },
index 9edae3ed830de66713ab8fa6171cfad664692b19..19edc96fd4dd83163170fb1769f2dfe28d9da987 100755 (executable)
@@ -832,6 +832,56 @@ test_expect_success 'submodule always visited' '
        my_match_and_clean
 '
 
+# If a submodule has a `sub/.git/` directory (rather than a file
+# pointing to the super's `.git/modules/sub`) and `core.fsmonitor`
+# turned on in the submodule and the daemon is not yet started in
+# the submodule, and someone does a `git submodule absorbgitdirs`
+# in the super, Git will recursively invoke `git submodule--helper`
+# to do the work and this may try to read the index.  This will
+# try to start the daemon in the submodule *and* pass (either
+# directly or via inheritance) the `--super-prefix` arg to the
+# `git fsmonitor--daemon start` command inside the submodule.
+# This causes a warning because fsmonitor--daemon does take that
+# global arg (see the table in git.c)
+#
+# This causes a warning when trying to start the daemon that is
+# somewhat confusing.  It does not seem to hurt anything because
+# the fsmonitor code maps the query failure into a trivial response
+# and does the work anyway.
+#
+# It would be nice to silence the warning, however.
+
+have_t2_error_event () {
+       log=$1
+       msg="fsmonitor--daemon doesnQt support --super-prefix" &&
+
+       tr '\047' Q <$1 | grep -e "$msg"
+}
+
+test_expect_success "stray submodule super-prefix warning" '
+       test_when_finished "rm -rf super; \
+                           rm -rf sub;   \
+                           rm super-sub.trace" &&
+
+       create_super super &&
+       create_sub sub &&
+
+       # Copy rather than submodule add so that we get a .git dir.
+       cp -R ./sub ./super/dir_1/dir_2/sub &&
+
+       git -C super/dir_1/dir_2/sub config core.fsmonitor true &&
+
+       git -C super submodule add ../sub ./dir_1/dir_2/sub &&
+       git -C super commit -m "add sub" &&
+
+       test_path_is_dir super/dir_1/dir_2/sub/.git &&
+
+       GIT_TRACE2_EVENT="$PWD/super-sub.trace" \
+               git -C super submodule absorbgitdirs &&
+
+       ! have_t2_error_event super-sub.trace
+'
+
 # On a case-insensitive file system, confirm that the daemon
 # notices when the .git directory is moved/renamed/deleted
 # regardless of how it is spelled in the the FS event.