File Coverage

lib/Dist/Zilla/Plugin/Git/ExcludeUntracked.pm
Criterion Covered Total %
statement 27 35 77.1
branch 3 6 50.0
condition n/a
subroutine 4 6 66.6
pod 1 1 100.0
total 35 48 72.9


line stmt bran cond sub pod time code
1             ## no critic (RequireUseStrict)
2             package Dist::Zilla::Plugin::Git::ExcludeUntracked;
3             {
4             $Dist::Zilla::Plugin::Git::ExcludeUntracked::VERSION = '0.03';
5             }
6              
7             ## use critic (RequireUseStrict)
8 2     2   2778734 use Moose;
  2         6  
  2         15  
9 2     2   13238 use File::Find;
  2         5  
  2         992  
10              
11             with 'Dist::Zilla::Role::FilePruner';
12              
13             sub _gather_files_under_dir {
14 0     0   0 my ( $self, $dirname ) = @_;
15              
16 0         0 my @files;
17              
18             find(sub {
19 0 0   0   0 return if -d;
20              
21 0         0 push @files, $File::Find::name;
22 0         0 }, $dirname);
23              
24 0         0 return @files;
25             }
26              
27             sub _assemble_untracked_lookup {
28 2     2   8 my ( $self ) = @_;
29              
30 7         98 my @untracked_files = map {
31 2         28740 chomp; $_
  7         67  
32             } qx(git ls-files --other);
33              
34 2         21 my @subdir_files;
35 2         27 foreach my $file (@untracked_files) {
36 7 50       141 if($file =~ m{/$}) {
37 0         0 push @subdir_files, $self->_gather_files_under_dir($file);
38 0         0 undef $file;
39             }
40             }
41 2         16 @untracked_files = grep { defined() } @untracked_files;
  7         35  
42 2         15 push @untracked_files, @subdir_files;
43              
44 2         9 return map { $_ => 1 } @untracked_files;
  7         84  
45             }
46              
47             sub prune_files {
48 2     2 1 497008 my ( $self ) = @_;
49              
50 2         121 my $zilla = $self->zilla;
51 2         21 my @files = @{ $zilla->files };
  2         77  
52 2         30 my %untracked_lookup = $self->_assemble_untracked_lookup;
53              
54 2         24 foreach my $file (@files) {
55 28 100       2107 if(exists $untracked_lookup{$file->name}) {
56 7         299 $self->log_debug([ 'pruning %s', $file->name ]);
57 7         846 $zilla->prune_file($file);
58             }
59             }
60             }
61              
62             __PACKAGE__->meta->make_immutable;
63              
64             1;
65              
66              
67              
68             =pod
69              
70             =head1 NAME
71              
72             Dist::Zilla::Plugin::Git::ExcludeUntracked - Excludes untracked files from your dist
73              
74             =head1 VERSION
75              
76             version 0.03
77              
78             =head1 SYNOPSIS
79              
80             [Git::ExcludeUntracked]
81              
82             =head1 DESCRIPTION
83              
84             This L<Dist::Zilla> plugin automatically excludes any files from your
85             distribution that are not currently tracked by Git.
86              
87             =head1 COMPARED TO GIT::GATHERDIR
88              
89             There's another plugin that provides similar functionality:
90             L<Dist::Zilla::Plugin::Git::GatherDir>. The chief difference is that
91             while this plugin is designed to work in concert with
92             L<Dist::Zilla::Plugin::GatherDir>, C<Git::GatherDir> is designed to work
93             as a replacement for C<GatherDir>.
94              
95             =head1 SEE ALSO
96              
97             L<Dist::Zilla>, L<Dist::Zilla::Plugin::Git::GatherDir>
98              
99             =begin comment
100              
101             =over
102              
103             =item prune_files
104              
105             =back
106              
107             =end comment
108              
109             =head1 AUTHOR
110              
111             Rob Hoelz <rob@hoelz.ro>
112              
113             =head1 COPYRIGHT AND LICENSE
114              
115             This software is copyright (c) 2013 by Rob Hoelz.
116              
117             This is free software; you can redistribute it and/or modify it under
118             the same terms as the Perl 5 programming language system itself.
119              
120             =head1 BUGS
121              
122             Please report any bugs or feature requests on the bugtracker website
123             https://github.com/hoelzro/dist-zilla-plugin-git-excludeuntracked/issues
124              
125             When submitting a bug or request, please include a test-file or a
126             patch to an existing test-file that illustrates the bug or desired
127             feature.
128              
129             =cut
130              
131              
132             __END__
133              
134             # ABSTRACT: Excludes untracked files from your dist
135