#!/usr/bin/make -f

GOPATH = $(CURDIR)/_build
GOCACHE = $(CURDIR)/_build/go-build
HOME = $(CURDIR)/_build/fakehome

# autopkgtest.ubuntu.com sets no_proxy env, however proxy_test.go will
# fail with that.
unexport no_proxy

%:
	dh $@ --builddirectory=_build --buildsystem=golang --with=golang

execute_after_dh_auto_configure:
	# remove test files if nocheck is passed
ifeq (nocheck,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	rm -f \
		$(CURDIR)/_build/src/github.com/go-git/go-git/plumbing/transport/http/internal/test/test_utils.go \
		$(CURDIR)/_build/src/github.com/go-git/go-git/plumbing/transport/ssh/internal/test/test_utils.go \
		$(CURDIR)/_build/src/github.com/go-git/go-git/plumbing/transport/test/receive_pack.go \
		$(CURDIR)/_build/src/github.com/go-git/go-git/storage/test/storage_suite.go
endif

override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	# writeable HOME directory with ~/.ssh/known_hosts and ~/.gitconfig is
	# needed, as per .github/workflows/test.yml.
	cp -r $(CURDIR)/debian/fakehome $(HOME)
	# `go test` must be run manually, as debhelper will clear the HOME variable.
	GOPATH=$(GOPATH) GOCACHE=$(GOCACHE) GO111MODULE=off GOPROXY=off GOTOOLCHAIN=local \
		HOME=$(HOME) go test -vet=off -v -p 8 github.com/go-git/go-git/...
endif

execute_after_dh_auto_test:
	find _build -type d -name .tmp -print0 | xargs -0r rm -rf
