nix-prefetch-git: restore the tag-related clone flags when leaving .git

When leaveDotGit == true,
restore the cloning behaviour before
commit 7e085677f9 ("nix-prefetch-git: dont't fetch tags when deep clone unless leaving .git")
to preserve the fragile hashes of .git sources.

Clean up fetchTagsCompat,
as fetchTagsCompat is no longer needed
after restoring the old tag-fetching flags.
This commit is contained in:
Yueh-Shun Li
2025-12-24 21:59:46 +08:00
parent 62b2dbef68
commit 09030960d5
+9 -13
View File
@@ -12,7 +12,6 @@ fetchSubmodules=
fetchLFS=
builder=
fetchTags=
fetchTagsCompat=
branchName=$NIX_PREFETCH_GIT_BRANCH_NAME
# ENV params
@@ -117,13 +116,6 @@ for arg; do
fi
done
# `deepClone` used to effectively imply `fetchTags`.
# We avoid such behaviour to enhance the `postCheckout` reproducibility,
# while keeping the old behaviour for `.git` for backward compatibility purposes.
if [[ -n "$deepClone" ]] && [[ -z "$leaveDotGit" ]]; then
fetchTagsCompat=true
fi
if test -z "$url"; then
usage
fi
@@ -188,11 +180,15 @@ checkout_hash(){
hash=$(hash_from_ref "$ref")
fi
local -a fetchTagsArgs
if [[ -n "$fetchTags" ]]; then
fetchTagsArgs=(--tags)
else
local -a fetchTagsArgs=()
# Avoid fetching all tags at clone time when not leaving .git,
# but keep/restore the behaviour before
# commit 7e085677f996 ("nix-prefetch-git: dont't fetch tags when deep clone unless leaving .git")
# to preserve the fragile hashes of existing .git sources.
if [[ -z "$leaveDotGit" ]]; then
fetchTagsArgs=(--no-tags)
elif [[ -n "$deepClone" ]]; then
fetchTagsArgs=(--tags)
fi
local -a fetchTargetArgs
if [[ -n "$deepClone" ]]; then
@@ -282,7 +278,7 @@ clone(){
# Fetch all tags if requested
# The fetched tags are potentially non-reproducible, as tags are mutable parts of the Git tree.
if [[ -n "$fetchTags" ]] || [[ -n "$fetchTagsCompat" ]]; then
if [[ -n "$fetchTags" ]]; then
echo "fetching all tags..." >&2
clean_git fetch origin 'refs/tags/*:refs/tags/*' || echo "warning: failed to fetch some tags" >&2
fi