maintainer="Michał Polański <michal@polanski.me>"
pkgname=git-warp-time
pkgver=0.8.4
pkgrel=1
pkgdesc="Reset timestamps of Git repository files to the time of the last modifying commit"
url="https://github.com/alerque/git-warp-time"
license="GPL-3.0-only"
arch="all"
makedepends="cargo cargo-auditable libgit2-dev"
subpackages="$pkgname-bash-completion $pkgname-fish-completion $pkgname-zsh-completion"
source="https://github.com/alerque/git-warp-time/archive/v$pkgver/git-warp-time-$pkgver.tar.gz"
options="net" # cargo fetch

prepare() {
	default_prepare

	# Doc-tests from README.md expect to be ran in a Git repository
	git init -q .
	git config --local user.name "example"
	git config --local user.email "example@example.com"
	git add .
	git commit -q -m "init"

	# Rust target triple
	local target="$(rustc -vV | sed -n 's/host: //p')"

	# Build against system-provided libraries
	mkdir -p .cargo
	cat >>.cargo/config.toml <<-EOF
		[target.$target]
		git2 = { rustc-link-lib = ["git2"] }
	EOF

	cargo fetch --target="$CTARGET" --locked
}

build() {
	cargo auditable build --frozen --release
}

check() {
	cargo test --frozen
}

package() {
	install -Dm755 target/release/$pkgname -t "$pkgdir"/usr/bin/

	# shell completions
	find target/release -name $pkgname.bash \
		-exec install -Dm644 {} "$pkgdir"/usr/share/bash-completion/completions/$pkgname \;
	find target/release -name $pkgname.fish \
		-exec install -Dm644 {} "$pkgdir"/usr/share/fish/vendor_completions.d/$pkgname.fish \;
	find target/release -name _$pkgname \
		-exec install -Dm644 {} "$pkgdir"/usr/share/zsh/site-functions/_$pkgname \;
}

sha512sums="
de6c6e14f15b662acb24585bd41eb9beb7d1d521876caeb9048ef4eba3683b79c6f9768423ccbfd136b61c22f12cb487ffa202470f6934ecbbac71cc5451f1af  git-warp-time-0.8.4.tar.gz
"
