From 9628f51fb24eaf42f7bd8a713c0018658c96113b Mon Sep 17 00:00:00 2001 From: LenaWil Date: Thu, 18 May 2023 21:58:22 +0200 Subject: [PATCH] Replace disabling the fsmonitor--daemon by just warning about it MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Detection could be better, but it works, and it is only a warning, doesn’t have to be perfect. --- pre_commit/staged_files_only.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pre_commit/staged_files_only.py b/pre_commit/staged_files_only.py index 456a51f4..f9aeea89 100644 --- a/pre_commit/staged_files_only.py +++ b/pre_commit/staged_files_only.py @@ -48,9 +48,10 @@ def _intent_to_add_cleared() -> Generator[None, None, None]: @contextlib.contextmanager -def _unstaged_changes_cleared(patch_dir: str) -> Generator[None, None, None]: - # Work around a bug in fsmonitor daemon by stopping it. - cmd_output('git', 'fsmonitor--daemon', 'stop') +def _unstaged_changes_cleared(patch_dir: str) -> Generator[None, None, None]: + if cmd_output('git', 'fsmonitor--daemon', 'status')[1].startswith('fsmonitor-daemon is watching'): + logger.warning('The fsmonitor-daemon is running; a bug in the fsmonitor-daemon sometimes causes data loss when run with pre-commit.') + tree = cmd_output('git', 'write-tree')[1].strip() diff_cmd = ( 'git', 'diff-index', '--ignore-submodules', '--binary',