#!/bin/sh
GIT_DIR="$1"
if [ -z "$GIT_DIR" ]; then
	GIT_DIR=`git rev-parse --git-dir`
fi

GIT_DIR=`realpath "$GIT_DIR"`

if [ -d "$GIT_DIR/.git" ]; then
	GIT_DIR="$GIT_DIR/.git"
fi

B=`git --git-dir="$GIT_DIR" rev-parse --is-bare-repository `
if [ "$B" = "true" ]; then
	exit 0
fi

cd "$GIT_DIR/.."

COUNT=`git --git-dir="$GIT_DIR" status  \
	| grep -v 'nothing to commit' \
	| grep -v '^On branch ' \
	| grep -v '^#' \
	| wc -l`

if ! [ "$COUNT" = "0" ]; then
	echo "You need to commit"
	exit 1
fi

COUNT2=`git --git-dir="$GIT_DIR" diff HEAD | wc -l`

if [ "$COUNT2" = "0" ]; then
	exit
fi

echo "You need to commit"
exit 1

