alchi/src/scripts/git-remote-add-all.sh

93 lines
2.2 KiB
Bash
Raw Permalink Normal View History

2023-10-06 21:43:30 +02:00
#!/usr/bin/env bash
main_branches="master journal"
2023-12-27 10:24:34 +01:00
username=milahu
2023-10-06 21:43:30 +02:00
2023-12-27 10:24:34 +01:00
force=true
2023-10-06 21:43:30 +02:00
function git_remote_add() {
local name="$1"
local url="$2"
2023-12-27 10:24:34 +01:00
exists=false
2023-10-06 21:43:30 +02:00
if git remote get-url "$name" >/dev/null 2>&1; then
2023-12-27 10:24:34 +01:00
exists=true
fi
if ! $force && $exists; then
2023-10-06 21:43:30 +02:00
# remote with this name already exists
echo "remote exists: $name"
return
fi
2023-12-27 10:24:34 +01:00
# add username
url="$(echo "$url" | sed -E "s|^(https?://)|\1${username}@|")"
if ! $exists; then
echo "adding remote: $name"
git remote add "$name" "$url"
else
echo "updating remote: $name"
git remote set-url "$name" "$url"
fi
2023-10-06 21:43:30 +02:00
if echo "$name" | grep -q '.onion$'; then
2023-12-27 10:24:34 +01:00
echo "torifying remote: $name"
2023-10-06 21:43:30 +02:00
git config --add "remote.$name.proxy" socks5h://127.0.0.1:9050
fi
}
git_remote_add github.com https://github.com/milahu/alchi
git_remote_add gitlab.com https://gitlab.com/milahu/alchi
git_remote_add codeberg.org https://codeberg.org/milahu/alchi
git_remote_add sourceforge.net https://git.code.sourceforge.net/p/milahu-alchi/code
git_remote_add notabug.org https://notabug.org/milahu/alchi
git_remote_add disroot.org https://git.disroot.org/milahu/alchi
2023-11-14 18:11:56 +01:00
git_remote_add sr.ht git@git.sr.ht:~milahu/alchi
2023-10-06 21:43:30 +02:00
git_remote_add darktea.onion http://it7otdanqu7ktntxzm427cba6i53w6wlanlh23v5i3siqmos47pzhvyd.onion/milahu/alchi
2023-10-07 01:32:49 +02:00
git_remote_add righttoprivacy.onion http://gg6zxtreajiijztyy5g6bt5o6l3qu32nrg7eulyemlhxwwl6enk6ghad.onion/milahu/alchi
2023-10-06 21:43:30 +02:00
# done
exit 0
# not needed?
# what problem should this solve?
if false; then
# fix error: There are multiple remotes whose fetch refspecs map to the remote
# caused by: git branch --set-upstream-to=...
if origin_url=$(git remote get-url origin); then
new_origin_name=""
git remote show | grep -v -x origin | while read remote; do
remote_url=$(git remote get-url $remote)
if [[ "$origin_url" == "$remote_url" ]]; then
new_origin_name="$remote"
break
fi
done
if [[ -n "$new_origin_name" ]]; then
git remote remove origin
# use the previous "origin" as default remote, so we can just "git pull" and "git push"
for branch in $main_branches; do
git branch --set-upstream-to=$new_origin_name/$branch $branch
fi
fi
fi
fi