#!/usr/bin/env bash

set -euo pipefail

old=$1
new=$2

test -z "$old" && echo "old remote name required." 1>&2 && exit 1
test -z "$new" && echo "new remote name required." 1>&2 && exit 1

if ! git config --get "remote.$old.fetch" > /dev/null; then
  echo "remote $old doesn't exist"
  exit 1
fi

if git config --get "remote.$new.fetch" > /dev/null; then
  git remote remove "$new"
fi
git remote rename "$old $new"
git remote -v
