| 1 | #!/usr/bin/env perl | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 6 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 6 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | # External dependencies. | ||||||||||||||||||||||||||||
| 7 | 6 | ▶ | use App::GitHooks; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 6 | ▶ | use Cwd qw(); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 6 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 6 | ▶ | use Data::Section -setup; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 6 | ▶ | use File::Spec; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 6 | ▶ | use Getopt::Long; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 6 | ▶ | use Git::Repository; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 6 | ▶ | use Pod::Usage qw(); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 6 | ▶ | use Try::Tiny; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 6 | ▶ | use autodie; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | =head1 NAME | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | githooks - Setup utility for App::GitHooks | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | =head1 VERSION | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | Version 1.7.3 | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | This command line utility allows setting up git hooks in the current git | ||||||||||||||||||||||||||||
| 32 | repository, so that all of App::GitHooks' hooks are triggered properly. | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | githooks <command> | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | =head1 COMMANDS | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | =over 4 | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | =item * C<help> - Show the commands available. | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | =item * C<install> - Install all the git hooks for the current repository. | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | =item * C<list> - List the plugins currently installed. | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | =item * C<uninstall> - Remove all the git hooks for the current repository. | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | =item * C<version> - Display the version of App::GitHooks in use. | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | =back | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | =head1 OPTIONS | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | =over 4 | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | =item * C<--chmod> - Chmod to use for the git hooks (default: 755). | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | =back | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | =cut | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | # Parse the action. | ||||||||||||||||||||||||||||
| 68 | 6 | my $action = shift( @ARGV ); | |||||||||||||||||||||||||||
| 69 | 6 | ▶ | usage() | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not defined $action or $action eq ""
MC/DC50%1/2
not defined $action or $action eq ""
not defined $action
$action eq ""
Truth table66%2/3
not(A) or B
A= not defined $actionB= $action eq ""
| |||||||||||||||||||||||||||||
| 70 | if !defined( $action ) || $action eq ''; | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | # Parse command-line options. | ||||||||||||||||||||||||||||
| 73 | 5 | my $chmod = '0755'; | |||||||||||||||||||||||||||
| 74 | 5 | Getopt::Long::GetOptions( | |||||||||||||||||||||||||||
| 75 | 'chmod' => \$chmod, | ||||||||||||||||||||||||||||
| 76 | ); | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | # List of supported hooks we'll need to set up. | ||||||||||||||||||||||||||||
| 79 | 5 | my $supported_hooks = $App::GitHooks::HOOK_NAMES; | |||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | # Actions. | ||||||||||||||||||||||||||||
| 82 | 5 | my $actions = | |||||||||||||||||||||||||||
| 83 | { | ||||||||||||||||||||||||||||
| 84 | help => \&usage, | ||||||||||||||||||||||||||||
| 85 | install => \&install, | ||||||||||||||||||||||||||||
| 86 | list => \&list, | ||||||||||||||||||||||||||||
| 87 | uninstall => \&uninstall, | ||||||||||||||||||||||||||||
| 88 | version => \&version, | ||||||||||||||||||||||||||||
| 89 | }; | ||||||||||||||||||||||||||||
| 90 | 5 | ▶ | if ( !defined( $actions->{ $action } ) ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 91 | { | ||||||||||||||||||||||||||||
| 92 | 1 | usage( "The action '$action' is not valid." ); | |||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | 4 | $actions->{ $action }(); | |||||||||||||||||||||||||||
| 95 | 3 | exit(0); | |||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | =head1 FUNCTIONS | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | =head2 usage() | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | Display the usage information on the command line and force exit. | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | usage(); | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | =cut | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | sub usage | ||||||||||||||||||||||||||||
| 109 | { | ||||||||||||||||||||||||||||
| 110 | 3 | ▶ | my ( $message ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
usage: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 111 | 3 | ▶ | chomp( $message ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 112 | if defined( $message ); | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | 3 | ▶ | $message //= "Setup utility for App::GitHooks."; | ||||||||||||||||||||||||||
|
Condition100%2/2
$message //= "Setup utility for App::GitHooks."
MC/DC100%1/1
$message //= "Setup utility for App::GitHooks."
$message
Truth table100%2/2
A
A= $message
| |||||||||||||||||||||||||||||
| 115 | 3 | $message = "\n$message\n"; | |||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 3 | Pod::Usage::pod2usage( | |||||||||||||||||||||||||||
| 118 | { | ||||||||||||||||||||||||||||
| 119 | -message => $message, | ||||||||||||||||||||||||||||
| 120 | -exitval => 'NOEXIT', | ||||||||||||||||||||||||||||
| 121 | -verbose => 99, | ||||||||||||||||||||||||||||
| 122 | -sections => | ||||||||||||||||||||||||||||
| 123 | [ | ||||||||||||||||||||||||||||
| 124 | qw( | ||||||||||||||||||||||||||||
| 125 | SYNOPSIS | ||||||||||||||||||||||||||||
| 126 | COMMANDS | ||||||||||||||||||||||||||||
| 127 | OPTIONS | ||||||||||||||||||||||||||||
| 128 | ) | ||||||||||||||||||||||||||||
| 129 | ], | ||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||
| 131 | ); | ||||||||||||||||||||||||||||
| 132 | 3 | exit(0); | |||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | =head2 uninstall() | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | Remove git hooks triggering App::GitHooks from the current git repository. | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | uninstall(); | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | =cut | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | sub uninstall | ||||||||||||||||||||||||||||
| 145 | { | ||||||||||||||||||||||||||||
| 146 | 1 | ▶ | my $hooks_directory = get_hooks_directory(); | ||||||||||||||||||||||||||
|
Subroutine
uninstall: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | 1 | foreach my $hook_name ( @$supported_hooks ) | |||||||||||||||||||||||||||
| 149 | { | ||||||||||||||||||||||||||||
| 150 | 17 | my $hook_filename = File::Spec->catfile( $hooks_directory, $hook_name ); | |||||||||||||||||||||||||||
| 151 | 17 | unlink( $hook_filename ); | |||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | 1 | print "The git hooks have been uninstalled successfully.\n"; | |||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | 1 | return; | |||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | =head2 install() | ||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | Install git hooks triggering App::GitHooks for the current git repository. | ||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | install(); | ||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | =cut | ||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | sub install | ||||||||||||||||||||||||||||
| 169 | { | ||||||||||||||||||||||||||||
| 170 | 1 | ▶ | my $hooks_directory = get_hooks_directory(); | ||||||||||||||||||||||||||
|
Subroutine
install: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | # Retrieve the hook template. | ||||||||||||||||||||||||||||
| 173 | 1 | my $hook_template_ref = __PACKAGE__->section_data( 'hook_template' ); | |||||||||||||||||||||||||||
| 174 | 1 | my $template = $$hook_template_ref; | |||||||||||||||||||||||||||
| 175 | 1 | $template =~ s/\Q{{perl}}\E/$^X/g; | |||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | 1 | my $errors = 0; | |||||||||||||||||||||||||||
| 178 | 1 | foreach my $hook_name ( @$supported_hooks ) | |||||||||||||||||||||||||||
| 179 | { | ||||||||||||||||||||||||||||
| 180 | 17 | my $hook_content = $template; | |||||||||||||||||||||||||||
| 181 | 17 | $hook_content =~ s/\Q{{name}}\E/$hook_name/g; | |||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | 17 | my $hook_filename = File::Spec->catfile( $hooks_directory, $hook_name ); | |||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | try | ||||||||||||||||||||||||||||
| 186 | { | ||||||||||||||||||||||||||||
| 187 | # Write the hook file. | ||||||||||||||||||||||||||||
| 188 | 17 | ▶ | open( my $hook_fh, '>', $hook_filename ); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 189 | 17 | print $hook_fh $hook_content; | |||||||||||||||||||||||||||
| 190 | 17 | close( $hook_fh ); | |||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||
| 192 | # Make the hook file executable. | ||||||||||||||||||||||||||||
| 193 | 17 | chmod oct( $chmod ), $hook_filename; | |||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||
| 195 | catch | ||||||||||||||||||||||||||||
| 196 | { | ||||||||||||||||||||||||||||
| 197 | 0 | ▶ | $errors++; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 198 | 0 | print "Unable to set up hook file for $hook_name, skipped: $_\n"; | |||||||||||||||||||||||||||
| 199 | 17 | }; | |||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||
| 202 | 1 | ▶ | print $errors > 0 | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 203 | ? 'Some errors occurred when installing the git hooks, please try again.' | ||||||||||||||||||||||||||||
| 204 | : 'The git hooks have been installed successfully.'; | ||||||||||||||||||||||||||||
| 205 | 1 | print "\n"; | |||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||
| 207 | 1 | return; | |||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | =head2 version() | ||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | Display the version of App::GitHooks in use. | ||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||
| 215 | version(); | ||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||
| 217 | =cut | ||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||
| 219 | sub version | ||||||||||||||||||||||||||||
| 220 | { | ||||||||||||||||||||||||||||
| 221 | 1 | ▶ | print "Using App::GitHooks version $App::GitHooks::VERSION.\n"; | ||||||||||||||||||||||||||
|
Subroutine
version: called CC=4 SCAR=17.3
| |||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||
| 223 | # Instantiate an object, but we're not using any hook-dependent features | ||||||||||||||||||||||||||||
| 224 | # (yet) in this function, so any hook name will do here. | ||||||||||||||||||||||||||||
| 225 | 1 | my $app = App::GitHooks->new( | |||||||||||||||||||||||||||
| 226 | name => 'pre-commit', | ||||||||||||||||||||||||||||
| 227 | ); | ||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||
| 229 | # Retrieve all the plugins available. | ||||||||||||||||||||||||||||
| 230 | my @plugins = | ||||||||||||||||||||||||||||
| 231 | sort keys | ||||||||||||||||||||||||||||
| 232 | ( | ||||||||||||||||||||||||||||
| 233 | 1 | %{{ | |||||||||||||||||||||||||||
| 234 | 0 | map { $_ => 1 } | |||||||||||||||||||||||||||
| 235 | 0 | map { @$_ } | |||||||||||||||||||||||||||
| 236 | 1 | ▶ | values %{ $app->get_all_plugins() || {} } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 237 | }} | ||||||||||||||||||||||||||||
| 238 | ); | ||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||
| 240 | # Display plugin versions. | ||||||||||||||||||||||||||||
| 241 | 1 | ▶ | if ( scalar( @plugins ) != 0 ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 242 | { | ||||||||||||||||||||||||||||
| 243 | 0 | print "\n"; | |||||||||||||||||||||||||||
| 244 | 0 | print "Plugins:\n"; | |||||||||||||||||||||||||||
| 245 | 0 | foreach my $plugin_name ( @plugins ) | |||||||||||||||||||||||||||
| 246 | { | ||||||||||||||||||||||||||||
| 247 | 0 | printf( | |||||||||||||||||||||||||||
| 248 | " - %s: v%s\n", | ||||||||||||||||||||||||||||
| 249 | $plugin_name, | ||||||||||||||||||||||||||||
| 250 | $plugin_name->VERSION(), | ||||||||||||||||||||||||||||
| 251 | ); | ||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||
| 255 | 1 | return; | |||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||
| 259 | =head2 list() | ||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||
| 261 | List the plugins currently installed. | ||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||
| 263 | list(); | ||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||
| 265 | =cut | ||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||
| 267 | sub list | ||||||||||||||||||||||||||||
| 268 | { | ||||||||||||||||||||||||||||
| 269 | # Instantiate an object, but we're not using any hook-dependent features | ||||||||||||||||||||||||||||
| 270 | # (yet) in this function, so any hook name will do here. | ||||||||||||||||||||||||||||
| 271 | 0 | ▶ | my $app = App::GitHooks->new( | ||||||||||||||||||||||||||
|
Subroutine
list: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 272 | name => 'pre-commit', | ||||||||||||||||||||||||||||
| 273 | ); | ||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||
| 275 | # Retrieve all the plugins available. | ||||||||||||||||||||||||||||
| 276 | 0 | my $all_plugins = $app->get_all_plugins(); | |||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||
| 278 | # Display the list of plugins by hook. | ||||||||||||||||||||||||||||
| 279 | 0 | print "\n"; | |||||||||||||||||||||||||||
| 280 | 0 | ▶ | if ( scalar( keys %$all_plugins ) == 0 ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 281 | { | ||||||||||||||||||||||||||||
| 282 | 0 | print "No plugins installed!\n"; | |||||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||||
| 284 | else | ||||||||||||||||||||||||||||
| 285 | { | ||||||||||||||||||||||||||||
| 286 | 0 | foreach my $hook_name ( keys %$all_plugins ) | |||||||||||||||||||||||||||
| 287 | { | ||||||||||||||||||||||||||||
| 288 | 0 | print "Plugins active for $hook_name:\n"; | |||||||||||||||||||||||||||
| 289 | 0 | foreach my $plugin_name ( @{ $all_plugins->{ $hook_name } } ) | |||||||||||||||||||||||||||
| 290 | { | ||||||||||||||||||||||||||||
| 291 | 0 | print " - $plugin_name\n"; | |||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||
| 293 | 0 | print "\n"; | |||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||
| 297 | 0 | return; | |||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||
| 301 | =head1 PRIVATE FUNCTIONS | ||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||
| 303 | =head2 get_hooks_directory() | ||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||
| 305 | Return the path to the hooks directory for the current git repository. | ||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||
| 307 | my $hooks_directory = get_hooks_directory(); | ||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||
| 309 | =cut | ||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||
| 311 | sub get_hooks_directory | ||||||||||||||||||||||||||||
| 312 | { | ||||||||||||||||||||||||||||
| 313 | # Make sure we're in a git repository. | ||||||||||||||||||||||||||||
| 314 | 2 | ▶ | my $current_directory = Cwd::getcwd(); | ||||||||||||||||||||||||||
|
Subroutine
get_hooks_directory: called CC=3 SCAR=11.2
| |||||||||||||||||||||||||||||
| 315 | 2 | my $repository = Git::Repository->new( work_tree => $current_directory ); | |||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||
| 317 | 2 | ▶ | die "The command '$action' requires being in a git repository, which $current_directory is not.\n" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 318 | if !defined( $repository ); | ||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||
| 320 | # Find out the git repository, as the hooks directory will be directly under | ||||||||||||||||||||||||||||
| 321 | # that path. | ||||||||||||||||||||||||||||
| 322 | 2 | my $git_directory = $repository->git_dir(); | |||||||||||||||||||||||||||
| 323 | 2 | ▶ | die "Could not determine git directory for the repository in $current_directory.\n" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 324 | if !defined( $git_directory ); | ||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||
| 326 | 2 | return File::Spec->catfile( $git_directory, 'hooks' ); | |||||||||||||||||||||||||||
| 327 | } | ||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||
| 330 | =head1 BUGS | ||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||
| 332 | Please report any bugs or feature requests through the web interface at | ||||||||||||||||||||||||||||
| 333 | L<https://github.com/guillaumeaubert/App-GitHooks/issues/new>. | ||||||||||||||||||||||||||||
| 334 | I will be notified, and then you'll automatically be notified of progress on | ||||||||||||||||||||||||||||
| 335 | your bug as I make changes. | ||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||
| 338 | =head1 SUPPORT | ||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||
| 340 | You can find documentation for this module with the perldoc command. | ||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||
| 342 | perldoc App::GitHooks | ||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||
| 345 | You can also look for information at: | ||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||
| 347 | =over | ||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||
| 349 | =item * GitHub's request tracker | ||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||
| 351 | L<https://github.com/guillaumeaubert/App-GitHooks/issues> | ||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||
| 353 | =item * AnnoCPAN: Annotated CPAN documentation | ||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||
| 355 | L<http://annocpan.org/dist/app-githooks> | ||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||
| 357 | =item * CPAN Ratings | ||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||
| 359 | L<http://cpanratings.perl.org/d/app-githooks> | ||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||
| 361 | =item * MetaCPAN | ||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||
| 363 | L<https://metacpan.org/release/App-GitHooks> | ||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||
| 365 | =back | ||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||
| 368 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||
| 370 | L<Guillaume Aubert|https://metacpan.org/author/AUBERTG>, | ||||||||||||||||||||||||||||
| 371 | C<< <aubertg at cpan.org> >>. | ||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||
| 374 | =head1 COPYRIGHT & LICENSE | ||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||
| 376 | Copyright 2013-2015 Guillaume Aubert. | ||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||
| 378 | This program is free software: you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||
| 379 | the terms of the GNU General Public License version 3 as published by the Free | ||||||||||||||||||||||||||||
| 380 | Software Foundation. | ||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||
| 382 | This program is distributed in the hope that it will be useful, but WITHOUT ANY | ||||||||||||||||||||||||||||
| 383 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A | ||||||||||||||||||||||||||||
| 384 | PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||
| 386 | You should have received a copy of the GNU General Public License along with | ||||||||||||||||||||||||||||
| 387 | this program. If not, see http://www.gnu.org/licenses/ | ||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||
| 389 | =cut | ||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||
| 392 | __DATA__ | ||||||||||||||||||||||||||||