diff mbox series

[v3,15/34] fsmonitor: do not try to operate on bare repos

Message ID eef39aa168fec58321ee233d907db696b56ee0b8.1625150864.git.gitgitgadget@gmail.com (mailing list archive)
State New, archived
Headers show
Series Builtin FSMonitor Feature | expand

Commit Message

Jeff Hostetler July 1, 2021, 2:47 p.m. UTC
From: Jeff Hostetler <jeffhost@microsoft.com>

Bare repos do not have a working directory, so there is no
directory for the daemon to register a watch upon.  And therefore
there are no files within the directory for it to actually watch.

Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com>
---
 builtin/fsmonitor--daemon.c |  8 ++++++++
 t/t7519-status-fsmonitor.sh | 16 ++++++++++++++++
 2 files changed, 24 insertions(+)

Comments

Ævar Arnfjörð Bjarmason July 1, 2021, 10:53 p.m. UTC | #1
On Thu, Jul 01 2021, Jeff Hostetler via GitGitGadget wrote:

> From: Jeff Hostetler <jeffhost@microsoft.com>
>
> Bare repos do not have a working directory, so there is no
> directory for the daemon to register a watch upon.  And therefore
> there are no files within the directory for it to actually watch.
>
> Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com>
> ---
>  builtin/fsmonitor--daemon.c |  8 ++++++++
>  t/t7519-status-fsmonitor.sh | 16 ++++++++++++++++
>  2 files changed, 24 insertions(+)
>
> diff --git a/builtin/fsmonitor--daemon.c b/builtin/fsmonitor--daemon.c
> index 7fcf960652f..d6161ad95a5 100644
> --- a/builtin/fsmonitor--daemon.c
> +++ b/builtin/fsmonitor--daemon.c
> @@ -490,6 +490,14 @@ int cmd_fsmonitor__daemon(int argc, const char **argv, const char *prefix)
>  		die(_("invalid 'ipc-threads' value (%d)"),
>  		    fsmonitor__ipc_threads);
>  
> +	prepare_repo_settings(the_repository);
> +	if (!the_repository->worktree)
> +		return error(_("fsmonitor-daemon does not support bare repos '%s'"),
> +			     xgetcwd());
> +	if (the_repository->settings.fsmonitor_mode == FSMONITOR_MODE_INCOMPATIBLE)
> +		return error(_("fsmonitor-daemon is incompatible with this repo '%s'"),
> +			     the_repository->worktree);

I commented on another patch that that second condition seems like it's
only hit under core.virtualfilesystem=true....


> +test_expect_success FSMONITOR_DAEMON 'try running fsmonitor-daemon in bare repo' '
> +	test_when_finished "rm -rf ./bare-clone" &&
> +	git clone --bare . ./bare-clone &&
> +	test_must_fail git -C ./bare-clone fsmonitor--daemon run 2>actual &&
> +	grep "fsmonitor-daemon does not support bare repos" actual
> +'

Isn't just:

    git init --bare bare.git
    test_must_fail git -C bare.git [...]

Enough, or does the repository need content to get to that error.

> +test_expect_success FSMONITOR_DAEMON 'try running fsmonitor-daemon in virtual repo' '
> +	test_when_finished "rm -rf ./fake-virtual-clone" &&
> +	git clone . ./fake-virtual-clone &&
> +	test_must_fail git -C ./fake-virtual-clone \
> +			   -c core.virtualfilesystem=true \
> +			   fsmonitor--daemon run 2>actual &&
> +	grep "fsmonitor-daemon is incompatible with this repo" actual
> +'
> +

Ditto.
diff mbox series

Patch

diff --git a/builtin/fsmonitor--daemon.c b/builtin/fsmonitor--daemon.c
index 7fcf960652f..d6161ad95a5 100644
--- a/builtin/fsmonitor--daemon.c
+++ b/builtin/fsmonitor--daemon.c
@@ -490,6 +490,14 @@  int cmd_fsmonitor__daemon(int argc, const char **argv, const char *prefix)
 		die(_("invalid 'ipc-threads' value (%d)"),
 		    fsmonitor__ipc_threads);
 
+	prepare_repo_settings(the_repository);
+	if (!the_repository->worktree)
+		return error(_("fsmonitor-daemon does not support bare repos '%s'"),
+			     xgetcwd());
+	if (the_repository->settings.fsmonitor_mode == FSMONITOR_MODE_INCOMPATIBLE)
+		return error(_("fsmonitor-daemon is incompatible with this repo '%s'"),
+			     the_repository->worktree);
+
 	if (!strcmp(subcmd, "start"))
 		return !!try_to_start_background_daemon();
 
diff --git a/t/t7519-status-fsmonitor.sh b/t/t7519-status-fsmonitor.sh
index 02919c68ddd..ed20a4f7fb9 100755
--- a/t/t7519-status-fsmonitor.sh
+++ b/t/t7519-status-fsmonitor.sh
@@ -394,6 +394,22 @@  test_expect_success 'incompatible bare repo' '
 	test_cmp expect actual
 '
 
+test_expect_success FSMONITOR_DAEMON 'try running fsmonitor-daemon in bare repo' '
+	test_when_finished "rm -rf ./bare-clone" &&
+	git clone --bare . ./bare-clone &&
+	test_must_fail git -C ./bare-clone fsmonitor--daemon run 2>actual &&
+	grep "fsmonitor-daemon does not support bare repos" actual
+'
+
+test_expect_success FSMONITOR_DAEMON 'try running fsmonitor-daemon in virtual repo' '
+	test_when_finished "rm -rf ./fake-virtual-clone" &&
+	git clone . ./fake-virtual-clone &&
+	test_must_fail git -C ./fake-virtual-clone \
+			   -c core.virtualfilesystem=true \
+			   fsmonitor--daemon run 2>actual &&
+	grep "fsmonitor-daemon is incompatible with this repo" actual
+'
+
 test_expect_success 'incompatible core.virtualfilesystem' '
 	test_when_finished "rm -rf ./fake-gvfs-clone" &&
 	git clone . ./fake-gvfs-clone &&