mirror of
https://github.com/envmodules/modules.git
synced 2026-06-03 00:33:18 +08:00
Of modules to the next commit # so that next time we commit changes it will be updated. This is a little bit tricky because of the way pre-commit's work. (It's making the change for the next commit not the current one).
42 lines
1021 B
Perl
Executable File
42 lines
1021 B
Perl
Executable File
#!/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");
|
|
|