master hovercats/oakiss / scripts / commit.sh
 1set -e
 2
 3if [ "$#" != 4 ] ; then
 4	echo 'usage: commit.sh repo branch tag out' >&2
 5	exit 2
 6fi
 7
 8repo=$1
 9branch=$2
10tag=$3
11out=$4
12
13if commit=$(git -C "$repo" show-ref -s --verify "refs/heads/$branch" 2>/dev/null) ; then
14	oldtree=$(git -C "$repo" rev-parse --verify "$branch^{tree}")
15	newtree=$(git -C "$repo" rev-parse --verify "$tag^{tree}")
16	if [ "$oldtree" != "$newtree" ] ; then
17		set -- -p "$branch"
18		unset commit
19	fi
20else
21	set --
22	unset commit
23fi
24
25if [ -z "${commit+set}" ] ; then
26	commit=$(git -C "$repo" commit-tree -m "oasis $(git rev-parse --short=10 HEAD)" "$@" "$tag")
27	git -C "$repo" update-ref "refs/heads/$branch" "$commit"
28fi
29echo "$commit" >"$out"