kiss: Further simplify git source handling

This commit is contained in:
Dylan Araps 2020-06-11 10:34:53 +03:00
parent c1bdf283f2
commit 2cdc994e41
No known key found for this signature in database
GPG Key ID: 46D62DD9F1DE636E

34
kiss
View File

@ -247,32 +247,18 @@ pkg_extract() {
case $src in \#*|'') ;; case $src in \#*|'') ;;
# Git repository. # Git repository.
git+*) git+*)
url=${src##git+} # Split the source into URL + OBJECT (branch or commit).
log "$1" "Cloning ${url%[@#]*}" url=${src##git+} com=${url##*[@#]} com=${com#${url%[#@]*}}
# Intelligently clone git repositories, pulling down as little # This magic will shallow clone branches, commits or the
# as possible. All clones are done using '--depth 1'. Commit # regular repository. It correctly handles cases where a
# clones aren't supported by every remote (GitHub/GitLab support # shallow clone is not possible.
# them) so a fallback is available. log "$1" "Cloning ${url%[#@]*}"; {
case $url in
# Branch clones.
*'@'*) git clone --depth=1 -b "${src##*@}" "${url%@*}" . ;;
# Commit clones.
*'#'*)
git init git init
git remote add origin "${url%#*}" git remote add origin "${url%[#@]*}"
git fetch --depth=1 origin "$com" || git fetch
git fetch --depth=1 origin "${url##*#}" || git fetch git checkout "${com:-FETCH_HEAD}"
} || die "$1" "Failed to clone $src"
git checkout "${url##*#}" ||
die "Commit hash ${url##*#} not found"
;;
# Regular clones.
*) git clone --depth=1 "$url" .
esac || die "$1" "Failed to clone $src"
;; ;;
# Tarballs of any kind. This is a shell equivalent of # Tarballs of any kind. This is a shell equivalent of