line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::GitHooks::Plugin::DetectCommitNoVerify; |
2
|
|
|
|
|
|
|
|
3
|
5
|
|
|
5
|
|
731423
|
use strict; |
|
5
|
|
|
|
|
7
|
|
|
5
|
|
|
|
|
109
|
|
4
|
5
|
|
|
5
|
|
17
|
use warnings; |
|
5
|
|
|
|
|
5
|
|
|
5
|
|
|
|
|
97
|
|
5
|
|
|
|
|
|
|
|
6
|
5
|
|
|
5
|
|
14
|
use base 'App::GitHooks::Plugin'; |
|
5
|
|
|
|
|
7
|
|
|
5
|
|
|
|
|
719
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# External dependencies. |
9
|
5
|
|
|
5
|
|
2832
|
use Capture::Tiny qw(); |
|
5
|
|
|
|
|
41532
|
|
|
5
|
|
|
|
|
142
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# Internal dependencies. |
12
|
5
|
|
|
5
|
|
431
|
use App::GitHooks::Constants qw( :PLUGIN_RETURN_CODES ); |
|
5
|
|
|
|
|
3338
|
|
|
5
|
|
|
|
|
594
|
|
13
|
5
|
|
|
5
|
|
1322
|
use App::GitHooks::Hook::PreCommit; |
|
5
|
|
|
|
|
23236
|
|
|
5
|
|
|
|
|
1341
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 NAME |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
App::GitHooks::Plugin::DetectCommitNoVerify - Find out when someone uses --no-verify and append the pre-commit checks to the commit message. |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 DESCRIPTION |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
Sometimes you just have to use C<--no-verify> to get past the checks and commit |
24
|
|
|
|
|
|
|
as fast as possible. To prevent this from being too tempting, this plugin |
25
|
|
|
|
|
|
|
checks when you use --no-verify and runs the pre-commit checks if you've |
26
|
|
|
|
|
|
|
skipped them. It will let you commit even if the pre-commit checks fail, but it |
27
|
|
|
|
|
|
|
will add their output to the commit message for posterity (and public shaming). |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=head1 VERSION |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
Version 1.0.3 |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=cut |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
our $VERSION = '1.0.3'; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head1 METHODS |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head2 run_prepare_commit_msg() |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
Code to execute as part of the prepare-commit-msg hook. |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
my $success = App::GitHooks::Plugin::DetectCommitNoVerify->run_prepare_commit_msg(); |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=cut |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub run_prepare_commit_msg |
50
|
|
|
|
|
|
|
{ |
51
|
2
|
|
|
2
|
1
|
7352
|
my ( $class, %args ) = @_; |
52
|
2
|
|
|
|
|
4
|
my $app = delete( $args{'app'} ); |
53
|
2
|
|
|
|
|
2
|
my $commit_message = delete( $args{'commit_message'} ); |
54
|
2
|
|
|
|
|
6
|
my $repository = $app->get_repository(); |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# Check if we've run the pre-commit hook. |
57
|
2
|
50
|
|
|
|
75506
|
return $PLUGIN_RETURN_SKIPPED |
58
|
|
|
|
|
|
|
if -e '.git/COMMIT-MSG-CHECKS'; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
# Check the changes and gather the output. |
61
|
2
|
|
|
|
|
6
|
my $changes_pass; |
62
|
|
|
|
|
|
|
my $stdout = Capture::Tiny::capture_stdout( |
63
|
|
|
|
|
|
|
sub |
64
|
|
|
|
|
|
|
{ |
65
|
|
|
|
|
|
|
# Pretend we're running the pre-commit hook here to gather its output. |
66
|
2
|
|
|
2
|
|
1864
|
my $local_app = $app->clone( |
67
|
|
|
|
|
|
|
name => 'pre-commit', |
68
|
|
|
|
|
|
|
); |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
# Git commit messages don't seem to like utf8, so force disabling it. |
71
|
2
|
|
|
|
|
488
|
my $terminal = $local_app->get_terminal(); |
72
|
2
|
|
|
|
|
20
|
$terminal->is_utf8(0); |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
# Run all the tests for the pre-commit hook. |
75
|
2
|
|
|
|
|
36
|
$changes_pass = App::GitHooks::Hook::PreCommit::run_all_tests( $local_app ); |
76
|
|
|
|
|
|
|
} |
77
|
2
|
|
|
|
|
138
|
); |
78
|
|
|
|
|
|
|
|
79
|
1
|
50
|
|
|
|
1013315
|
if ( !$changes_pass ) |
80
|
|
|
|
|
|
|
{ |
81
|
|
|
|
|
|
|
# "git revert" bypasses the pre-commit hook, so we can only use use the |
82
|
|
|
|
|
|
|
# prepare-commit-msg hook to catch any show-stoppers. |
83
|
|
|
|
|
|
|
# Since prepare-commit-msg doesn't support --no-verify, we should only |
84
|
|
|
|
|
|
|
# perform the essential checks when we're analyzing a revert. Note that you |
85
|
|
|
|
|
|
|
# can still do chmod -x .git/hooks/prepare-commit-msg to force-bypass this |
86
|
|
|
|
|
|
|
# hook in this case. |
87
|
1
|
|
|
|
|
7
|
my $staged_changes = $app->get_staged_changes(); |
88
|
1
|
50
|
|
|
|
67
|
if ( $staged_changes->is_revert() ) |
89
|
|
|
|
|
|
|
{ |
90
|
0
|
|
|
|
|
0
|
chomp( $stdout ); |
91
|
0
|
|
|
|
|
0
|
print $stdout, "\n"; |
92
|
0
|
|
|
|
|
0
|
print "\n"; |
93
|
0
|
|
|
|
|
0
|
print $app->color( 'red', "Fix the errors above and use 'git commit' to complete the revert." ) . "\n"; |
94
|
0
|
|
|
|
|
0
|
return $PLUGIN_RETURN_FAILED; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
# If output was generated by the pre-commit hooks, append it to the commit |
98
|
|
|
|
|
|
|
# message. |
99
|
1
|
50
|
|
|
|
62
|
if ( $stdout =~ /\w/ ) |
100
|
|
|
|
|
|
|
{ |
101
|
1
|
|
|
|
|
3
|
chomp( $stdout ); |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
# Git commit messages don't support ANSI control characters (which we |
104
|
|
|
|
|
|
|
# use for colors), so we need to strip those out. |
105
|
1
|
|
|
|
|
5
|
$stdout =~ s/\e\[[\d;]*[a-zA-Z]//g; |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
# We need to append $stdout to $commit_message, as $commit_message will |
108
|
|
|
|
|
|
|
# contain the message passed via -m and this should be at the top of |
109
|
|
|
|
|
|
|
# the final message. |
110
|
1
|
|
|
|
|
11
|
$commit_message->update_message( $commit_message->get_message() . "\n\n" . $stdout ); |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
1
|
|
|
|
|
31
|
return $PLUGIN_RETURN_PASSED; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head1 BUGS |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Please report any bugs or feature requests through the web interface at |
121
|
|
|
|
|
|
|
L. |
122
|
|
|
|
|
|
|
I will be notified, and then you'll automatically be notified of progress on |
123
|
|
|
|
|
|
|
your bug as I make changes. |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head1 SUPPORT |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
perldoc App::GitHooks::Plugin::DetectCommitNoVerify |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
You can also look for information at: |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=over |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=item * GitHub's request tracker |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
L |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
L |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=item * CPAN Ratings |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
L |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=item * MetaCPAN |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
L |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=back |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=head1 AUTHOR |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
L, |
159
|
|
|
|
|
|
|
C<< >>. |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
Copyright 2013-2016 Guillaume Aubert. |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
This code is free software; you can redistribute it and/or modify it under the |
167
|
|
|
|
|
|
|
same terms as Perl 5 itself. |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful, but WITHOUT ANY |
170
|
|
|
|
|
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
171
|
|
|
|
|
|
|
PARTICULAR PURPOSE. See the LICENSE file for more details. |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=cut |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
1; |