#!/bin/sh
## Test repotool initmake, svn->hg

workdir=$(mktemp -d "${TMPDIR:-/tmp}/test-workdir.XXXXXX") || { echo "$0: mktemp failed"; exit 1; }
out=$(mktemp "${TMPDIR:-/tmp}/repotool-makemake-svn-hg.XXXXXX") || { echo "$0: mktemp failed"; rm -rf "${workdir}"; exit 1; }
here=$(pwd)
cd "${workdir}" >/dev/null || { echo "$0: cd failed" >&2; rm -rf "${workdir}" "${out}"; exit 1; }
${REPOTOOL:-repotool} initmake xyzzy svn hg >"${out}"
repotool_status=$?
echo Return code: ${repotool_status} >>"${out}"
cd "${here}" >/dev/null || { echo "$0: cd failed" >&2; rm -rf "${workdir}" "${out}"; exit 1; }
./dir-md5 "${workdir}" >>"${out}"

# shellcheck disable=SC1091
. ./common-setup.sh
if [ "${repotool_status}" -ne 0 ]
then
	if [ "$1" != "--rebuild" ]
	then
		toolmeta "$1" "${out}"
	else
		cat "${out}"
	fi
	rm -rf "${workdir}" "${out}"
	exit "${repotool_status}"
fi
toolmeta "$1" "${out}"

st=$?
if [ $st -eq 0 ]; then
	rm -rf "${workdir}" "${out}"
fi

exit $st

#end
