#!/bin/bash

# See ./reg-test/run and ./reg-test/README.md for background on this
# keystroke-saver.

set -euo pipefail
us=$(basename $0)

if [ $# -ne 2 ]; then
    echo "Usage: $us {case-old-name.sh} {case-new-name.sh}"
    exit 1
fi
old=$(basename $1)
new=$(basename $2)

old_sh=reg-test/cases/$old
old_out=reg-test/expected/$old.out
old_err=reg-test/expected/$old.err

new_sh=reg-test/cases/$new
new_out=reg-test/expected/$new.out
new_err=reg-test/expected/$new.err

if [ ! -f $old_sh ]; then
  echo "Can't find case file $old_sh"
  exit 1
fi

if [ ! -f $old_out ]; then
  echo "Can't find output file $old_out"
  exit 1
fi

if [ -f $new_sh ]; then
  echo "This would overwrite existing case file $new_sh"
  exit 1
fi

if [ -f $new_out ]; then
  echo "This would overwrite existing output file $new_out"
  exit 1
fi

git mv $old_sh $new_sh
git mv $old_out $new_out
if [ -f "$old_err" ]; then
  git mv $old_err $new_err
fi
