fix: fix Docker path mounting

Currently pre-commit mounts the current directory to /src and uses
current directory name as mount base.
However this does not work when pre-commit is run inside the container
on some mounted path already, because mount points are relative to the
host, not to the container.

See https://gist.github.com/dpfoose/f96d4e4b76c2e01265619d545b77987a
Fixes #1387
This commit is contained in:
Oleg Kainov 2021-04-21 11:43:12 +03:00
parent 24d9dc7469
commit 6d31cff55f
No known key found for this signature in database
GPG key ID: 30827D5765567994
2 changed files with 72 additions and 1 deletions

View file

@ -8,6 +8,7 @@ from pre_commit.hook import Hook
from pre_commit.languages import helpers
from pre_commit.prefix import Prefix
from pre_commit.util import clean_path_on_failure
from pre_commit.util import translate_path
ENVIRONMENT_DIR = 'docker'
PRE_COMMIT_LABEL = 'PRE_COMMIT'
@ -73,7 +74,7 @@ def docker_cmd() -> Tuple[str, ...]: # pragma: win32 no cover
# https://docs.docker.com/engine/reference/commandline/run/#mount-volumes-from-container-volumes-from
# The `Z` option tells Docker to label the content with a private
# unshared label. Only the current container can use a private volume.
'-v', f'{os.getcwd()}:/src:rw,Z',
'-v', f'{translate_path(os.getcwd())}:/src:rw,Z',
'--workdir', '/src',
)