#!/usr/bin/env bash

# you should never call this script from a non-public repository, but just in
# case...
if [ ! -f "git-daemon-export-ok" ] || [ ! -f "category" ]; then
    exit 1
fi

set -e

eval $(ssh-agent -s)
ssh-add /srv/git/.ssh/id_ed25519_sourcehut

trap "notify \"ERROR pushing $repo\" \"There was an error pushing $repo to either SourceHut or Codeberg.\"" ERR

dir="$(pwd)"
repo="$(basename "$(pwd)" ".git")"

git -C "$dir" remote get-url srht || \
    git -C "$dir" remote add srht "git@git.sr.ht:~hwchen/$repo"
git -C "$dir" push --all --force --prune srht
git -C "$dir" push --tags --force --prune srht

#git -C "$dir" remote get-url codeberg || \
#    git -C "$dir" remote add codeberg "git@codeberg.org:hwchen/$repo"
#git -C "$dir" push --all --force --prune codeberg
#git -C "$dir" push --tags --force --prune codeberg
