2021-06-02 08:34:18 +02:00
|
|
|
#!/usr/bin/env bash
|
2020-11-26 07:44:59 +01:00
|
|
|
set -euo pipefail
|
|
|
|
|
|
|
|
if [ ! -d "$HOME/GitProjects" ]; then
|
|
|
|
mkdir "$HOME/GitProjects"
|
|
|
|
fi
|
|
|
|
|
|
|
|
WORKPATH="$HOME/GitProjects"
|
|
|
|
|
2022-06-30 15:00:13 +02:00
|
|
|
readarray -t dirs < <(find "$WORKPATH" -mindepth 1 -maxdepth 1 -type d -printf '%P\n')
|
|
|
|
|
|
|
|
for dir in "${dirs[@]}"; do
|
|
|
|
# go into GitProjects directory
|
|
|
|
cd "$WORKPATH"
|
|
|
|
# output directory you're currently working on
|
|
|
|
printf "Working on ${dir}\n"
|
|
|
|
# change into that directory
|
|
|
|
cd "$dir"
|
|
|
|
# try to check out master or main branch
|
2022-07-04 20:18:31 +02:00
|
|
|
git checkout -q master 2>/dev/null \
|
|
|
|
|| git checkout -q main 2>/dev/null
|
|
|
|
# check whether the previous two commands failed
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
printf "Couldn't find master or main branches\n"
|
|
|
|
exit 1
|
|
|
|
fi
|
2022-06-30 15:00:13 +02:00
|
|
|
git fetch --all
|
2022-06-30 15:01:42 +02:00
|
|
|
git pull
|
2022-06-30 15:00:13 +02:00
|
|
|
done
|
2021-03-07 16:03:39 +01:00
|
|
|
|
2020-11-26 07:44:59 +01:00
|
|
|
exit 0
|