2023-06-09 17:22:46 +02:00
|
|
|
#!/bin/bash
|
|
|
|
set -e
|
2024-05-19 14:19:10 +02:00
|
|
|
shopt -s nullglob
|
2023-06-09 17:22:46 +02:00
|
|
|
|
|
|
|
subdirs_path=$(dirname -- "$(realpath -- "$0")")
|
|
|
|
cd "$subdirs_path"
|
|
|
|
|
|
|
|
declare -A repo_names=(
|
|
|
|
[c++utilities]=cpp-utilities
|
|
|
|
[qtutilities]=
|
|
|
|
[qtforkawesome]=
|
|
|
|
[syncthingtray]=
|
|
|
|
[tagparser]=
|
|
|
|
[tageditor]=
|
|
|
|
[passwordfile]=
|
|
|
|
[passwordmanager]=
|
|
|
|
[videodownloader]=
|
|
|
|
[reflective-rapidjson]=
|
|
|
|
[dbus-soundrecorder]=
|
|
|
|
[geocoordinatecalculator]=
|
2023-06-10 23:40:51 +02:00
|
|
|
[auto-makepkg]=arch-repo-manager
|
2024-02-05 23:46:31 +01:00
|
|
|
[PianoBooster]=
|
2023-06-11 01:03:30 +02:00
|
|
|
[subdirs]=
|
2023-06-09 17:22:46 +02:00
|
|
|
)
|
|
|
|
|
2024-05-19 13:58:07 +02:00
|
|
|
[[ $# -gt 0 ]] && relevant_dirs=("$@") || relevant_dirs=("${!repo_names[@]}")
|
|
|
|
|
2023-06-09 17:22:46 +02:00
|
|
|
# ensure a clone of all repositories exists
|
2024-05-19 13:58:07 +02:00
|
|
|
for dir in "${relevant_dirs[@]}"; do
|
2023-06-09 17:22:46 +02:00
|
|
|
[[ -d ../$dir/.git ]] && continue
|
|
|
|
echo "==> Cloning $dir"
|
|
|
|
repo=${repo_names[$dir]:-$dir}
|
2023-06-09 18:01:09 +02:00
|
|
|
git -C .. clone -c core.symlinks=true "git@github.com:Martchus/$repo.git" "$dir"
|
2023-06-09 17:22:46 +02:00
|
|
|
done
|
|
|
|
|
2023-06-11 01:03:30 +02:00
|
|
|
# ensure the fallback repo is added
|
2024-05-19 13:58:07 +02:00
|
|
|
for dir in "${relevant_dirs[@]}"; do
|
|
|
|
[[ -d ../$dir/.git ]] && continue
|
2023-06-11 01:03:30 +02:00
|
|
|
repo=${repo_names[$dir]:-$dir}
|
|
|
|
if ! git -C "../$dir" remote show gitea &> /dev/null ; then
|
|
|
|
echo "==> Adding fallback remote for $dir"
|
|
|
|
git -C "../$dir" remote add gitea "gitea@martchus.no-ip.biz:Martchus/$repo.git"
|
|
|
|
fi
|
|
|
|
if ! git -C "../$dir" remote show all &> /dev/null ; then
|
|
|
|
echo "==> Configuring 'all' remote for $dir"
|
|
|
|
git -C "../$dir" remote add all "git@github.com:Martchus/$repo.git"
|
|
|
|
git -C "../$dir" remote set-url --add --push all "git@github.com:Martchus/$repo.git"
|
|
|
|
git -C "../$dir" remote set-url --add --push all "gitea@martchus.no-ip.biz:Martchus/$repo.git"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2023-06-09 17:22:46 +02:00
|
|
|
# ensure all repositories are up-to-date
|
2024-05-19 13:58:07 +02:00
|
|
|
[[ $# -gt 0 ]] && relevant_dirs=("${relevant_dirs[@]/#/../}") || relevant_dirs=(../*)
|
|
|
|
for dir in "${relevant_dirs[@]}"; do
|
2023-06-09 17:22:46 +02:00
|
|
|
[[ -d $dir/.git ]] || continue
|
|
|
|
echo "==> Updating $dir"
|
|
|
|
git -C "$dir" remote update
|
|
|
|
branch_name=$(git -C "$dir" symbolic-ref -q HEAD)
|
|
|
|
branch_name=${branch_name##refs/heads/}
|
|
|
|
branch_name=${branch_name:-DETACHED}
|
2023-07-23 21:40:14 +02:00
|
|
|
|
|
|
|
# try pushing local changes first
|
|
|
|
if git -C "$dir" push -u all master:master ; then
|
|
|
|
git -C "$dir" remote update
|
2024-05-19 14:19:10 +02:00
|
|
|
else
|
|
|
|
echo "Unable to push local changes of '$dir' to master, trying to rebase anyway."
|
2023-07-23 21:40:14 +02:00
|
|
|
fi
|
|
|
|
|
2024-05-19 14:19:10 +02:00
|
|
|
# clean files like "git-config.exe.stackdump"
|
|
|
|
files_to_delete=("$dir"/*.stackdump)
|
|
|
|
if [[ ${#files_to_delete[@]} -gt 0 ]]; then
|
|
|
|
echo "Deleting junk files within '$dir':"
|
|
|
|
rm -v "${files_to_delete[@]}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# reset to current master
|
|
|
|
if [[ $branch_name != DETACHED && $branch_name != master ]]; then
|
|
|
|
echo "Not touching '$dir' - it isn't on master or a detached had (it is on $branch_name)."
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
if output=$(git -C "$dir" status --porcelain) && [[ -z $output ]]; then
|
2023-06-09 17:22:46 +02:00
|
|
|
git -C "$dir" reset --hard origin/master
|
2024-05-19 14:19:10 +02:00
|
|
|
else
|
|
|
|
echo "Not touching '$dir' - it isn't clean:\n$output"
|
2023-06-09 17:22:46 +02:00
|
|
|
fi
|
|
|
|
done
|
2023-07-23 21:40:14 +02:00
|
|
|
|