From 308c77cb473a25514511a1f4cbb843ef679c2f5a Mon Sep 17 00:00:00 2001 From: robeortZ <41119144+robeortZ@users.noreply.github.com> Date: Wed, 29 Apr 2026 09:35:57 +0800 Subject: [PATCH 1/2] Implement _resolve_git_hooks_dir function Add a function to resolve the git hooks directory path for both normal clones and submodules. --- tools/cli_command/cli_check.py | 35 +++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/tools/cli_command/cli_check.py b/tools/cli_command/cli_check.py index a6471423d..e65f94495 100755 --- a/tools/cli_command/cli_check.py +++ b/tools/cli_command/cli_check.py @@ -15,12 +15,45 @@ from tools.cli_command.util_git import set_repo_mirro, download_submoudules +def _resolve_git_hooks_dir(open_root: str) -> str: + """ + Path to the repository's hooks directory. + For a normal clone, this is /.git/hooks. For a git submodule, .git is + a file (gitdir pointer), so we ask git for the real path. + """ + try: + result = subprocess.run( + ["git", "-C", open_root, "rev-parse", "--git-path", "hooks"], + stdout=subprocess.PIPE, + stderr=subprocess.DEVNULL, + text=True, + check=True, + timeout=20, + ) + except (subprocess.CalledProcessError, FileNotFoundError, OSError): + return None + path = (result.stdout or "").strip() + if not path: + return None + if not os.path.isabs(path): + path = os.path.normpath(os.path.join(open_root, path)) + return path + + def copy_pre_commit(): params = get_global_params() + logger = get_logger() open_root = params["open_root"] tools_root = params["tools_root"] source = os.path.join(tools_root, "hooks") - target = os.path.join(open_root, ".git", "hooks") + if not os.path.isdir(source): + return + + target = _resolve_git_hooks_dir(open_root) + if not target: + logger.note("Skip copying pre-commit hooks (not a git repo or hooks path unknown).") + return + copy_directory(source, target) pass From bec57cbb3134447215fb762eab15efad42c97941 Mon Sep 17 00:00:00 2001 From: robeortZ <41119144+robeortZ@users.noreply.github.com> Date: Wed, 29 Apr 2026 09:40:47 +0800 Subject: [PATCH 2/2] Implement git hooks directory resolution function Add function to resolve the git hooks directory path for both normal clones and git submodules. --- tools/cli_command/cli_check.py | 35 +++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/tools/cli_command/cli_check.py b/tools/cli_command/cli_check.py index a6471423d..e65f94495 100755 --- a/tools/cli_command/cli_check.py +++ b/tools/cli_command/cli_check.py @@ -15,12 +15,45 @@ from tools.cli_command.util_git import set_repo_mirro, download_submoudules +def _resolve_git_hooks_dir(open_root: str) -> str: + """ + Path to the repository's hooks directory. + For a normal clone, this is /.git/hooks. For a git submodule, .git is + a file (gitdir pointer), so we ask git for the real path. + """ + try: + result = subprocess.run( + ["git", "-C", open_root, "rev-parse", "--git-path", "hooks"], + stdout=subprocess.PIPE, + stderr=subprocess.DEVNULL, + text=True, + check=True, + timeout=20, + ) + except (subprocess.CalledProcessError, FileNotFoundError, OSError): + return None + path = (result.stdout or "").strip() + if not path: + return None + if not os.path.isabs(path): + path = os.path.normpath(os.path.join(open_root, path)) + return path + + def copy_pre_commit(): params = get_global_params() + logger = get_logger() open_root = params["open_root"] tools_root = params["tools_root"] source = os.path.join(tools_root, "hooks") - target = os.path.join(open_root, ".git", "hooks") + if not os.path.isdir(source): + return + + target = _resolve_git_hooks_dir(open_root) + if not target: + logger.note("Skip copying pre-commit hooks (not a git repo or hooks path unknown).") + return + copy_directory(source, target) pass