diff --git a/pre_commit/languages/docker.py b/pre_commit/languages/docker.py index eea1bdcd..72a98ea5 100644 --- a/pre_commit/languages/docker.py +++ b/pre_commit/languages/docker.py @@ -82,14 +82,14 @@ def get_docker_user() -> Tuple[str, ...]: # pragma: win32 no cover ('docker', 'system', 'info'), text=True, ) + for line in output.splitlines(): + # rootless docker has "rootless" + # rootless podman has "rootless: true" + if line.strip().startswith('rootless'): + if 'false' not in line: + return () # no -u for rootless + break try: - for line in output.splitlines(): - # rootless docker has "rootless" - # rootless podman has "rootless: true" - if line.strip().startswith('rootless'): - if 'false' not in line: - return () # no -u for rootless - break return ('-u', f'{os.getuid()}:{os.getgid()}') except AttributeError: return ()