#!/usr/bin/env bats
bats_require_minimum_version 1.5.0

export _DEVTOOLS_LIBRARY_DIR="${PWD}/src"

_pkgctl_repo_configure() {
	source "${_DEVTOOLS_LIBRARY_DIR}"/lib/repo/configure.sh
	pkgctl_repo_configure "$@"
}

@test "repo-configure-valid-packaging" {
	local tmpdir
	tmpdir=$(mktemp -dt devtools.test.repo-configure.XXXXXX)
	pushd "${tmpdir}"
	git init
	git remote add origin "https://gitlab.archlinux.org/archlinux/packaging/packages/devtools.git"
	run _pkgctl_repo_configure
	[ "$status" -eq 0 ]
	popd
	rm -rf "${tmpdir}"
}

@test "repo-configure-non-packaging" {
	local tmpdir
	tmpdir=$(mktemp -dt devtools.test.repo-configure.XXXXXX)
	pushd "${tmpdir}"
	git init
	git remote add origin "https://gitlab.com/kicad/libraries/kicad-packages3D.git"
	run _pkgctl_repo_configure
	[ "$status" -eq 0 ]
	popd
	rm -rf "${tmpdir}"
}

@test "repo-configure-non-arch" {
	local tmpdir
	tmpdir=$(mktemp -dt devtools.test.repo-configure.XXXXXX)
	pushd "${tmpdir}"
	git init
	git remote add origin "https://github.com/torvalds/linux.git"
	run _pkgctl_repo_configure
	[ "$status" -eq 0 ]
	popd
	rm -rf "${tmpdir}"
}

@test "repo-configure-no-git" {
	local tmpdir
	tmpdir=$(mktemp -dt devtools.test.repo-configure.XXXXXX)
	pushd "${tmpdir}"
	run ! _pkgctl_repo_configure
	[ "$status" -ne 0 ]
	[[ "$output" == *"Not in a git repository"* ]]
	popd
	rm -rf "${tmpdir}"
}

@test "repo-configure-local-git" {
	local tmpdir
	tmpdir=$(mktemp -dt devtools.test.repo-configure.XXXXXX)
	pushd "${tmpdir}"
	git init
	run _pkgctl_repo_configure
	[ "$status" -eq 0 ]
	popd
	rm -rf "${tmpdir}"
}
