33 lines
1005 B
Bash
Executable File
33 lines
1005 B
Bash
Executable File
#!/bin/bash
|
|
|
|
checkout-git-folder() {
|
|
if [[ -z "$1" ]]; then
|
|
echo '$1/branch is empty.'
|
|
exit
|
|
fi
|
|
if [[ -z "$2" ]]; then
|
|
echo '$2/path is empty.'
|
|
exit
|
|
fi
|
|
|
|
local git_branch="$1"
|
|
local git_folders=$(ls-git-folder "$2")
|
|
for git_folder in $git_folders; do
|
|
|
|
git_folder="${git_folder#./}"
|
|
|
|
local shallow=$(git config --file .gitmodules --get submodule."$git_folder".shallow)
|
|
local commit_ref=$(grep "$git_folder" ".gitmodules.csv" | cut -d',' -f2)
|
|
|
|
if [[ "$shallow" = "true" ]]; then
|
|
echo "Checkout git folder $git_folder (shallow) to $commit_ref"
|
|
git -C "$git_folder" stash
|
|
git -C "$git_folder" fetch origin "$git_branch:$git_branch"
|
|
git -C "$git_folder" checkout "$commit_ref"
|
|
else
|
|
echo "Checkout git folder $git_folder to $commit_ref"
|
|
git -C "$git_folder" stash
|
|
git -C "$git_folder" checkout "$commit_ref"
|
|
fi
|
|
done
|
|
} |