From 623be741b6bc361681c4f1c69407dd6822a76e3d Mon Sep 17 00:00:00 2001 From: Xinyi Wang Date: Tue, 19 Sep 2023 16:44:35 -0700 Subject: [PATCH] implement .nowatchman discovery in repo root Summary: Implement .nowatchman check as required in the task If .nowatchman is presented, not spawning watchman As required, we will check .nowatchman under repo root, only .nowatchman under repo root will count. Reviewed By: kmancini Differential Revision: D49429032 fbshipit-source-id: f959f5bbd3e2e08e6bc888000491415829fc14f9 --- watchman/cmds/watch.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/watchman/cmds/watch.cpp b/watchman/cmds/watch.cpp index 98cd89636f4b..7a61afdb0285 100644 --- a/watchman/cmds/watch.cpp +++ b/watchman/cmds/watch.cpp @@ -191,6 +191,17 @@ bool find_project_root( return false; } +void check_no_watchman(w_string resolved_root) { + // check if .nowatchman exists under the resolved path + auto no_watchman_path = w_string::pathCat({resolved_root, ".nowatchman"}); + if (w_path_exists(no_watchman_path.c_str())) { + CommandValidationError::throwf( + "resolve_projpath: the repository is configured to not enable watchman. " + "Found .nowatchman at {}", + no_watchman_path); + } +} + // For watch-project, take a root path string and resolve the // containing project directory, then update the args to reflect // that path. @@ -235,6 +246,7 @@ static w_string resolve_projpath( if (find_project_root(*root_files, resolvedpiece, relpiece)) { relpath = relpiece.asWString(); resolved = resolvedpiece.asWString(); + check_no_watchman(resolved); args[1] = w_string_to_json(resolved); return resolved; }