#!/bin/sh -e
# SPDX-License-Identifier: WTFPL
# shellcheck enable=

usage () {
	cat <<- EOF
		usage: $0 <tree-ish> [<pathspec>...]

		Set the tree in the same state as <tree-ish>.
		If <pathspec> are given, operate only on those paths (recursively).
		Else, operate on the whole git repository root.
	EOF
}

if [ $# -lt 1 ]
then
	usage >&2
	exit 64  # EX_USAGE
elif [ "$1" = -h ]
then
	usage
	exit 0
fi

commit="$1"
shift

if [ $# -eq 0 ]
then
	set -- :/
fi

git checkout "$commit" -- "$@"
git commit --reuse-message "$commit"
