Files
git.taskfile.build/bin/download-git-folder
T

31 lines
1.2 KiB
Bash
Executable File

#!/usr/bin/env bash
download-git-folder() {
if [[ -z "$1" ]]; then
echo '$1/path is empty.'
exit
fi
local git_folders=$(ls-git-folder "$1")
for git_folder in $git_folders; do
local git_folder_path=$(git config --file .gitmodules --get submodule."$git_folder".path)
local git_folder_url=$(git config --file .gitmodules --get submodule."$git_folder".url)
local git_folder_branch=$(git config --file .gitmodules --get submodule."$git_folder".branch)
# Convert git url to http url.
git_folder_url="$(echo $git_folder_url | sed 's|git@|https://|g' | sed 's|m:|m/|g' | sed 's|\.git||g')"
# Get commit ref from .gitmodule.csv
local commit_ref=$(grep "$git_folder_path" ".gitmodules.csv" | cut -d',' -f2)
echo "Download $git_folder_url to $git_folder_path."
mkdir -p "$git_folder_path"
curl -L -o "$git_folder_path/archive.tar.gz" \
"$git_folder_url/archive/$commit_ref.tar.gz"
echo "Extract and delete $git_folder_path/archive.tar.gz"
tar -xzf "$git_folder_path/archive.tar.gz" --strip-components=1 -C "$git_folder_path"
rm "$git_folder_path/archive.tar.gz"
done
}