1package SVN::Hooks::CheckMimeTypes; 2# ABSTRACT: Require the svn:mime-type property. 3$SVN::Hooks::CheckMimeTypes::VERSION = '1.34'; 4use strict; 5use warnings; 6 7use Carp; 8use SVN::Hooks; 9 10use Exporter qw/import/; 11my $HOOK = 'CHECK_MIMETYPES'; 12our @EXPORT = ($HOOK); 13 14 15my $Help = <<"EOS"; 16You may want to consider uncommenting the auto-props section 17in your ~/.subversion/config file. Read the Subversion book 18(http://svnbook.red-bean.com/), Chapter 7, Properties section, 19Automatic Property Setting subsection for more help. 20EOS 21 22sub CHECK_MIMETYPES { 23 my ($help) = @_; 24 $Help = $help if defined $help; 25 26 PRE_COMMIT(\&pre_commit); 27 28 return 1; 29} 30 31sub 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 55Every added file must have the svn:mime-type property set. In 56addition, text files must have the svn:eol-style and svn:keywords 57properties set. 58 59For binary files try running 60svn propset svn:mime-type application/octet-stream path/of/file 61 62For text files try 63svn propset svn:mime-type text/plain path/of/file 64svn propset svn:eol-style native path/of/file 65svn propset svn:keywords 'Author Date Id Revision' path/of/file 66 67EOS 68 } 69} 70 711; # End of SVN::Hooks::CheckMimeTypes 72 73__END__ 74 75=pod 76 77=encoding UTF-8 78 79=head1 NAME 80 81SVN::Hooks::CheckMimeTypes - Require the svn:mime-type property. 82 83=head1 VERSION 84 85version 1.34 86 87=head1 SYNOPSIS 88 89This SVN::Hooks plugin checks if the files added to the repository 90have the B<svn:mime-type> property set. Moreover, for text files, it 91checks if the properties B<svn:eol-style> and B<svn:keywords> are also 92set. 93 94The plugin was based on the 95L<check-mime-type.pl|http://svn.digium.com/view/repotools/check-mime-type.pl> 96script. 97 98It's active in the C<pre-commit> hook. 99 100It's configured by the following directive. 101 102=head2 CHECK_MIMETYPES([MESSAGE]) 103 104This directive enables the checking, causing the commit to abort if it 105doesn't comply. 106 107The MESSAGE argument is an optional help message shown to the user in 108case the commit fails. Note that by default the plugin already inserts 109a rather verbose help message in case of errors. 110 111 CHECK_MIMETYPES("Use TortoiseSVN -> Properties menu option to set properties."); 112 113=for Pod::Coverage pre_commit 114 115=head1 AUTHOR 116 117Gustavo L. de M. Chaves <gnustavo@cpan.org> 118 119=head1 COPYRIGHT AND LICENSE 120 121This software is copyright (c) 2016 by CPqD <www.cpqd.com.br>. 122 123This is free software; you can redistribute it and/or modify it under 124the same terms as the Perl 5 programming language system itself. 125 126=cut 127