#! /bin/bash
#------------------------------------------------------------------------------
#$Author: saulius $
#$Date: 2020-12-15 15:00:08 +0000 (Tue, 15 Dec 2020) $
#$Revision: 8422 $
#$URL: file:///home/saulius/svn-repositories/paskaitos/VU/software/assignment-evaluation/trunk/scripts/do-check--svn-executable-property $
#------------------------------------------------------------------------------
#*
# Check that executable files have svn:executable property set.
#**

set -ue
## set -x

DIRECTORY="$1"

ID='$Id: do-check--svn-executable-property 8422 2020-12-15 15:00:08Z saulius $'

cd "${DIRECTORY}"

if [ "$(find -name .svn)" == "" ]
then
    # The directory is not a working copy -- no sense to check
    # further.
    exit 0;
fi

find \
     -name .svn -prune -o \
     -name .git -prune -o \
     -name hooks -prune -o \
     -type f -perm /111 \
     -print \
| sort \
| (
    COUNT=0
    while read FILE
    do
        if [ "$(svn propget svn:executable "${FILE}" 2> /dev/null)" == "" ]
        then
            if [ $COUNT -eq 0 ]
            then
                cat <<EOF
-- [AUTO;INTERFACE;$(echo $ID | sed 's/\$//g')]

   Vykdomiems failams turi būti nustatyta 'svn:executable' savybė,
   bet failui "${FILE}" ji nenustatyta (-10 balai);
EOF
            else
                echo "   Dar vienas toks failas: \"${FILE}\""
            fi
            COUNT=$(expr $COUNT + 1)
        fi    
    done

    if [ $COUNT -gt 0 ]
    then
        echo ""
    fi
)
