Content-Length: 2074 | pFad | http://github.com/pre-commit/pre-commit/pull/3650.patch
thub.com
From ac1301417b3cd2a3276b50f057c93fd8fdb5d169 Mon Sep 17 00:00:00 2001
From: Venkateswara Rao Mandela
Date: Sun, 5 Apr 2026 14:48:46 +0530
Subject: [PATCH] feat(run): warn instead of error when --files is used outside
a git repo
When `pre-commit run --files ` is called outside a git
repository, the tool previously raised a FatalError and exited
with code 1.
- Print a warning that pre-commit is running outside a git
repository and only the explicitly passed files will be checked
- Continue execution rather than aborting
- All other commands (and `run` without `--files`) retain the
existing fatal error behavior
This modification helps use pre-commit in jujutsu worktrees as long
as the modified file list is supplied on command line.
Signed-off-by: Venkateswara Rao Mandela
---
pre_commit/main.py | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/pre_commit/main.py b/pre_commit/main.py
index 0c3eefdaa..6cfc851d5 100644
--- a/pre_commit/main.py
+++ b/pre_commit/main.py
@@ -26,6 +26,7 @@
from pre_commit.commands.validate_config import validate_config
from pre_commit.commands.validate_manifest import validate_manifest
from pre_commit.error_handler import error_handler
+from pre_commit.errors import FatalError
from pre_commit.logging_handler import logging_handler
from pre_commit.store import Store
@@ -185,7 +186,16 @@ def _adjust_args_and_chdir(args: argparse.Namespace) -> None:
if args.command == 'try-repo' and os.path.exists(args.repo):
args.repo = os.path.abspath(args.repo)
- toplevel = git.get_root()
+ try:
+ toplevel = git.get_root()
+ except FatalError:
+ if args.command == 'run' and args.files:
+ logger.warning(
+ 'pre-commit is running outside a git repository. '
+ 'Only the files passed via `--files` will be checked.',
+ )
+ return
+ raise
os.chdir(toplevel)
args.config = os.path.relpath(args.config)
--- a PPN by Garber Painting Akron. With Image Size Reduction included!Fetched URL: http://github.com/pre-commit/pre-commit/pull/3650.patch
Alternative Proxies:
Alternative Proxy
pFad Proxy
pFad v3 Proxy
pFad v4 Proxy