2020-11-14 14:43:46 +01:00
|
|
|
#!/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
|
2020-12-04 14:49:45 +01:00
|
|
|
git submodule foreach git reset --hard origin/master > /dev/null 2>&1
|
2020-11-14 14:43:46 +01:00
|
|
|
|
|
|
|
for remote in $(ssh git@subgit.ugent.be task students -l "$task" | cut -f4); do
|
2020-12-13 00:36:28 +01:00
|
|
|
if [ -d "$(basename "$remote")" ]; then continue; fi # exists
|
|
|
|
remotes="$(git ls-remote "$remote")"
|
|
|
|
if ! echo "$remotes" | grep -q HEAD; then
|
|
|
|
printf 'No HEAD at %s' "$remote"
|
|
|
|
count="$(echo "$remotes" | grep -o refs/heads | wc -l)"
|
|
|
|
if [ "$count" -gt 0 ]; then printf ' (but %d other)' "$count"; fi
|
|
|
|
printf '\n'
|
2020-11-14 14:43:46 +01:00
|
|
|
else
|
|
|
|
echo "adding $remote"
|
2020-12-04 14:49:45 +01:00
|
|
|
git submodule --quiet add --force "$remote" || true
|
2020-11-14 14:43:46 +01:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
git add .
|
|
|
|
git commit -v
|