[Zope3-dev] Denying commit for carriage returns in text

Fred L. Drake, Jr. fred@zope.com
Wed, 13 Nov 2002 16:59:25 -0500


--nr68PGqN4j
Content-Type: text/plain; charset=us-ascii
Content-Description: message body and .signature
Content-Transfer-Encoding: 7bit


I've attached a script that could be run from CVSROOT/commitinfo that
denies a commit if a text file contains a carriage return.  It ignores
binary files (the -kb sticky option is set).


  -Fred

-- 
Fred L. Drake, Jr.  <fred at zope.com>
PythonLabs at Zope Corporation


--nr68PGqN4j
Content-Type: text/plain
Content-Description: carriage returns are vile!
Content-Disposition: inline;
	filename="check-commit.sh"
Content-Transfer-Encoding: 7bit

#! /bin/sh
REPODIR="$1"
shift

TEMPFILE="/tmp/check-commit-$$"
for FILE in "$@" ; do
    REPOFILE="$REPODIR/$FILE,v"
    if test -f "$REPOFILE" -a -f "$FILE" ; then
        if (rlog -h "$REPOFILE" \
            | grep 'keyword substitution:' \
            | sed 's/^.*: //' \
            | grep -q b); then
            echo >/dev/null
        else
            sed "s/`echo -en '\r'`//" "$FILE" >"$TEMPFILE"
            cmp "$FILE" "$TEMPFILE"
            RC=$?
            rm -f "$TEMPFILE"
            if test $RC -ne 0 ; then
                echo '***'
                echo '*** Found carriage returns in text file; commit denied!'
                echo '***'
                exit $RC
            fi
        fi
    fi
done

exit 0

--nr68PGqN4j--