#!/bin/sh -e
#
# git-backup - creates a bare clone parallel to the current repository

is_git_repo() {
  git rev-parse HEAD >/dev/null 2>&1
}

if [ -z "${is_git_repo}" ]; then
  printf '%s\n' "not in a git repo!"
  exit 1
fi

dir="$(git rev-parse --show-toplevel)"
p="$(basename "${dir}")"
builtin cd .. || exit
git clone --mirror "${p}"
builtin cd $ || exit
