Merge pull request #11671 from timbertson/fetchgit

fetchgit: output improvements
This commit is contained in:
zimbatm 2016-02-27 22:45:07 +00:00
commit de124cfa79

View File

@ -12,6 +12,11 @@ fetchSubmodules=
builder= builder=
branchName=$NIX_PREFETCH_GIT_BRANCH_NAME branchName=$NIX_PREFETCH_GIT_BRANCH_NAME
# populated by clone_user_rev()
fullRev=
humanReadableRev=
commitDate=
if test -n "$deepClone"; then if test -n "$deepClone"; then
deepClone=true deepClone=true
else else
@ -52,6 +57,7 @@ for arg; do
--hash) argfun=set_hashType;; --hash) argfun=set_hashType;;
--branch-name) argfun=set_branchName;; --branch-name) argfun=set_branchName;;
--deepClone) deepClone=true;; --deepClone) deepClone=true;;
--quiet) QUIET=true;;
--no-deepClone) deepClone=false;; --no-deepClone) deepClone=false;;
--leave-dotGit) leaveDotGit=true;; --leave-dotGit) leaveDotGit=true;;
--fetch-submodules) fetchSubmodules=true;; --fetch-submodules) fetchSubmodules=true;;
@ -254,7 +260,7 @@ make_deterministic_repo(){
} }
clone_user_rev() { _clone_user_rev() {
local dir="$1" local dir="$1"
local url="$2" local url="$2"
local rev="${3:-HEAD}" local rev="${3:-HEAD}"
@ -272,23 +278,60 @@ clone_user_rev() {
fi;; fi;;
esac esac
local full_revision=$(cd $dir && (git rev-parse $rev 2> /dev/null || git rev-parse refs/heads/$branchName) | tail -n1) fullRev="$(cd $dir && (git rev-parse $rev 2> /dev/null || git rev-parse refs/heads/$branchName) | tail -n1)"
echo "git revision is $full_revision" humanReadableRev="$(cd $dir && (git describe $fullRev 2> /dev/null || git describe --tags $fullRev 2> /dev/null || echo -- none --))"
echo "git human-readable version is $(cd $dir && (git describe $full_revision 2> /dev/null || git describe --tags $full_revision 2> /dev/null || echo -- none --))" >&2 commitDate="$(cd $dir && git show --no-patch --pretty=%ci $fullRev)"
echo "Commit date is $(cd $dir && git show --no-patch --pretty=%ci $full_revision)"
# Allow doing additional processing before .git removal # Allow doing additional processing before .git removal
eval "$NIX_PREFETCH_GIT_CHECKOUT_HOOK" eval "$NIX_PREFETCH_GIT_CHECKOUT_HOOK"
if test -z "$leaveDotGit"; then if test -z "$leaveDotGit"; then
echo "removing \`.git'..." >&2 echo "removing \`.git'..." >&2
find $dir -name .git\* | xargs rm -rf find "$dir" -name .git\* -print0 | xargs -0 rm -rf
else else
find $dir -name .git | while read gitdir; do find "$dir" -name .git | while read gitdir; do
make_deterministic_repo "$(readlink -f "$gitdir/..")" make_deterministic_repo "$(readlink -f "$gitdir/..")"
done done
fi fi
} }
clone_user_rev() {
if ! test -n "$QUIET"; then
_clone_user_rev "$@"
else
errfile="$(mktemp "${TMPDIR:-/tmp}/git-checkout-err-XXXXXXXX")"
trap "rm -rf \"$errfile\"" EXIT
_clone_user_rev "$@" 2> "$errfile" || (
status="$?"
cat "$errfile" >&2
exit "$status"
)
fi
}
print_results() {
hash="$1"
if ! test -n "$QUIET"; then
echo "" >&2
echo "git revision is $fullRev" >&2
if test -n "$finalPath"; then
echo "path is $finalPath" >&2
fi
echo "git human-readable version is $humanReadableRev" >&2
echo "Commit date is $commitDate" >&2
if test -n "$hash"; then
echo "hash is $hash" >&2
fi
fi
if test -n "$hash"; then
echo "{"
echo " url = \"$url\";"
echo " rev = \"$fullRev\";"
echo " $hashType = \"$hash\";"
echo "}"
fi
}
if test -z "$branchName"; then if test -z "$branchName"; then
branchName=fetchgit branchName=fetchgit
fi fi
@ -327,20 +370,18 @@ else
# Compute the hash. # Compute the hash.
hash=$(nix-hash --type $hashType --base32 $tmpFile) hash=$(nix-hash --type $hashType --base32 $tmpFile)
if ! test -n "$QUIET"; then echo "hash is $hash" >&2; fi
# Add the downloaded file to the Nix store. # Add the downloaded file to the Nix store.
finalPath=$(nix-store --add-fixed --recursive "$hashType" "$tmpFile") finalPath=$(nix-store --add-fixed --recursive "$hashType" "$tmpFile")
if test -n "$expHash" -a "$expHash" != "$hash"; then if test -n "$expHash" -a "$expHash" != "$hash"; then
echo "hash mismatch for URL \`$url'" print_metadata
echo "hash mismatch for URL \`$url'" >&2
exit 1 exit 1
fi fi
fi fi
if ! test -n "$QUIET"; then echo "path is $finalPath" >&2; fi print_results "$hash"
echo $hash
if test -n "$PRINT_PATH"; then if test -n "$PRINT_PATH"; then
echo $finalPath echo $finalPath