#!/bin/sh
#
# git-squash - for squashing commits on a branch

set -eu

if git show-ref --verify --quiet refs/heads/main; then
  default_branch=main
elif git show-ref --verify --quiet refs/heads/master; then
  default_branch=master
else
  printf '%s\n' "Neither 'main' nor 'master' exists in this repo." >&2
  exit 1
fi

# shellcheck disable=SC2312
git reset --soft "$(git merge-base "${default_branch}" HEAD)"
