package SVN::Hooks::CheckMimeTypes; use strict; use warnings; use Carp; use SVN::Hooks; use Exporter qw/import/; my $HOOK = 'CHECK_MIMETYPES'; our @EXPORT = ($HOOK); our $VERSION = $SVN::Hooks::VERSION; =head1 NAME SVN::Hooks::CheckMimeTypes - Require the svn:mime-type property. =head1 SYNOPSIS This SVN::Hooks plugin checks if the files added to the repository have the B property set. Moreover, for text files, it checks if the properties B and B are also set. The plugin was based on the L script. It's active in the C hook. It's configured by the following directive. =head2 CHECK_MIMETYPES([MESSAGE]) This directive enables the checking, causing the commit to abort if it doesn't comply. The MESSAGE argument is an optional help message shown to the user in case the commit fails. Note that by default the plugin already inserts a rather verbose help message in case of errors. CHECK_MIMETYPES("Use TortoiseSVN -> Properties menu option to set properties."); =cut my $Help = <<"EOS"; You may want to consider uncommenting the auto-props section in your ~/.subversion/config file. Read the Subversion book (http://svnbook.red-bean.com/), Chapter 7, Properties section, Automatic Property Setting subsection for more help. EOS sub CHECK_MIMETYPES { my ($help) = @_; $Help = $help if defined $help; PRE_COMMIT(\&pre_commit); return 1; } sub pre_commit { my ($svnlook) = @_; my @errors; foreach my $added ($svnlook->added()) { next if $added =~ m:/$:; # disregard directories my $props = $svnlook->proplist($added); unless (my $mimetype = $props->{'svn:mime-type'}) { push @errors, "property svn:mime-type is not set for: $added"; } elsif ($mimetype =~ m:^text/:) { for my $prop ('svn:eol-style', 'svn:keywords') { push @errors, "property $prop is not set for text file: $added" unless exists $props->{$prop}; } } } if (@errors) { croak "$HOOK:\n", join("\n", @errors), <<'EOS', $Help; Every added file must have the svn:mime-type property set. In addition, text files must have the svn:eol-style and svn:keywords properties set. For binary files try running svn propset svn:mime-type application/octet-stream path/of/file For text files try svn propset svn:mime-type text/plain path/of/file svn propset svn:eol-style native path/of/file svn propset svn:keywords 'Author Date Id Revision' path/of/file EOS } } =head1 AUTHOR Gustavo Chaves, C<< >> =head1 BUGS Please report any bugs or feature requests to C, or through the web interface at L. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. =head1 SUPPORT You can find documentation for this module with the perldoc command. perldoc SVN::Hooks You can also look for information at: =over 4 =item * RT: CPAN's request tracker L =item * AnnoCPAN: Annotated CPAN documentation L =item * CPAN Ratings L =item * Search CPAN L =back =head1 ACKNOWLEDGEMENTS To the author of the C script at L. =head1 COPYRIGHT & LICENSE Copyright 2008-2011 CPqD, all rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut 1; # End of SVN::Hooks::CheckMimeTypes