Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pre_commit/languages/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def _get_docker_path(path: str) -> str:
if os.path.commonpath((path, to_path)) == to_path:
# So there is something in common,
# and we can proceed remapping it
return path.replace(to_path, src_path)
return path.replace(to_path, src_path, 1)
# we're in Docker, but the path is not mounted, cannot really do anything,
# so fall back to original path
return path
Expand Down
10 changes: 10 additions & 0 deletions tests/languages/docker_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,16 @@ def test_get_docker_path_in_docker_binds_path_complex(in_docker):
assert docker._get_docker_path(path) == '/opt/my_code/test/something'


def test_get_docker_path_preserves_repeated_destination(in_docker):
binds_list = [{'Source': '/opt/my_code', 'Destination': '/project'}]
docker_out = json.dumps([{'Mounts': binds_list}]).encode()

with _linux_commonpath(), _docker_output(docker_out):
path = '/project/cache/project/repo'
expected = '/opt/my_code/cache/project/repo'
assert docker._get_docker_path(path) == expected


def test_get_docker_path_in_docker_no_substring(in_docker):
binds_list = [{'Source': '/opt/my_code', 'Destination': '/project'}]
docker_out = json.dumps([{'Mounts': binds_list}]).encode()
Expand Down
Loading