Files
iopsyswrt/scripts/git_clone.sh
Andreas Gnau d80c4ca447 scripts: Clone git repositories using tree-less clone
This will save time downloading on servers that support it, because only
the checked out commit's trees and blobs are downloaded on checkout
while only the history is being downloaded for all other commits.

It will also save time compressing, because in IOWRT, we do not exclude
the .git directory from the tarballs.

Signed-off-by: Andreas Gnau <andreas.gnau@iopsys.eu>
2023-12-04 09:34:17 +00:00

49 lines
1.1 KiB
Bash
Executable File

#! /bin/bash
URL="$1"
SUBDIR="$2"
if [ $# -eq 4 ]; then
MIRROR="$3"
VERSION="$4"
elif [ $# -eq 5 ]; then
MIRROR="$3"
VERSION="$4"
REWRITE="$5"
else
echo "$0: Error, invalid number of arguments"
exit 1
fi
IOPSYS_URL="dev.iopsys.eu"
IOPSYS_HTTP_URL="https://"${IOPSYS_URL}
#first try to use mirror
# is this an inteno server ? in that case do not use the mirror
if [ -n "${MIRROR}" ] && [[ $URL != *${IOPSYS_URL}* ]]; then
repo=$(basename $URL)
MIRROR_URL=${MIRROR}/${repo}
echo "trying to clone from mirror ${MIRROR_URL}"
if git clone --filter=tree:0 ${MIRROR_URL} ${SUBDIR} --recursive; then
old="$PWD"
cd ${SUBDIR}
if git checkout ${VERSION}; then
exit 0
fi
# checkout failed mirror is not correct
cd $old
rm -rf cd ${SUBDIR}
fi
fi
if [ "$REWRITE" = y ] && [[ $URL == ${IOPSYS_HTTP_URL}* ]]; then
# clone with ssh
repo=$(echo $URL | sed "s ${IOPSYS_HTTP_URL}/ g")
URL="git@"${IOPSYS_URL}:${repo}
fi
#if not try the original
echo "No working mirror cloning from ${URL}"
git clone --filter=tree:0 ${URL} ${SUBDIR} --recursive