#!/bin/bash
#
# Owned by RunCloud
# Usage without permission is prohibited

GITDIRECTORY=$1

function isGitDir {
    if git rev-parse --git-dir > /dev/null 2>&1; then
        return 0
    else
        return 1
    fi
}

function isHavingPermission {
    if git ls-remote > /dev/null 2>&1; then
        return 0
    else
        return 1
    fi
}

cd $GITDIRECTORY

if ! isGitDir; then
    exit 1
elif ! isHavingPermission; then
    exit 2
else
    exit 0
fi
