mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-04-16 18:41:46 +04:00
mounting the superproject directory
This commit is contained in:
parent
c2980217a8
commit
69709798c6
2 changed files with 14 additions and 3 deletions
|
|
@ -39,6 +39,14 @@ def get_root():
|
||||||
return cmd_output('git', 'rev-parse', '--show-toplevel')[1].strip()
|
return cmd_output('git', 'rev-parse', '--show-toplevel')[1].strip()
|
||||||
|
|
||||||
|
|
||||||
|
def get_superproject_root():
|
||||||
|
stdout = cmd_output('git',
|
||||||
|
'rev-parse',
|
||||||
|
'--show-superproject-working-tree',
|
||||||
|
'--show-toplevel')
|
||||||
|
return stdout[1].splitlines()[0].strip()
|
||||||
|
|
||||||
|
|
||||||
def get_git_dir(git_root='.'):
|
def get_git_dir(git_root='.'):
|
||||||
opts = ('--git-common-dir', '--git-dir')
|
opts = ('--git-common-dir', '--git-dir')
|
||||||
_, out, _ = cmd_output('git', 'rev-parse', *opts, cwd=git_root)
|
_, out, _ = cmd_output('git', 'rev-parse', *opts, cwd=git_root)
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ import hashlib
|
||||||
import os
|
import os
|
||||||
|
|
||||||
import pre_commit.constants as C
|
import pre_commit.constants as C
|
||||||
from pre_commit import five
|
from pre_commit import five, git
|
||||||
from pre_commit.languages import helpers
|
from pre_commit.languages import helpers
|
||||||
from pre_commit.util import CalledProcessError
|
from pre_commit.util import CalledProcessError
|
||||||
from pre_commit.util import clean_path_on_failure
|
from pre_commit.util import clean_path_on_failure
|
||||||
|
|
@ -74,6 +74,9 @@ def install_environment(
|
||||||
|
|
||||||
|
|
||||||
def docker_cmd(): # pragma: windows no cover
|
def docker_cmd(): # pragma: windows no cover
|
||||||
|
superproject_dir = git.get_superproject_root()
|
||||||
|
project_dir = git.get_root()
|
||||||
|
project_relpath = os.path.relpath(project_dir, superproject_dir)
|
||||||
return (
|
return (
|
||||||
'docker', 'run',
|
'docker', 'run',
|
||||||
'--rm',
|
'--rm',
|
||||||
|
|
@ -81,8 +84,8 @@ def docker_cmd(): # pragma: windows no cover
|
||||||
# https://docs.docker.com/engine/reference/commandline/run/#mount-volumes-from-container-volumes-from
|
# 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
|
# The `Z` option tells Docker to label the content with a private
|
||||||
# unshared label. Only the current container can use a private volume.
|
# unshared label. Only the current container can use a private volume.
|
||||||
'-v', '{}:/src:rw,Z'.format(os.getcwd()),
|
'-v', '{}:/src:rw,Z'.format(superproject_dir),
|
||||||
'--workdir', '/src',
|
'--workdir', os.path.abspath(os.path.join('/src', project_relpath)),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue