containers: retain shallow git data (#37734)

This commit is contained in:
Jonathon Anderson
2023-07-12 16:03:10 -05:00
committed by GitHub
parent c8026c3c87
commit 90208da8a5
3 changed files with 14 additions and 8 deletions

View File

@@ -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",
]
)

View File

@@ -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