#!/bin/sh

set -e

po=$1

if test -z "$po"
then
    po=$(git config --get remote.origin.url)
    po=${po%/}
    po=${po%.git}
    case "$po" in
      *gitlab.com*)
        po=git@gitlab.com:jo-so/${po##*/}.git
        ;;

      *github.com*)
        # po=https://github.com/jo-so/${po##*/}
        po=git@github.com:jo-so/${po##*/}.git
        ;;

      *)
        echo 'Parameter missing: please provide a push URL' >&2
        exit 1
    esac
fi

git remote add push-origin "$po"
git config branch."$(git symbolic-ref --short HEAD)".pushRemote push-origin
