# Copyright 2019-2026 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI=8

inherit go-module

DESCRIPTION="Remote repository management made easy"
HOMEPAGE="https://github.com/x-motemen/ghq"
if [[ "${PV}" == 9999 ]]; then
	inherit git-r3
	EGIT_REPO_URI="https://github.com/x-motemen/ghq.git"
	RESTRICT="mirror"
else
	SRC_URI="
		https://github.com/x-motemen/ghq/archive/v${PV}.tar.gz -> ${P}.tar.gz
		https://github.com/ingenarel/guru-depfiles/releases/download/${P}-deps.tar.xz/${P}-go-mod-deps.tar.xz ->
		${P}-deps.tar.xz
	"
	KEYWORDS="~amd64"
	#bump the CURRENT_REVISION on the next release
	MY_GIT_REV="39ead65"
fi

LICENSE="MIT"
#gentoo-go-license ghq-1.9.4.ebuild
LICENSE+=" BSD-2 BSD MIT "

SLOT="0"
BDEPEND=">=dev-lang/go-1.26.0"

src_unpack() {
	if [[ "${PV}" == 9999 ]];then
		git-r3_src_unpack
		go-module_live_vendor
	else
		default
	fi
}

src_prepare() {
	default
	sed -i -E 's/^\s*build:\s*deps\s*$/build:/; s/-s\s+-w\s+//' Makefile || die "sed failed!"
}

src_compile() {
	if [[ "${PV}" == 9999 ]]; then
		emake build
	else
		emake build VERSION="${PV}" CURRENT_REVISION="${MY_GIT_REV}"
	fi
}

src_test() {
	ego test -v ./...
}

src_install() {
	dobin "${PN}"
	einstalldocs
}