Hooks/CheckMimeTypes.pm untested

filter: Statementstmt 0.0% 0 / 37 Branchbran 0.0% 0 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 60 CC 8 SCAR 33.9
CC
8
Cov
0%
pre_commit
56.0
CHECK_MIMETYPES
6.0
BEGIN
2.0
CRAP 29.6
1 package SVN::Hooks::CheckMimeTypes;
2 # ABSTRACT: Require the svn:mime-type property.
3 $SVN::Hooks::CheckMimeTypes::VERSION = '1.35';
4 use strict;
5 use warnings;
6  
7 use Carp;
8 use SVN::Hooks;
9  
10 use Exporter qw/import/;
11 my $HOOK = 'CHECK_MIMETYPES';
12 our @EXPORT = ($HOOK);
13  
14  
15 my $Help = <<"EOS";
16 You may want to consider uncommenting the auto-props section
17 in your ~/.subversion/config file. Read the Subversion book
18 (http://svnbook.red-bean.com/), Chapter 7, Properties section,
19 Automatic Property Setting subsection for more help.
20 EOS
21  
22 sub CHECK_MIMETYPES {
23 my ($help) = @_;
24 $Help = $help if defined $help;
25  
26 PRE_COMMIT(\&pre_commit);
27  
28 return 1;
29 }
30  
31 sub pre_commit {
32 my ($svnlook) = @_;
33  
34 my @errors;
35  
36 foreach my $added ($svnlook->added()) {
37 next if $added =~ m:/$:; # disregard directories
38 my $props = $svnlook->proplist($added);
39  
40 next if exists $props->{'svn:special'}; # disregard symbolic links too
41  
42 unless (my $mimetype = $props->{'svn:mime-type'}) {
43 push @errors, "property svn:mime-type is not set for: $added";
44 } elsif ($mimetype =~ m:^text/:) {
45 for my $prop ('svn:eol-style', 'svn:keywords') {
46 push @errors, "property $prop is not set for text file: $added"
47 unless exists $props->{$prop};
48 }
49 }
50 }
51  
52 if (@errors) {
53 croak "$HOOK:\n", join("\n", @errors), <<'EOS', $Help;
54  
55 Every added file must have the svn:mime-type property set. In
56 addition, text files must have the svn:eol-style and svn:keywords
57 properties set.
58  
59 For binary files try running
60 svn propset svn:mime-type application/octet-stream path/of/file
61  
62 For text files try
63 svn propset svn:mime-type text/plain path/of/file
64 svn propset svn:eol-style native path/of/file
65 svn propset svn:keywords 'Author Date Id Revision' path/of/file
66  
67 EOS
68 }
69 }
70  
71 1; # End of SVN::Hooks::CheckMimeTypes
72  
73 __END__