add script to fetch subgit repos

This commit is contained in:
Felix Van der Jeugt 2020-11-14 14:43:46 +01:00
parent b4fc540c87
commit 7eb71c1361
No known key found for this signature in database
GPG Key ID: 58B209295023754D

37
local/bin/subgit-fetch Executable file
View File

@ -0,0 +1,37 @@
#!/bin/sh
task="$1"
repo="$2"
set -e
if [ ! -d "$repo" ]; then
mkdir -p "$repo"
cd "$repo"
git init
else
cd "$repo"
fi
if [ ! -z "$(git status --porcelain)" ]; then
echo "Requires a clean working tree" >&2
exit 1
fi
# update existing submodules
git submodule foreach git fetch origin
git submodule foreach git reset --hard origin/master
for remote in $(ssh git@subgit.ugent.be task students -l "$task" | cut -f4); do
if [ -d "$(basename "$remote")" ]; then
true # exists
elif [ -z "$(git ls-remote "$remote")" ]; then
echo "No branches at $remote"
else
echo "adding $remote"
git submodule --quiet add "$remote"
fi
done
git add .
git commit -v