Wednesday, June 4, 2014

Locking CVS repository branches

Sometimes we need to lock CVS repository branches before a release to prevent accidentally committed by developers.

In a CVS repository, the commitinfo file under the CVSROOT that defines programs to execute whenever `cvs commit' is about to execute.

So lets create a trigger bash script called that get branches parameters to be validated.

 if [ -f CVS/Tag ]; then  
  tag=`cat CVS/Tag`  
 for branch in "$@"  
   if [ "$tag" == "T$branch" ]; then  
      echo Cannot commit to $branch  
      exit 1  
 echo Commit OK  
 exit 0  

We can place this script in any folder, for example /cvs/scripts/

Then just append a line at the bottom of the CVSROOT/commitinfo of a repository:
ALL /cvs/scripts/ branch1 branch2

We could make a script to append/remove branches from that list on multiple repositories at the same time.

With GIT or SVN, they also provide similar pre-commit hook feature so we can do the same thing.