#!/usr/bin/perl # This file is a pre-commit git hook to automatically update the # MODULES_CURRENT_VERSION in modulecmd.tcl # Put this in modules/.git/hooks/pre-commit and make it executable. use strict; use warnings; use Cwd 'abs_path'; my ($ROOT, $OUTFILE, $INFILE, $line, $value); $ROOT = abs_path($0); print "ROOT BASE = $ROOT\n"; $ROOT =~ /(.*)\.git\/hooks\/pre-commit/; $ROOT = $1; print "ROOT = $ROOT\n"; $value = `cd $ROOT;git rev-list HEAD --count`; $value ++; $value ++; system("cp $ROOT/modulecmd.tcl $ROOT/modulecmd.tmp"); unlink("$ROOT/modulecmd.tcl"); open($OUTFILE, ">","$ROOT/modulecmd.tcl") or die "Unable to open $ROOT/modulecmd.tcl"; open($INFILE, "<","$ROOT/modulecmd.tmp") or die "Unable to open $ROOT/modulecmd.tmp"; while(<$INFILE>) { $line = $_; if ($line =~ /set MODULES_CURRENT_VERSION (.*)/) { print $OUTFILE "set MODULES_CURRENT_VERSION 1.$value\n"; } else { print $OUTFILE $line; } } close $OUTFILE; unlink("$ROOT/modulecmd.tmp"); system("chmod 755 $ROOT/modulecmd.tcl");