#!/bin/bash
set -e

if [[ ! "$1" =~ ^[a-zA-Z0-9._-]+$ ]] || [[ "$1" =~ \.git$ ]]; then
	exit 1
fi

repo_path=$(realpath "/home/git/repo/$1")

if [[ $repo_path != /home/git/repo/* ]]; then
	exit 1
fi

if [[ ! -d $repo_path ]]; then
	exit 1
fi

c=`cat ${repo_path}/c`
p=`cat ${repo_path}/p`
for can in $c $p; do
	if [ "$GIT_USER" == "$can" ]; then
		pass=1
	fi
done

[ $pass -eq 1 ]

if [ -d $repo_path/stone ]; then
	cd $repo_path/stone
	find -type f
fi

exit 0
