Skip to content

Instantly share code, notes, and snippets.

@serrasqueiro
Last active June 25, 2021 13:58
Show Gist options
  • Select an option

  • Save serrasqueiro/8fc600b82780e742b521e0ebeb324db4 to your computer and use it in GitHub Desktop.

Select an option

Save serrasqueiro/8fc600b82780e742b521e0ebeb324db4 to your computer and use it in GitHub Desktop.
How-To create CVS pre-commit hook

How To, create CVS pre-commit hook

Installing CVS, if needed

If you do not have CVS, you can install it. If you come in a Linux OS with pre-installed CVS, but you have an empty $CVSROOT/CVSROOT/ content, you can initialize CVS as follow:

  • cvs -d /usr/local/cvsroot init

I am using actually:

  • cvs -d /opt/cvsroot init

Creating the pre-hook

First, checkout existing commitinfo file (which will be handled by CVS as the generic pre-commit hooj).

henri@pena:/tmp$ cvs co CVSROOT/commitinfo
U CVSROOT/commitinfo
henri@pena:/tmp$ cd CVSROOT/
henri@pena:/tmp/CVSROOT$

Then edit commitinfo with the appropriate content (see the line without a comment, below)

CVS  commitinfo
henri@pena:/tmp/CVSROOT$ vi commitinfo 
henri@pena:/tmp/CVSROOT$ cat commitinfo 
# The "commitinfo" file is used to control pre-commit checks.
# The filter on the right is invoked with the repository and a list
# of files to check.  A non-zero exit of the filter program will
# cause the commit to be aborted.
#
# The first entry on a line is a regular expression which is tested
# against the directory that the change is being committed to, relative
# to the $CVSROOT.  For the first match that is found, then the remainder
# of the line is the name of the filter to run.
#
# Format strings present in the filter will be replaced as follows:
#    %c = canonical name of the command being executed
#    %I = unique (randomly generated) commit ID
#    %R = the name of the referrer, if any, otherwise the value NONE
#    %p = path relative to repository
#    %r = repository (path portion of $CVSROOT)
#    %{s} = file name, file name, ...
#
# If no format strings are present in the filter string, a default of
# " %r %s" will be appended to the filter string, but this usage is
# deprecated.
#
# If the repository name does not match any of the regular expressions in this
# file, the "DEFAULT" line is used, if it is specified.
#
# If the name "ALL" appears as a regular expression it is always used
# in addition to the first matching regex or "DEFAULT".

^your_module_name/*        /home/henri/tinyconf/packages/cvhelper/cvcommitinfo.sh %{s} 

Understanding the pre-hook

The following script acts as a wrapper between CVS and your file-system, calling the appropriate python script that analyzes the content of the files changed.

An example of a python script to analyze the content is here:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment