#! /bin/bash -x

set -e

clone_url_parent=https://github.com/praiskup/argparse-manpage

workdir=$(basename "$clone_url_parent")
workdir=${workdir%%.git}

hook_payload=$(readlink -f "${HOOK_PAYLOAD-hook_payload}")

# clone the helper scripts when needed, and add to PATH
test -d copr-ci-tooling \
    || git clone --depth 1 https://github.com/praiskup/copr-ci-tooling.git
export PATH="$PWD/copr-ci-tooling:$PATH"

# clone the tested project
git clone \
    --recursive \
    --no-single-branch \
    "$clone_url_parent"

# checkout requested revision
cd "$workdir"

webhook-checkout "$hook_payload"

cd rpm || exit 1
make srpm
