1set -e
2
3if [ "$#" != 4 ] ; then
4 echo 'usage: tree.sh repo tag index out' >&2
5 exit 2
6fi
7
8repo=$1
9tag=$2
10index=$3
11out=$4
12
13export GIT_INDEX_FILE="$PWD/$out.index"
14git -C "$repo" read-tree --empty
15git -C "$repo" update-index --index-info <"$index"
16tree=$(git -C "$repo" write-tree)
17git -C "$repo" update-ref "refs/tags/$tag" "$tree"
18
19printf '%s\n' "$tree" >"$out.tmp"
20if cmp -s "$out" "$out.tmp" ; then
21 rm "$out.tmp"
22else
23 mv "$out.tmp" "$out"
24fi