1 eval '(exit $?0)' && eval 'exec perl -w "$0" ${1+"$@"}'
2 & eval 'exec perl -w "$0" $argv:q'
5 # An hook script to check the commit log message.
6 # Called by "git commit" with one argument, the name of the file
7 # that has the commit message. The hook should exit with non-zero
8 # status after issuing an appropriate message if it wants to stop the
9 # commit. The hook is allowed to edit the commit message file.
11 # To enable this hook, copy it to "~/.git/hooks/commit-msg".
13 # This script is based on the one from GNU coreutils.
17 (my $ME = $0) =~ s|.*/||;
19 my $editor = $ENV{EDITOR} || 'vi';
20 $ENV{PATH} = '/bin:/usr/bin';
22 # Rewrite the $LOG_FILE (old contents in @$LINE_REF) with an additional
23 # commented diagnostic "# $ERR" line at the top.
26 my ($log_file, $err, $line_ref) = @_;
28 open LOG, '>', $log_file
29 or die "$ME: $log_file: failed to open for writing: $!";
33 or die "$ME: $log_file: failed to rewrite: $!\n";
40 warn "Interrupt (Ctrl-C) to abort...\n";
42 system 'sh', '-c', "$editor $log_file";
43 ($? & 127) || ($? >> 8)
44 and die "$ME: $log_file: the editor ($editor) failed, aborting\n";
47 # Given a $LOG_FILE name and a \@LINE buffer,
48 # read the contents of the file into the buffer and analyze it.
49 # If the log message passes muster, return the empty string.
50 # If not, return a diagnostic.
53 my ($log_file, $line_ref) = @_;
56 open LOG, '<', $log_file
57 or return "failed to open for reading: $!";
61 my @line = @$line_ref;
64 # Don't filter out blank or comment lines; git does that already,
65 # and if we were to ignore them here, it could lead to committing
66 # with lines that start with "#" in the log.
68 # Filter out leading blank and comment lines.
69 # while (@line && $line[0] =~ /^(?:#.*|[ \t]*)$/) { shift @line; }
71 # Filter out blank and comment lines at EOF.
72 # while (@line && $line[$#line] =~ /^(?:#.*|[ \t]*)$/) { pop @line; }
75 and return 'no log message';
77 # The first line should not be too short
78 8 < length $line[0] || return 'summary line too short';
80 # The first line should not start with an asterisk or a hash sign.
81 # An asterisk might indicate that a change entry was started right
83 $line[0] =~ /^[*#]/ && return "summary line starts with an * or #";
85 # Second line should be blank or not present.
86 2 <= @line && length $line[1]
87 and return 'second line must be empty';
89 # Limit line length to allow for the ChangeLog's leading TAB.
90 foreach my $line (@line)
92 72 < length $line && $line =~ /^[^#]/
93 and return 'line longer than 72 characters';
103 my $log_file = $ARGV[0];
108 my $err = check_msg $log_file, \@line;
111 $err = "$ME: $err\n";
115 # Insert the diagnostic as a comment on the first line of $log_file.
116 #rewrite $log_file, $err, \@line;
119 ## Stop if our parent is killed.