~ecs/tm

9df4fe210cf2b97601c83e54dcfcf4f6f6c37252 — Ember Sawady 3 years ago 25860dd
commit: handle lack of HEAD gracefully

By creating a no-parent commit
1 files changed, 3 insertions(+), 4 deletions(-)

M tm-commit
M tm-commit => tm-commit +3 -4
@@ 1,11 1,10 @@
#!/bin/sh

. "$(dirname -- "$0")/lib.sh"
parents=
while getopts p: opt; do
	case "$opt" in
	p)
		parents="$parents -p $OPTARG"
		parents="${parents:-} -p $OPTARG"
		;;
	?)
		abort "usage: tm commit [-p <parent>]... [<file>|<directory>]"


@@ 15,9 14,9 @@ done

shift "$((OPTIND - 1))"

[ -z "$parents" ] && parents="-p HEAD"
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:-.}"
commit="$(tm commit-tree $parents "$tree")" || abort "failed to commit $tree"
exec tm update-ref index "$commit"
exec tm update-ref index "$commit" >/dev/null