39 lines
1.2 KiB
Bash
Executable File
39 lines
1.2 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
CSV_FILE="repos.csv"
|
|
IFS=,
|
|
while read -r name url type target directory; do
|
|
if [ "$name" = "name" ]; then continue; fi
|
|
echo "\n[Repo] $name -> $directory"
|
|
if [ ! -d "$directory" ]; then
|
|
echo "[Clone] $url"
|
|
git clone --progress "$url" "$directory" || true
|
|
fi
|
|
echo "[Fetch] $directory"
|
|
git -C "$directory" fetch --all --prune --tags --progress || true
|
|
case "$type" in
|
|
branch)
|
|
echo "[Checkout] $target"
|
|
if git -C "$directory" show-ref --verify --quiet "refs/remotes/origin/$target"; then
|
|
git -C "$directory" checkout "$target" 2>/dev/null || git -C "$directory" checkout -B "$target" "origin/$target"
|
|
git -C "$directory" reset --hard "origin/$target"
|
|
else
|
|
echo "[Warn] Branche $target introuvable pour $name"
|
|
fi
|
|
;;
|
|
create_from)
|
|
base="${target%%->*}"
|
|
newb="${target##*->}"
|
|
echo "[Create] $newb depuis $base"
|
|
if git -C "$directory" show-ref --verify --quiet "refs/remotes/origin/$base"; then
|
|
git -C "$directory" checkout -B "$newb" "origin/$base"
|
|
else
|
|
echo "[Error] Base $base introuvable pour $name"
|
|
fi
|
|
;;
|
|
*)
|
|
echo "[Warn] Type inconnu: $type"
|
|
;;
|
|
esac
|
|
done < "$CSV_FILE"
|