Merge pull request #80091 from NixOS/npregit-dumpall
nix-prefetch-git: report deepClone & leaveDotGit
This commit is contained in:
commit
477ea066ca
@ -25,7 +25,7 @@ commitDateStrict8601=
|
|||||||
if test -n "$deepClone"; then
|
if test -n "$deepClone"; then
|
||||||
deepClone=true
|
deepClone=true
|
||||||
else
|
else
|
||||||
deepClone=false
|
deepClone=
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if test "$leaveDotGit" != 1; then
|
if test "$leaveDotGit" != 1; then
|
||||||
@ -53,6 +53,11 @@ Options:
|
|||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# some git commands print to stdout, which would contaminate our JSON output
|
||||||
|
clean_git(){
|
||||||
|
git "$@" >&2
|
||||||
|
}
|
||||||
|
|
||||||
argi=0
|
argi=0
|
||||||
argfun=""
|
argfun=""
|
||||||
for arg; do
|
for arg; do
|
||||||
@ -65,7 +70,7 @@ for arg; do
|
|||||||
--branch-name) argfun=set_branchName;;
|
--branch-name) argfun=set_branchName;;
|
||||||
--deepClone) deepClone=true;;
|
--deepClone) deepClone=true;;
|
||||||
--quiet) QUIET=true;;
|
--quiet) QUIET=true;;
|
||||||
--no-deepClone) deepClone=false;;
|
--no-deepClone) deepClone=;;
|
||||||
--leave-dotGit) leaveDotGit=true;;
|
--leave-dotGit) leaveDotGit=true;;
|
||||||
--fetch-submodules) fetchSubmodules=true;;
|
--fetch-submodules) fetchSubmodules=true;;
|
||||||
--builder) builder=true;;
|
--builder) builder=true;;
|
||||||
@ -98,9 +103,9 @@ fi
|
|||||||
|
|
||||||
init_remote(){
|
init_remote(){
|
||||||
local url=$1
|
local url=$1
|
||||||
git init
|
clean_git init
|
||||||
git remote add origin "$url"
|
clean_git remote add origin "$url"
|
||||||
( [ -n "$http_proxy" ] && git config http.proxy "$http_proxy" ) || true
|
( [ -n "$http_proxy" ] && clean_git config http.proxy "$http_proxy" ) || true
|
||||||
}
|
}
|
||||||
|
|
||||||
# Return the reference of an hash if it exists on the remote repository.
|
# Return the reference of an hash if it exists on the remote repository.
|
||||||
@ -141,8 +146,8 @@ checkout_hash(){
|
|||||||
hash=$(hash_from_ref "$ref")
|
hash=$(hash_from_ref "$ref")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
git fetch -t ${builder:+--progress} origin || return 1
|
clean_git fetch -t ${builder:+--progress} origin || return 1
|
||||||
git checkout -b "$branchName" "$hash" || return 1
|
clean_git checkout -b "$branchName" "$hash" || return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
# Fetch only a branch/tag and checkout it.
|
# Fetch only a branch/tag and checkout it.
|
||||||
@ -150,7 +155,7 @@ checkout_ref(){
|
|||||||
local hash="$1"
|
local hash="$1"
|
||||||
local ref="$2"
|
local ref="$2"
|
||||||
|
|
||||||
if "$deepClone"; then
|
if [[ -n "$deepClone" ]]; then
|
||||||
# The caller explicitly asked for a deep clone. Deep clones
|
# The caller explicitly asked for a deep clone. Deep clones
|
||||||
# allow "git describe" and similar tools to work. See
|
# allow "git describe" and similar tools to work. See
|
||||||
# https://marc.info/?l=nix-dev&m=139641582514772
|
# https://marc.info/?l=nix-dev&m=139641582514772
|
||||||
@ -164,8 +169,8 @@ checkout_ref(){
|
|||||||
|
|
||||||
if test -n "$ref"; then
|
if test -n "$ref"; then
|
||||||
# --depth option is ignored on http repository.
|
# --depth option is ignored on http repository.
|
||||||
git fetch ${builder:+--progress} --depth 1 origin +"$ref" || return 1
|
clean_git fetch ${builder:+--progress} --depth 1 origin +"$ref" || return 1
|
||||||
git checkout -b "$branchName" FETCH_HEAD || return 1
|
clean_git checkout -b "$branchName" FETCH_HEAD || return 1
|
||||||
else
|
else
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
@ -174,7 +179,7 @@ checkout_ref(){
|
|||||||
# Update submodules
|
# Update submodules
|
||||||
init_submodules(){
|
init_submodules(){
|
||||||
# Add urls into .git/config file
|
# Add urls into .git/config file
|
||||||
git submodule init
|
clean_git submodule init
|
||||||
|
|
||||||
# list submodule directories and their hashes
|
# list submodule directories and their hashes
|
||||||
git submodule status |
|
git submodule status |
|
||||||
@ -248,7 +253,7 @@ make_deterministic_repo(){
|
|||||||
|
|
||||||
# Remove all remote branches.
|
# Remove all remote branches.
|
||||||
git branch -r | while read -r branch; do
|
git branch -r | while read -r branch; do
|
||||||
git branch -rD "$branch" >&2
|
clean_git branch -rD "$branch"
|
||||||
done
|
done
|
||||||
|
|
||||||
# Remove tags not reachable from HEAD. If we're exactly on a tag, don't
|
# Remove tags not reachable from HEAD. If we're exactly on a tag, don't
|
||||||
@ -256,19 +261,19 @@ make_deterministic_repo(){
|
|||||||
maybe_tag=$(git tag --points-at HEAD)
|
maybe_tag=$(git tag --points-at HEAD)
|
||||||
git tag --contains HEAD | while read -r tag; do
|
git tag --contains HEAD | while read -r tag; do
|
||||||
if [ "$tag" != "$maybe_tag" ]; then
|
if [ "$tag" != "$maybe_tag" ]; then
|
||||||
git tag -d "$tag" >&2
|
clean_git tag -d "$tag"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
# Do a full repack. Must run single-threaded, or else we lose determinism.
|
# Do a full repack. Must run single-threaded, or else we lose determinism.
|
||||||
git config pack.threads 1
|
clean_git config pack.threads 1
|
||||||
git repack -A -d -f
|
clean_git repack -A -d -f
|
||||||
rm -f .git/config
|
rm -f .git/config
|
||||||
|
|
||||||
# Garbage collect unreferenced objects.
|
# Garbage collect unreferenced objects.
|
||||||
# Note: --keep-largest-pack prevents non-deterministic ordering of packs
|
# Note: --keep-largest-pack prevents non-deterministic ordering of packs
|
||||||
# listed in .git/objects/info/packs by only using a single pack
|
# listed in .git/objects/info/packs by only using a single pack
|
||||||
git gc --prune=all --keep-largest-pack
|
clean_git gc --prune=all --keep-largest-pack
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -369,7 +374,9 @@ print_results() {
|
|||||||
"rev": "$(json_escape "$fullRev")",
|
"rev": "$(json_escape "$fullRev")",
|
||||||
"date": "$(json_escape "$commitDateStrict8601")",
|
"date": "$(json_escape "$commitDateStrict8601")",
|
||||||
"$(json_escape "$hashType")": "$(json_escape "$hash")",
|
"$(json_escape "$hashType")": "$(json_escape "$hash")",
|
||||||
"fetchSubmodules": $([[ -n "$fetchSubmodules" ]] && echo true || echo false)
|
"fetchSubmodules": $([[ -n "$fetchSubmodules" ]] && echo true || echo false),
|
||||||
|
"deepClone": $([[ -n "$deepClone" ]] && echo true || echo false),
|
||||||
|
"leaveDotGit": $([[ -n "$leaveDotGit" ]] && echo true || echo false)
|
||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
fi
|
fi
|
||||||
|
Loading…
x
Reference in New Issue
Block a user