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

usage () {
	cat <<- EOF
		usage: $0 <commit> <pathspec>...

		Apply diff from <commit> like git-cherry-pick, but operate only on changes
		from <pathspec> (recursively).
		There can be multiple <pathspec> arguments.
	EOF
}

if [ $# -lt 2 ]
then
	usage >&2
	exit 64  # EX_USAGE
fi

commit="$1"
shift

git -c diff.noprefix=false diff "$commit^" "$commit" -- "$@" | \
	git apply --reject --index -
git commit --reuse-message="$commit"
