#!/bin/sh
# SourceTree on OS X provides a defective path that doesn't contain python
# https://jira.atlassian.com/browse/SRCTREE-6540
export PATH=$PATH:/usr/local/bin

OLD_HEAD=$1
NEW_HEAD=$2
CHANGED_BRANCH=$3

if [ "$CHANGED_BRANCH" -eq "1" ]; then
	if /usr/bin/env python3 -c ""; then
		echo "Trying to fetch cached olean"
		leanproject get-cache
		# If the current project is not called "mathlib", then get a mathlib cache.
		leanpkg dump | grep --quiet 'name = "mathlib"'
		if [ $? -ne 0 ]; then
			leanproject get-mathlib-cache
		fi
		leanproject delete-zombies
	else
		echo "'env python3' failed; not running post-checkout hook"
	fi
fi
