aboutsummaryrefslogtreecommitdiff
path: root/hooks
diff options
context:
space:
mode:
Diffstat (limited to 'hooks')
-rwxr-xr-xhooks/commit-msg140
-rwxr-xr-xhooks/pre-commit42
-rwxr-xr-xhooks/pre-receive344
3 files changed, 263 insertions, 263 deletions
diff --git a/hooks/commit-msg b/hooks/commit-msg
index 5482389..0fe306b 100755
--- a/hooks/commit-msg
+++ b/hooks/commit-msg
@@ -146,7 +146,7 @@ $MAXLEN = 68;
"ChangeLog.txt: ",
"README: ",
"Public www update: ",
- "(tag: ", # I'm not sure this actually does anything
+ "(tag: ", # I'm not sure this actually does anything
);
abort("Hook called with no argument.") unless $ARGV[0];
@@ -155,9 +155,9 @@ $msgfile = $ARGV[0];
# get list of directories with changes.
for(split /\0/, `git -P diff -z --cached --name-only`) {
- my ($cat, $prog, undef) = split /\//, $_, 3;
- next unless (defined $cat && defined $prog);
- $dirs{"$cat/$prog"}++;
+ my ($cat, $prog, undef) = split /\//, $_, 3;
+ next unless (defined $cat && defined $prog);
+ $dirs{"$cat/$prog"}++;
}
@dirs = keys %dirs;
@@ -171,106 +171,106 @@ chomp for @lines;
$msgline = $lines[0];
if(grep { index($msgline, $_) == 0 } @admin_msgs) {
- warn "$SELF: Skipping checks due to admin-only commit message.\n";
- exit 0;
+ warn "$SELF: Skipping checks due to admin-only commit message.\n";
+ exit 0;
}
if(@dirs > 1) {
- abort("Aborting due to changes in multiple directories:" .
- join("\n ", "", @dirs));
+ abort("Aborting due to changes in multiple directories:" .
+ join("\n ", "", @dirs));
}
$lines[0] = fix_message($msgline, $dirs[0]);
save_file($msgfile, @lines) if $msgline ne $lines[0];
if(exists($ENV{DRYRUN})) {
- warn "$SELF: commit message OK, not committing due to DRYRUN in env.\n";
- exit 1;
+ warn "$SELF: commit message OK, not committing due to DRYRUN in env.\n";
+ exit 1;
}
exit 0;
#################################################################
sub fix_message {
- my $msg = shift;
- my $catprg = shift;
-
- my $prefix = "$catprg: ";
- my $orig = $msg;
-
- # v => Updated for version <ver>
- # v,stuff => Updated for version <ver>, stuff
- if($msg =~ /^v(?:\s*,\s*(\S.*$))?/) {
- my $rest = defined $1 ? ", $1" : "";
- $msg = "Updated for version " . get_ver($catprg) . $rest;
- }
-
- # add prefix only if missing.
- if(index($msg, $prefix) != 0) {
- if($msg =~ /^(\S+:)(\s)?/) {
- my $err = "Commit message has bad prefix:\n" .
- " '$1'\n should be:\n '$prefix'";
- if(!defined($2)) {
- $err .= "\n Missing space after '$1'";
- }
- abort($err);
- }
- $msg = "$prefix$msg";
- }
-
- # add a period if there isn't one, and if there's room for one.
- if(length($msg) < $MAXLEN && ($msg !~ /.*\.$/)) {
- $msg .= ".";
- }
-
- if($msg ne $orig) {
- warn <<EOF;
+ my $msg = shift;
+ my $catprg = shift;
+
+ my $prefix = "$catprg: ";
+ my $orig = $msg;
+
+ # v => Updated for version <ver>
+ # v,stuff => Updated for version <ver>, stuff
+ if($msg =~ /^v(?:\s*,\s*(\S.*$))?/) {
+ my $rest = defined $1 ? ", $1" : "";
+ $msg = "Updated for version " . get_ver($catprg) . $rest;
+ }
+
+ # add prefix only if missing.
+ if(index($msg, $prefix) != 0) {
+ if($msg =~ /^(\S+:)(\s)?/) {
+ my $err = "Commit message has bad prefix:\n" .
+ " '$1'\n should be:\n '$prefix'";
+ if(!defined($2)) {
+ $err .= "\n Missing space after '$1'";
+ }
+ abort($err);
+ }
+ $msg = "$prefix$msg";
+ }
+
+ # add a period if there isn't one, and if there's room for one.
+ if(length($msg) < $MAXLEN && ($msg !~ /.*\.$/)) {
+ $msg .= ".";
+ }
+
+ if($msg ne $orig) {
+ warn <<EOF;
=== Modified commit message
was: '$orig'
now: '$msg'
If this doesn't look correct, use 'git commit --amend' to fix it.
EOF
- }
+ }
- my $l = length $msg;
- if($l > $MAXLEN) {
- abort("Commit message too long ($l chars, max is $MAXLEN).");
- }
+ my $l = length $msg;
+ if($l > $MAXLEN) {
+ abort("Commit message too long ($l chars, max is $MAXLEN).");
+ }
- return $msg;
+ return $msg;
}
#################################################################
# Saves the commit message file (overwrites the original).
sub save_file {
- my $file = shift;
- open my $f, ">", $file or abort("$file: $!");
- print $f "$_\n" for @_;
- close $f;
+ my $file = shift;
+ open my $f, ">", $file or abort("$file: $!");
+ print $f "$_\n" for @_;
+ close $f;
}
#################################################################
# Read VERSION from the .info file, return it.
sub get_ver {
- my $catprg = shift;
- my $prg = $catprg =~ s,.*/,,r;
- my $info = "$catprg/$prg.info";
- my $ver;
-
- open my $f, "<", $info or abort("Missing $info file");
- while(<$f>) {
- next unless /^VERSION="([^"]+)"/;
- $ver = $1;
- last;
- }
- close $f;
-
- abort("Can't read VERSION from $info") unless defined $ver;
- return $ver;
+ my $catprg = shift;
+ my $prg = $catprg =~ s,.*/,,r;
+ my $info = "$catprg/$prg.info";
+ my $ver;
+
+ open my $f, "<", $info or abort("Missing $info file");
+ while(<$f>) {
+ next unless /^VERSION="([^"]+)"/;
+ $ver = $1;
+ last;
+ }
+ close $f;
+
+ abort("Can't read VERSION from $info") unless defined $ver;
+ return $ver;
}
#################################################################
sub abort {
- warn "*** $_[0]\n" if $_[0];
- die "$SELF hook: Commit aborted due to bad commit message.\n";
+ warn "*** $_[0]\n" if $_[0];
+ die "$SELF hook: Commit aborted due to bad commit message.\n";
}
diff --git a/hooks/pre-commit b/hooks/pre-commit
index 045b2b8..f630400 100755
--- a/hooks/pre-commit
+++ b/hooks/pre-commit
@@ -113,30 +113,30 @@ EOF
# The fugly grep regex below matches only the actual .info files, named
# category/prgnam/prgnam.info (and not other files named .info).
if [ "${MD5OK:-no}" != "yes" ]; then
- while read filename; do
- check_info_file "$filename"
- done < <(git diff --cached --name-only | grep '^[^/]*/\([^/]*\)/\1.info' || exit 0)
+ while read filename; do
+ check_info_file "$filename"
+ done < <(git diff --cached --name-only | grep '^[^/]*/\([^/]*\)/\1.info' || exit 0)
fi
if [ "${SBOLINT:-yes}" = "yes" ]; then
- sbolintfailed=""
- if ! which sbolint &>/dev/null; then
- echo "WARNING: can't find sbolint in PATH, no linting will be done"
- else
- while read build; do
- # If there's no slack-desc or README, assume the build was removed.
- # The directory still might exist after a "git rm -rf" because it
- # might contain untracked files (e.g. the source tarball).
- if [ -e "$build/slack-desc" -o -e "$build/README" ]; then
- sbolint "$build" || sbolintfailed=1
- fi
- done < <(git diff --cached --name-only | cut -d/ -f1,2 | sort -u)
- fi
- if [ -n "$sbolintfailed" ]; then
- echo "*** sbolint failed, fix the errors or set SBOLINT=no"
- echo "*** in the environment to commit anyway."
- exit 1
- fi
+ sbolintfailed=""
+ if ! which sbolint &>/dev/null; then
+ echo "WARNING: can't find sbolint in PATH, no linting will be done"
+ else
+ while read build; do
+ # If there's no slack-desc or README, assume the build was removed.
+ # The directory still might exist after a "git rm -rf" because it
+ # might contain untracked files (e.g. the source tarball).
+ if [ -e "$build/slack-desc" -o -e "$build/README" ]; then
+ sbolint "$build" || sbolintfailed=1
+ fi
+ done < <(git diff --cached --name-only | cut -d/ -f1,2 | sort -u)
+ fi
+ if [ -n "$sbolintfailed" ]; then
+ echo "*** sbolint failed, fix the errors or set SBOLINT=no"
+ echo "*** in the environment to commit anyway."
+ exit 1
+ fi
fi
exit 0
diff --git a/hooks/pre-receive b/hooks/pre-receive
index 52303ab..7e4847d 100755
--- a/hooks/pre-receive
+++ b/hooks/pre-receive
@@ -94,80 +94,80 @@ $default_branch = 'master';
($SELF = $0) =~ s,.*/,,;
sub debug {
- return unless $debugging;
- warn "$SELF: $_\n" for @_;
+ return unless $debugging;
+ warn "$SELF: $_\n" for @_;
}
sub fatal {
- die "$SELF: $_[0]\n";
+ die "$SELF: $_[0]\n";
}
sub errmsg {
- return " " . yellow($_[0]) . "\n";
+ return " " . yellow($_[0]) . "\n";
}
# Meat and potatoes here. Eat hearty!
sub check_message {
- my $full_msg = shift;
- my $hash = shift; # not used except to print it
-
- my $result;
-
- debug("check_message(\"$full_msg\", \"$hash\")");
-
- # length check can be combined with the 'serious' errors.
- if(length($full_msg) > 68) {
- $result = errmsg("Length exceeds 68 characters");
- }
-
- for($full_msg) {
- # don't check these!
- return if /^Public www update:/;
-
- # first 3 errors are serious enough that we don't check
- # for the rest (hence the 'last').
- if(! /:/) {
- $result .= errmsg("No category/build (no colon)");
- last;
- }
-
- my ($catprg, $msg) = split /:/, $_, 2;
- if($catprg !~ m{/}) {
- $result .= errmsg("No category");
- last;
- }
-
- my ($cat, $prg, $junk) = split /\//, $catprg;
- if(defined($junk)) {
- $result .= errmsg("Invalid category/build (2 or more slashes)");
- last;
- }
-
- # the rest of these, we can have more than one of.
- if($prg =~ /[^-A-Za-z0-9_+.]/) {
- $result .= errmsg("Invalid character in build name '$prg'");
- }
-
- if(!category_ok($cat)) {
- $result .= errmsg("Invalid category '$cat'");
- }
-
- if($msg !~ /^ /) {
- $result .= errmsg("Missing space after colon");
- }
-
- if($msg =~ /^ /) {
- $result .= errmsg("Extra space after colon");
- }
- }
-
- if(defined $result) {
- push @errs, (
- red("* Malformed commit message for ") . yellow($hash). "\n",
- green($full_msg) . "\n",
- $result,
- "\n" );
- }
+ my $full_msg = shift;
+ my $hash = shift; # not used except to print it
+
+ my $result;
+
+ debug("check_message(\"$full_msg\", \"$hash\")");
+
+ # length check can be combined with the 'serious' errors.
+ if(length($full_msg) > 68) {
+ $result = errmsg("Length exceeds 68 characters");
+ }
+
+ for($full_msg) {
+ # don't check these!
+ return if /^Public www update:/;
+
+ # first 3 errors are serious enough that we don't check
+ # for the rest (hence the 'last').
+ if(! /:/) {
+ $result .= errmsg("No category/build (no colon)");
+ last;
+ }
+
+ my ($catprg, $msg) = split /:/, $_, 2;
+ if($catprg !~ m{/}) {
+ $result .= errmsg("No category");
+ last;
+ }
+
+ my ($cat, $prg, $junk) = split /\//, $catprg;
+ if(defined($junk)) {
+ $result .= errmsg("Invalid category/build (2 or more slashes)");
+ last;
+ }
+
+ # the rest of these, we can have more than one of.
+ if($prg =~ /[^-A-Za-z0-9_+.]/) {
+ $result .= errmsg("Invalid character in build name '$prg'");
+ }
+
+ if(!category_ok($cat)) {
+ $result .= errmsg("Invalid category '$cat'");
+ }
+
+ if($msg !~ /^ /) {
+ $result .= errmsg("Missing space after colon");
+ }
+
+ if($msg =~ /^ /) {
+ $result .= errmsg("Extra space after colon");
+ }
+ }
+
+ if(defined $result) {
+ push @errs, (
+ red("* Malformed commit message for ") . yellow($hash). "\n",
+ green($full_msg) . "\n",
+ $result,
+ "\n" );
+ }
}
# Note that this runs *in a bare git repo*, so we can't check
@@ -175,98 +175,98 @@ sub check_message {
# have to run 'git ls-tree' to get them, which slows this down
# slightly.
{
- my %cats;
-
- sub init_cats {
- my @cmd = ("git", "ls-tree", "-d", "--name-only", $default_branch);
- debug("executing " . join(" ", @cmd));
- open(my $gitpipe, "-|", @cmd) or fatal($!);
-
- while(my $l=<$gitpipe>) {
- next if $l =~ /^\./; # skip .forgejo and .github dirs
- chomp $l;
- $cats{$l}++;
- }
- close $gitpipe;
-
- # Allow "git" as a 'category', aclemons uses it in CI.
- $cats{git}++;
-
- debug("categories: " . join " ", sort { $a cmp $b } keys %cats);
- }
-
- sub category_ok {
- init_cats() unless %cats;
- return $cats{$_[0]};
- }
+ my %cats;
+
+ sub init_cats {
+ my @cmd = ("git", "ls-tree", "-d", "--name-only", $default_branch);
+ debug("executing " . join(" ", @cmd));
+ open(my $gitpipe, "-|", @cmd) or fatal($!);
+
+ while(my $l=<$gitpipe>) {
+ next if $l =~ /^\./; # skip .forgejo and .github dirs
+ chomp $l;
+ $cats{$l}++;
+ }
+ close $gitpipe;
+
+ # Allow "git" as a 'category', aclemons uses it in CI.
+ $cats{git}++;
+
+ debug("categories: " . join " ", sort { $a cmp $b } keys %cats);
+ }
+
+ sub category_ok {
+ init_cats() unless %cats;
+ return $cats{$_[0]};
+ }
}
sub print_opt_help {
- print yellow("Options:") . "\n";
- print " " . green("-o skip") .
- " Accept all commit message as-is; skip error checking.\n";
- print " " . green("-o debug") .
- " Print debug messages about commit message checking.\n";
- print " " . green("-o mono") .
- " Don't colorize output.\n";
- print " " . green("-o help") .
- " Display this help and abort the commit.\n";
+ print yellow("Options:") . "\n";
+ print " " . green("-o skip") .
+ " Accept all commit message as-is; skip error checking.\n";
+ print " " . green("-o debug") .
+ " Print debug messages about commit message checking.\n";
+ print " " . green("-o mono") .
+ " Don't colorize output.\n";
+ print " " . green("-o help") .
+ " Display this help and abort the commit.\n";
}
# Don't be picky about case or whether someone types "debugging"
# when they meant "debug".
sub process_push_opt {
- my $opt = lc shift;
- if($opt =~ /debug/) {
- $debugging++;
- } elsif($opt =~ /skip/) {
- $skip++;
- } elsif($opt =~ /mono/) {
- $color_output = 0;
- init_colors();
- } elsif($opt =~ /help/) {
- $help++;
- } else {
- fatal("$SELF: unknown push option '-o $opt', try '-o help'");
- }
+ my $opt = lc shift;
+ if($opt =~ /debug/) {
+ $debugging++;
+ } elsif($opt =~ /skip/) {
+ $skip++;
+ } elsif($opt =~ /mono/) {
+ $color_output = 0;
+ init_colors();
+ } elsif($opt =~ /help/) {
+ $help++;
+ } else {
+ fatal("$SELF: unknown push option '-o $opt', try '-o help'");
+ }
}
# man page githooks(5) and git's pre-receive.sample explain
# how this works.
sub read_push_options {
- return unless my $count = $ENV{GIT_PUSH_OPTION_COUNT};
- for(my $i = 0; $i < $count; $i++) {
- process_push_opt($ENV{"GIT_PUSH_OPTION_" . $i});
- }
+ return unless my $count = $ENV{GIT_PUSH_OPTION_COUNT};
+ for(my $i = 0; $i < $count; $i++) {
+ process_push_opt($ENV{"GIT_PUSH_OPTION_" . $i});
+ }
}
sub init_colors {
- # Good old ANSI colors. Really should be using 'tput' or something
- # to get these, but I don't think anyone's still using anything
- # that doesn't either support or at least know how to ignore these
- # escape codes.
- # Note that the "1;" means we're using bold. It looks nicer to
- # me, on my black-background urxvt, but YMMV.
- if($color_output) {
- $red = "\x1b[1;31m";
- $yellow = "\x1b[1;33m";
- $green = "\x1b[1;32m";
- $color_off = "\x1b[0m";
- } else {
- $red = $yellow = $green = $color_off = "";
- }
+ # Good old ANSI colors. Really should be using 'tput' or something
+ # to get these, but I don't think anyone's still using anything
+ # that doesn't either support or at least know how to ignore these
+ # escape codes.
+ # Note that the "1;" means we're using bold. It looks nicer to
+ # me, on my black-background urxvt, but YMMV.
+ if($color_output) {
+ $red = "\x1b[1;31m";
+ $yellow = "\x1b[1;33m";
+ $green = "\x1b[1;32m";
+ $color_off = "\x1b[0m";
+ } else {
+ $red = $yellow = $green = $color_off = "";
+ }
}
sub red {
- return "$red$_[0]$color_off";
+ return "$red$_[0]$color_off";
}
sub yellow {
- return "$yellow$_[0]$color_off";
+ return "$yellow$_[0]$color_off";
}
sub green {
- return "$green$_[0]$color_off";
+ return "$green$_[0]$color_off";
}
### main()
@@ -275,18 +275,18 @@ init_colors();
read_push_options();
if($help) {
- print_opt_help();
- exit 1;
+ print_opt_help();
+ exit 1;
}
if($debugging) {
- chomp(my $pwd = `pwd`);
- debug("$0 starting up in dir $pwd with -o debug");
+ chomp(my $pwd = `pwd`);
+ debug("$0 starting up in dir $pwd with -o debug");
}
if($skip) {
- debug("skipping commit message checks due to -o skip");
- exit 0;
+ debug("skipping commit message checks due to -o skip");
+ exit 0;
}
# Lines of input look like:
@@ -295,44 +295,44 @@ if($skip) {
# Normally we only get one line of input, but it's unclear to me
# whether this is *always* the case, hence the while loop.
while(<STDIN>) {
- chomp;
- debug("STDIN line: $_");
- my($start, $end, $ref, undef) = split / /;
- # $ref currently unused, but maybe it shouldn't be?
-
- if($start eq ('0' x 40)) {
- # all-zeroes start hash means, new branch being pushed
- $range = "$default_branch..$end";
- } else {
- $range = "$start..$end";
- }
- debug("range $range");
-
- my $cmd = "git log --pretty=format:%h%x09%s $range";
- my @cmd = ("git", "log", "--pretty=format:%h%x09%s", $range);
- debug("executing: " . join " ", @cmd);
-
- my $count = 0;
- open(my $git, "-|", @cmd) or fatal($!);
- while(<$git>) {
- chomp;
- debug("read line from git: $_\n");
- $count++;
- my($hash, $msg) = split /\t/, $_, 2;
- check_message($msg, $hash);
- }
- close $git;
-
- debug("checked $count commit message" . ($count == 1 ? "" : "s"));
+ chomp;
+ debug("STDIN line: $_");
+ my($start, $end, $ref, undef) = split / /;
+ # $ref currently unused, but maybe it shouldn't be?
+
+ if($start eq ('0' x 40)) {
+ # all-zeroes start hash means, new branch being pushed
+ $range = "$default_branch..$end";
+ } else {
+ $range = "$start..$end";
+ }
+ debug("range $range");
+
+ my $cmd = "git log --pretty=format:%h%x09%s $range";
+ my @cmd = ("git", "log", "--pretty=format:%h%x09%s", $range);
+ debug("executing: " . join " ", @cmd);
+
+ my $count = 0;
+ open(my $git, "-|", @cmd) or fatal($!);
+ while(<$git>) {
+ chomp;
+ debug("read line from git: $_\n");
+ $count++;
+ my($hash, $msg) = split /\t/, $_, 2;
+ check_message($msg, $hash);
+ }
+ close $git;
+
+ debug("checked $count commit message" . ($count == 1 ? "" : "s"));
}
if(@errs) {
- print red("!!! git push aborted; fix the errors below and try again.") .
- "\n ...or, if you're " . red("100% certain") .
- " everything is correct, re-run the\n" .
- " command as: " . yellow("git push -o skip") . "\n" .
- " ...and let Urchlay know you found a bug in the pre-receive hook.\n\n";
- print for @errs;
+ print red("!!! git push aborted; fix the errors below and try again.") .
+ "\n ...or, if you're " . red("100% certain") .
+ " everything is correct, re-run the\n" .
+ " command as: " . yellow("git push -o skip") . "\n" .
+ " ...and let Urchlay know you found a bug in the pre-receive hook.\n\n";
+ print for @errs;
}
exit @errs;