~ecs/tm

ref: 0022137d89f12741ac3e6cf4173aa876cda5a726 tm/tm-resolve-ref -rwxr-xr-x 414 bytes
0022137dEmber Sawady Fix shellcheck warnings 1 year, 10 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/bin/sh -eu

# shellcheck source=./lib.sh
. "$(dirname -- "$0")/lib.sh"
if [ $# -ne 1 ]; then
	abort "usage: tm resolve-ref <ref>"
fi

# TODO: ref~X, ref^X
if [ -f "$TM_DIR/refs/$1" ]; then
	tm resolve-ref "$(cat -- "$TM_DIR/refs/$1")"
else
	short="$1"
	set -- "$TM_DIR/objects/$short"*
	if [ $# -eq 1 ] && [ -f "$1" ]; then
		printf "%s\n" "$(basename -- "$1")"
	else
		abort "error: invalid ref $short"
	fi
fi