#!/bin/sh
# shellcheck source=./lib.sh
. "$(dirname -- "$0")/lib.sh"
while getopts p: opt; do
case "$opt" in
p)
parents="${parents:-} -p $OPTARG"
;;
?)
abort "usage: tm commit [-p <parent>]... [<file>|<directory>]"
;;
esac
done
shift "$((OPTIND - 1))"
tm resolve-ref HEAD >/dev/null 2>/dev/null && : "${parents=-p HEAD}"
[ $# -gt 1 ] && abort "usage: tm commit [-p <parent>]... [<file>|<directory>]"
tree="$(tm insert "${1:-.}")" || abort "failed to insert ${1:-.}"
set -f
# This \o/ is \o/ really \o/ really \o/ dumb
# shellcheck disable=SC2086
set -- $parents
set +f
commit="$(tm commit-tree "$@" "$tree")" || abort "failed to commit $tree"
exec tm update-ref index "$commit" >/dev/null