diff options
| author | B. Watson <urchlay@slackware.uk> | 2026-11-30 06:55:11 -0500 |
|---|---|---|
| committer | B. Watson <urchlay@slackware.uk> | 2026-11-30 06:55:11 -0500 |
| commit | 346167ea0bda2346b415c31507905e95faa0b1fd (patch) | |
| tree | 61c98cc5aa3f65fde9603c2e45c4325b2df1a9e2 /hooks/pre-receive | |
| parent | 77f9ffb2de1e88fcce24c4ee420731b3147a1bc6 (diff) | |
| download | sbo-maintainer-tools-346167ea0bda2346b415c31507905e95faa0b1fd.tar.gz | |
hooks/*: replace tab indents with 2 spaces each.
Diffstat (limited to 'hooks/pre-receive')
| -rwxr-xr-x | hooks/pre-receive | 344 |
1 files changed, 172 insertions, 172 deletions
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; |
