From a8671d2bc9cd471d57fcafbd7bb63646996e6355 Mon Sep 17 00:00:00 2001 From: Marek Date: Sun, 19 Apr 2026 19:21:35 +0200 Subject: [PATCH] update --- sync.sh | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100755 sync.sh diff --git a/sync.sh b/sync.sh new file mode 100755 index 0000000..a2dc2dd --- /dev/null +++ b/sync.sh @@ -0,0 +1,77 @@ +#!/usr/bin/env bash +# Geht durch alle Git-Repos unter ~/projects/ und führt +# pull, add, commit, push aus. Am Ende: Zusammenfassung. + +set -u + +PROJECTS_DIR="$HOME/projects" + +ok=() +no_changes=() +pull_failed=() +push_failed=() +no_upstream=() +not_a_repo=() + +for dir in "$PROJECTS_DIR"/*/; do + [ -d "$dir" ] || continue + name="$(basename "$dir")" + + if [ ! -d "$dir/.git" ]; then + not_a_repo+=("$name") + continue + fi + + echo "=== $name ===" + cd "$dir" || continue + + if ! git pull --ff-only; then + echo ">> Pull-Konflikt oder Fehler in '$name' – übersprungen" + pull_failed+=("$name") + continue + fi + + git add -A + if git diff --cached --quiet; then + committed=false + else + git commit -m "update" + committed=true + fi + + if ! git rev-parse --abbrev-ref --symbolic-full-name '@{u}' >/dev/null 2>&1; then + echo ">> Kein Upstream gesetzt für '$name'" + no_upstream+=("$name") + continue + fi + + if git push; then + if [ "$committed" = true ]; then + ok+=("$name") + else + no_changes+=("$name") + fi + else + echo ">> Push fehlgeschlagen für '$name'" + push_failed+=("$name") + fi +done + +echo +echo "==========================================" +echo " Zusammenfassung" +echo "==========================================" +print_group() { + local label="$1"; shift + if [ "$#" -gt 0 ]; then + echo "$label ($#):" + printf ' - %s\n' "$@" + fi +} + +print_group "Erfolgreich gepusht" "${ok[@]:+${ok[@]}}" +print_group "Keine Änderungen" "${no_changes[@]:+${no_changes[@]}}" +print_group "Pull-Konflikt/Fehler" "${pull_failed[@]:+${pull_failed[@]}}" +print_group "Push fehlgeschlagen" "${push_failed[@]:+${push_failed[@]}}" +print_group "Kein Upstream" "${no_upstream[@]:+${no_upstream[@]}}" +print_group "Kein Git-Repo" "${not_a_repo[@]:+${not_a_repo[@]}}"