diff --git a/pkg/build/pipelines/git-checkout.yaml b/pkg/build/pipelines/git-checkout.yaml index 2da3001a9..d013ff803 100644 --- a/pkg/build/pipelines/git-checkout.yaml +++ b/pkg/build/pipelines/git-checkout.yaml @@ -39,6 +39,7 @@ inputs: pipeline: - runs: | + set -x if [ -z "${{inputs.branch}}" ] && [ -z "${{inputs.tag}}" ]; then echo "Warning (git-checkout): you have not specified a branch or tag." fi @@ -54,21 +55,35 @@ pipeline: workdir=$(mktemp -d) mkdir -p '${{inputs.destination}}' clone_fullpath=$(realpath '${{inputs.destination}}') + referenceRepo="/var/cache/melange/${{package.name}}.git" git config --global --add safe.directory $workdir git config --global --add safe.directory $clone_fullpath - git clone $git_clone_flags $clone_target --depth '${{inputs.depth}}' '${{inputs.repository}}' $workdir + git config --global --add safe.directory $referenceRepo + git config --global advice.detachedHead false + git config --global init.defaultBranch main + + # Init or re-init + git init --bare $referenceRepo + # Populate or update cache + if [ -n '${{inputs.tag}}' ]; then + git -C $referenceRepo fetch --progress $git_clone_flags --depth '${{inputs.depth}}' '${{inputs.repository}}' tag '${{inputs.tag}}' + elif [ -n '${{inputs.branch}}' ]; then + git -C $referenceRepo fetch --progress $git_clone_flags --depth '${{inputs.depth}}' '${{inputs.repository}}' '${{inputs.branch}}:${{inputs.branch}}' + elif + git -C $referenceRepo fetch --progress $git_clone_flags --depth '${{inputs.depth}}' '${{inputs.repository}}' HEAD:main + fi + # Do clone like before, but with reference + cd $workdir tar -c . | (cd $clone_fullpath && tar -x) rm -rf $workdir cd $clone_fullpath - git config --global --add safe.directory $clone_fullpath if [ -z "${{inputs.expected-commit}}" ]; then echo "Warning (git-checkout): no expected-commit" elif [ -n '${{inputs.branch}}' ]; then - git config --global advice.detachedHead false remote_commit=$(git rev-parse --verify --end-of-options "refs/heads/${{inputs.branch}}") if [[ '${{inputs.expected-commit}}' != "$remote_commit" ]]; then echo "Error (git-checkout): expect commit ${{inputs.expected-commit}}, got $remote_commit"