-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgit-update.sh
More file actions
executable file
·68 lines (58 loc) · 1.6 KB
/
git-update.sh
File metadata and controls
executable file
·68 lines (58 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/bin/bash
# Standardwerte für Optionen setzen
PRJDIR="$HOME/Projekte"
CLEAN=true
COMPRESS=false
# Parameter verarbeiten
while [ $# -gt 0 ]; do
if [ "$1" == "--noclean" ]; then
CLEAN=false
elif [ "$1" == "--dir" ] && [ -n "$2" ] && [ -d "$2" ]; then
PRJDIR="$2"
elif [ "$1" == "--compress" ]; then
COMPRESS=true
else
echo "unbekannter Parameter $1"
exit 1
fi
shift
done
# Im Projektverzeichnis nach git Repositories suchen
# und diese aktualisieren
cd "$PRJDIR" || exit
echo "suche zu aktualisierende git Repositories"
for REPO in $(find . -name .git -type d | sort); do
cd "$PRJDIR" || exit
DIR=$(dirname "$REPO")
REPOPATH=$(realpath "$DIR")
REPONAME=$(basename "$REPOPATH")
cd "$REPOPATH" || exit
echo "Aktualisiere $REPONAME"
UPSTREAM=$(git remote -v | grep ups)
# Wenn es einen Upstream-Branch gibt, Änderungen mergen und pushen,
# ansonten nur Änderungen herunterladen
if [ -n "$UPSTREAM" ]; then
echo "Synchronisiere mit Upstream"
git fetch upstream
if [ "$(git branch -r | grep -c master)" -gt 0 ]; then
BRANCH="master"
elif [ "$(git branch -r | grep -c main)" -gt 0 ]; then
BRANCH="main"
fi
git checkout "$BRANCH"
git merge "upstream/$BRANCH"
git push
else
git pull
fi
if [ "$CLEAN" = true ]; then
echo "Räume auf"
git fetch -p -P
git clean -fd
fi
if [ "$COMPRESS" = true ]; then
echo "Komprimiere git Datenbank"
git gc --aggressive
fi
echo
done