[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: ^M Characters - files in dos format
From: |
Frederic Brehm |
Subject: |
Re: ^M Characters - files in dos format |
Date: |
Thu, 03 Jul 2003 08:33:30 -0400 |
Lots and lots of people keep asking:
Is there any way to detect
files in dos format during check-in.
and I'm tired of it. So, here's the solution....
The script pasted below should do the trick. I cut it down from a larger
one that has more options, so try it first. The comments should tell you
what's going on.
I would be very happy if someone could put this into the CVS FAQ, the CVS
contrib directory, and anywhere else that people who are looking for this
solution can find it.
Fred
----------------------------- Cut here -----------------------------
#! /bin/sh
# SUMMARY
#
# cvs-no-cr
#
# A cvs commitinfo script to prevent files containing
# carriage return characters from getting into the
# repository. This script may not work for files
# with spaces in their names without modification.
# AUTHOR
#
# Frederic W. Brehm, address@hidden
# COPYRIGHT
#
# None claimed. This script is free to use as you see fit.
# INSTALLATION
#
# 1. Replace the ^M in the grep command below with a real carriage return.
# 2. Change the error message to meet your local conventions.
# 3. Put this script into $CVSROOT/CVSROOT.
# USAGE
#
# Suppose you want to prevent all *.c and *.h files in module "A"
# from being checked if they contain a carrage return. Put the following
# line in commitinfo (without the leading "#", of course).
#
# A $CVSROOT/CVSROOT/cvs-no-cr \.h$,\.c$
#######################################################################
# the first argument should be the comma-separated pattern for the files
# to check. The patterns are used in a grep command.
PATTERN=`echo $1 | sed -e 's/,/ /g'`
shift
# the second argument, supplied by cvs, is the path to the repository.
REPOSITORY=$1
shift
# subsequent arguments supplied by cvs are file names. Ignore missing ones.
OK=true
for FILE in $*; do
if test -f $FILE; then
for P in $PATTERN; do
if echo $FILE | grep -s $P; then
# N.B. be sure to fix the next line before installing. See above.
if grep -is '^M$' $FILE; then
echo
echo ERROR: $FILE contains a carriage return
character.
echo
OK=false
fi
fi
fi
done
fi
done
if $OK; then
exit 0
fi
exit 1
----------------------------- Cut here -----------------------------
_______________________________________________________________
Frederic W. Brehm, Sarnoff Corporation, http://www.sarnoff.com/