#!/bin/sh

set -e

. ./helpers.sh

# With --ask-upstream-git and no UPSTREAM_GIT in debian/rules, the script
# must prompt for the upstream git url and use the typed value as is.

set_stub_rmadison "" 0
make_fixture "1.0.0-1" unstable "python-aodhclient" ""

RUN_STDIN="https://opendev.org/openstack/python-aodhclient
"
export RUN_STDIN
run_modernize --ask-upstream-git
assert_eq "exit code" "${MODERNIZE_RC}" "0"
assert_contains "typed url" "$(cat debian/watch)" \
	"https://opendev.org/openstack/python-aodhclient refs/tags/(\d[brc\d\.]+)"
assert_contains "prompt shown" "${OUT}" "Cannot guess upstream git url, please type it: "

# With UPSTREAM_GIT defined, --ask-upstream-git must not prompt, and the
# UPSTREAM_GIT value must win.
make_fixture "1.0.0-1" unstable "python-aodhclient" \
	"UPSTREAM_GIT := https://github.com/openstack/python-aodhclient.git"
RUN_STDIN=""
run_modernize --ask-upstream-git
assert_eq "exit code" "${MODERNIZE_RC}" "0"
assert_not_contains "no prompt" "${OUT}" "Cannot guess upstream git url"
assert_contains "upstream git wins" "$(cat debian/watch)" \
	"https://github.com/openstack/python-aodhclient refs/tags/(\d[brc\d\.]+)"

exit 0
