0

I am trying to write a hook that blocks a commit if it has a certain string. I've gotten that working with the following code.

#!/bin/sh

REPOS="$1"
TXN="$2"
COMPARE=`$SVNLOOK diff -t "$TXN" "$REPOS"`

if echo ${COMPARE} | grep -qw "path/to/file/*"; then
  if         echo ${COMPARE} | egrep "string1"; then
             echo "file contains invalid string string1. Unable to commit " 1>&2
            exit 1
  fi

  if         echo ${COMPARE} | egrep "string2"; then
             echo "file contains invalid string string2. Unable to commit " 1>&2
            exit 1
  fi

  if         echo ${COMPARE} | egrep "string3"; then
             echo "file contains invalid string string3. Unable to commit"  1>&2
            exit 1
  fi


fi

Now what I am trying to do is exclude files that end with a "_man.txt". I know you have to use the --exclude=*{_man.txt} but it is not ignoring files and still showing the commit error echo message i have set up. Can anyone see what might I be missing and why?

if echo ${COMPARE} | grep -qw --exclude=\*{_man.txt} "path/to/file/*"; then
  if         echo ${COMPARE} | egrep "string1"; then
             echo "file contains invalid string string1. Unable to commit " 1>&2
            exit 1
  fi

  if         echo ${COMPARE} | egrep "string2"; then
             echo "file contains invalid string string2. Unable to commit " 1>&2
            exit 1
  fi

  if         echo ${COMPARE} | egrep "string3"; then
             echo "file contains invalid string string3. Unable to commit"  1>&2
            exit 1
  fi


fi

1 Answers1

0

Here is what I had to do.

for ROUTE in $COMPARE
do
 if [[ "$ROUTE" == *path/to/file* ]]; then

    if [[ "$ROUTE" == *_man.txt* ]]; then
        exit 0
    fi

    if echo ${COMPARE} | grep -qw "path/to/file/*"; then
        if  echo ${COMPARE} | egrep "string1"; then
            echo "string1 cannot be found in file." 1>&2
            exit 1
        fi

        if  echo ${COMPARE} | egrep "string2"; then
            echo "string2 cannot be found in file." 1>&2
            exit 1
        fi

        if  echo ${COMPARE} | egrep "string3"; then
            echo "string3 cannot be found in file." 1>&2
            exit 1
        fi
    fi
fi
done
#Operation 001 Completed