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 validateCommit.sh that get branches parameters to be validated.

 #!/bin/bash  
 if [ -f CVS/Tag ]; then  
  tag=`cat CVS/Tag`  
 else  
  tag=THEAD  
 fi  
 for branch in "$@"  
 do  
   if [ "$tag" == "T$branch" ]; then  
      echo Cannot commit to $branch  
      exit 1  
   fi  
 done  
 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/validateCommit.sh 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.