kiss: Add shallow commit cloning

This commit is contained in:
Dylan Araps 2020-06-11 09:44:32 +03:00
parent a39e9d2410
commit c1bdf283f2
No known key found for this signature in database
GPG Key ID: 46D62DD9F1DE636E

18
kiss
View File

@ -250,22 +250,26 @@ pkg_extract() {
url=${src##git+}
log "$1" "Cloning ${url%[@#]*}"
# Intelligently clone git repositories, pulling down as little
# as possible. All clones are done using '--depth 1'. Commit
# clones aren't supported by every remote (GitHub/GitLab support
# them) so a fallback is available.
case $url in
# If a branch was given, shallow clone it directly.
# This speeds things up as we don't have to grab
# a lot of unneeded commits.
# Branch clones.
*'@'*) git clone --depth=1 -b "${src##*@}" "${url%@*}" . ;;
# If a commit was given, clone all branches as the
# given commit may not be in master.
# Commit clones.
*'#'*)
git clone "${url%#*}" .
git init
git remote add origin "${url%#*}"
git fetch --depth=1 origin "${url##*#}" || git fetch
git checkout "${url##*#}" ||
die "Commit hash ${url##*#} not found"
;;
# Simply shallow clone everything else.
# Regular clones.
*) git clone --depth=1 "$url" .
esac || die "$1" "Failed to clone $src"