diff --git a/lib/spack/spack/container/images.py b/lib/spack/spack/container/images.py index 130adaffdb..476fbab1db 100644 --- a/lib/spack/spack/container/images.py +++ b/lib/spack/spack/container/images.py @@ -5,6 +5,7 @@ """Manages the details on the images used in the various stages.""" import json import os.path +import shlex import sys import llnl.util.filesystem as fs @@ -130,8 +131,11 @@ def checkout_command(url, ref, enforce_sha, verify): if enforce_sha or verify: ref = _verify_ref(url, ref, enforce_sha) - command = ( - "git clone {0} . && git fetch origin {1}:container_branch &&" - " git checkout container_branch " - ).format(url, ref) - return command + return " && ".join( + [ + "git init --quiet", + f"git remote add origin {shlex.quote(url)}", + f"git fetch --depth=1 origin {shlex.quote(ref)}", + "git checkout --detach FETCH_HEAD", + ] + ) diff --git a/lib/spack/spack/test/container/cli.py b/lib/spack/spack/test/container/cli.py index 8353514b70..1ccd47d002 100644 --- a/lib/spack/spack/test/container/cli.py +++ b/lib/spack/spack/test/container/cli.py @@ -41,5 +41,7 @@ def test_bootstrap_phase(minimal_configuration, config_dumper, capsys): with fs.working_dir(spack_yaml_dir): output = containerize() - # Check for the presence of the clone command - assert "git clone" in output + # Check for the presence of the Git commands + assert "git init" in output + assert "git fetch" in output + assert "git checkout" in output diff --git a/share/spack/templates/container/bootstrap-base.dockerfile b/share/spack/templates/container/bootstrap-base.dockerfile index e002cce02e..ac069bbe37 100644 --- a/share/spack/templates/container/bootstrap-base.dockerfile +++ b/share/spack/templates/container/bootstrap-base.dockerfile @@ -23,7 +23,7 @@ RUN ln -s $SPACK_ROOT/share/spack/docker/entrypoint.bash \ RUN mkdir -p /root/.spack \ && cp $SPACK_ROOT/share/spack/docker/modules.yaml \ /root/.spack/modules.yaml \ - && rm -rf /root/*.* /run/nologin $SPACK_ROOT/.git + && rm -rf /root/*.* /run/nologin # [WORKAROUND] # https://superuser.com/questions/1241548/