From 69709798c6b42dffe3a93dc9a119bfeb9dcadd9c Mon Sep 17 00:00:00 2001 From: Ilya Epifanov Date: Wed, 8 May 2019 13:50:25 +0200 Subject: [PATCH] mounting the superproject directory --- pre_commit/git.py | 8 ++++++++ pre_commit/languages/docker.py | 9 ++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/pre_commit/git.py b/pre_commit/git.py index 64e449cb..113b8f67 100644 --- a/pre_commit/git.py +++ b/pre_commit/git.py @@ -39,6 +39,14 @@ def get_root(): 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='.'): opts = ('--git-common-dir', '--git-dir') _, out, _ = cmd_output('git', 'rev-parse', *opts, cwd=git_root) diff --git a/pre_commit/languages/docker.py b/pre_commit/languages/docker.py index 59a53b4f..fb3f3e28 100644 --- a/pre_commit/languages/docker.py +++ b/pre_commit/languages/docker.py @@ -5,7 +5,7 @@ import hashlib import os 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.util import CalledProcessError from pre_commit.util import clean_path_on_failure @@ -74,6 +74,9 @@ def install_environment( 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 ( 'docker', 'run', '--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 # The `Z` option tells Docker to label the content with a private # unshared label. Only the current container can use a private volume. - '-v', '{}:/src:rw,Z'.format(os.getcwd()), - '--workdir', '/src', + '-v', '{}:/src:rw,Z'.format(superproject_dir), + '--workdir', os.path.abspath(os.path.join('/src', project_relpath)), )