From 55f9ae755e3851d08875072fbf0930d8c2f6b40d Mon Sep 17 00:00:00 2001 From: gnought <1684105+gnought@users.noreply.github.com> Date: Sat, 14 Feb 2026 21:49:34 +0800 Subject: [PATCH] best-effort fetch tag for HEAD in shallow clone --- pre_commit/store.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pre_commit/store.py b/pre_commit/store.py index dc90c051..de51c473 100644 --- a/pre_commit/store.py +++ b/pre_commit/store.py @@ -186,6 +186,7 @@ class Store: git_config = 'protocol.version=2' git_cmd('-c', git_config, 'fetch', 'origin', ref, '--depth=1') + git_cmd('-c', git_config, 'fetch', 'origin', f'refs/tags/{ref}:refs/tags/{ref}', '--depth=1', check=False) git_cmd('checkout', 'FETCH_HEAD') git_cmd( '-c', git_config, 'submodule', 'update', '--init', '--recursive', @@ -199,8 +200,8 @@ class Store: git.init_repo(directory, repo) env = git.no_git_env() - def _git_cmd(*args: str) -> None: - cmd_output_b('git', *args, cwd=directory, env=env) + def _git_cmd(*args: str, check=True) -> None: + cmd_output_b('git', *args, cwd=directory, env=env, check=check) try: self._shallow_clone(ref, _git_cmd)