aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordylan.araps@gmail.com <dylan.araps@gmail.com>2020-02-19 14:11:02 +0000
committerdylan.araps@gmail.com <dylan.araps@gmail.com>2020-02-19 14:11:02 +0000
commit431522e3e711803c87d27ef935831541b0d6d91f (patch)
treef980d8a63f73ee24e11c76ab95f6ba44666303b2
parent027b4915ea60fb7277cfce452b1aaff02c40d92b (diff)
downloadcpt-431522e3e711803c87d27ef935831541b0d6d91f.tar.gz
kiss: shallow branch support
FossilOrigin-Name: 0f36586c97a34cfa6d4df3cb3deb9d206e2b186026c7410835462f43f6aa8257
-rwxr-xr-xkiss45
1 files changed, 23 insertions, 22 deletions
diff --git a/kiss b/kiss
index f698c13..1aed25d 100755
--- a/kiss
+++ b/kiss
@@ -187,22 +187,27 @@ pkg_sources() {
mkdir -p "$mak_dir/$1/$dest"
- # Run in a subshell to keep variables local.
+ # Run in a subshell to keep the variables, path and
+ # argument list local to each loop iteration.
(
repo_src=${src##git+}
- log "$1" "Cloning ${repo_src%#*}"
+ log "$1" "Cloning ${repo_src%[@#]*}"
- # If a commit hash or branch was given, grab the latest
- # commit from all branches. This gives a speed-up when
- # wanting to checkout a specific branch.
- [ "${src##*#*}" ] ||
- branch=--no-single-branch
+ # Git has no option to clone a repository to a
+ # specific location so we must do it ourselves
+ # beforehand.
+ cd "$mak_dir/$1/$dest" || die 2>/dev/null
+
+ # 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.
+ [ "${src##*@*}" ] && set -- ||
+ set -- -b "${src##*@}" "${repo_src%@*}"
# Always do a shallow clone as we will unshallow it if
# needed later (when a commit is desired).
- cd "$mak_dir/$1/$dest" &&
- git clone --depth=1 "${branch:---}" "${repo_src%#*}" .
+ git clone --depth=1 "${@:-${repo_src%#*}}" .
) || die "$1" "Failed to clone $src"
@@ -241,19 +246,15 @@ pkg_extract() {
log "Checking out ${src##*#}"
(
- set -- git -c advice.detachedHead=false checkout
-
- # Try to checkout the commit or branch. If it fails,
- # unshallow the repository as we're dealing with a
- # specific commit.
- "$@" "${src##*#}" >/dev/null 2>&1 ||
- git fetch --unshallow
-
- # Checkout the repository a second time. If this
- # fails, the desired commit or branch doesn't exist.
- # This will do nothing if the above checkout succeeded.
- "$@" "${src##*#}" 2>/dev/null ||
- die "${src##*#} doesn't exist"
+ # A commit was requested, unshallow the repository.
+ # This will convert it to a regular repository with
+ # full history.
+ git fetch --unshallow
+
+ # Try to checkout the repository. If we fail here,
+ # the requested commit doesn't exist.
+ git -c advice.detachedHead=false checkout "${src##*#}" ||
+ die "Commit hash ${src##*#} doesn't exist"
)
;;