summaryrefslogtreecommitdiff
path: root/scripts/commit.sh
blob: 1d4124a7de6c4b50f0db8f03988793e943411f4f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
set -e

if [ "$#" != 4 ] ; then
	echo 'usage: commit.sh repo branch tag out' >&2
	exit 2
fi

repo=$1
branch=$2
tag=$3
out=$4

if commit=$(git -C "$repo" show-ref -s --verify "refs/heads/$branch" 2>/dev/null) ; then
	oldtree=$(git -C "$repo" rev-parse --verify "$branch^{tree}")
	newtree=$(git -C "$repo" rev-parse --verify "$tag^{tree}")
	if [ "$oldtree" != "$newtree" ] ; then
		set -- -p "$branch"
		unset commit
	fi
else
	set --
	unset commit
fi

if [ -z "${commit+set}" ] ; then
	commit=$(git -C "$repo" commit-tree -m "oasis $(git rev-parse --short=10 HEAD)" "$@" "$tag")
	git -C "$repo" update-ref "refs/heads/$branch" "$commit"
fi
echo "$commit" >"$out"