App-Git-Workflow
view release on metacpan or search on metacpan
bin/git-hook-setup view on Meta::CPAN
pod2usage( -verbose => 2 );
}
elsif ( $option{'help'} ) {
pod2usage( -verbose => 1 );
}
# do stuff here
my $hooks = hooks();
if ( $option{global} ) {
$option{template} ||= '/usr/share/git-core/templates/hooks';
# create path if missing? TODO Does this work with git-bash?
if ( !-d $option{template} ) {
my @parts = splitdir($option{template});
my $path = shift @parts;
while (my $part = shift @parts) {
my $subdir = catdir($path, $part);
if ( !-d $subdir ) {
mkdir $subdir or die "Can't create path $subdir! (trying to make $option{template})\n";
}
$path = $subdir;
}
}
# write the hook to the global template directory
write_hooks($option{template}, $hooks);
}
write_hooks(".git/hooks", $hooks);
return;
}
sub hooks {
local $/ = undef;
my $hook_data = <DATA>;
my @data = split /^__([^_]+)__$/xms, $hook_data;
shift @data;
return { @data };
}
sub write_hooks {
my ($dir, $hooks) = @_;
for my $hook (keys %{ $hooks } ) {
my $file = catfile($dir, $hook);
my $backup = catfile($dir, "$hook~");
my $count = 1;
while (-e $backup) {
$backup = catfile($dir, "$hook$count~");
$count++;
}
system 'cp', $file, $backup;
my $fh = $file->openw;
print {$fh} $hooks->{$hook};
close $fh;
chmod 0755, $file;
}
}
=head1 NAME
git-hook-setup - Copies hooks into their proper location
=head1 VERSION
This documentation refers to git-hook-setup version 1.1.20.
=head1 SYNOPSIS
git-hook-setup [local]
git-hook-setup global
git-hook-setup find [path]
SUB-COMMANDS:
local Install git hooks into local git repository
global Install git hooks into global git hook template directory
find Install git hooks into any git directory found under path
path - path to search (default is curent directory)
OPTIONS:
-v --verbose Show more detailed option
--version Prints the version information
--help Prints this help information
--man Prints the full documentation for git-hook-setup
=head1 DESCRIPTION
Install the git-hooks provided by the git-hooks package
=head1 SUBROUTINES/METHODS
=head1 DIAGNOSTICS
=head1 CONFIGURATION AND ENVIRONMENT
=head1 DEPENDENCIES
=head1 INCOMPATIBILITIES
=head1 BUGS AND LIMITATIONS
There are no known bugs in this module.
Please report problems to Ivan Wills (ivan.wills@gmail.com).
Patches are welcome.
=head1 AUTHOR
Ivan Wills - (ivan.wills@gmail.com)
=head1 LICENSE AND COPYRIGHT
Copyright (c) 2014 Ivan Wills (14 Mullion Close, Hornsby Heights, NSW Australia 2077).
All rights reserved.
( run in 2.549 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )