App-Git-Workflow

 view release on metacpan or  search on metacpan

bin/git-hook-setup  view on Meta::CPAN

    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.

This module is free software; you can redistribute it and/or modify it under
the same terms as Perl itself. See L<perlartistic>.  This program is
distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.

=cut

__DATA__
__pre-commit__
#!/bin/sh

if git rev-parse --verify HEAD >/dev/null 2>&1
then
    against=HEAD
else
    # Initial commit: diff against an empty tree object
    against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
fi

# If you want to allow non-ascii filenames set this variable to true.
allownonascii=$(git config hooks.allownonascii)

# Cross platform projects tend to avoid non-ascii filenames; prevent
# them from being added to the repository. We exploit the fact that the
# printable range starts at the space character and ends with tilde.
if [ "$allownonascii" != "true" ] &&
    # Note that the use of brackets around a tr range is ok here, (it's
    # even required, for portability to Solaris 10's /usr/bin/tr), since
    # the square bracket bytes happen to fall in the designated range.
    test "$(git diff --cached --name-only --diff-filter=A -z $against |
      LC_ALL=C tr -d '[ -~]\0')"
then
    echo "Error: Attempt to add a non-ascii file name."
    echo
    echo "This can cause problems if you want to work"
    echo "with people on other platforms."
    echo
    echo "To be portable it is advisable to rename the file ..."
    echo
    echo "If you know what you are doing you can disable this"
    echo "check using:"
    echo
    echo "  git config hooks.allownonascii true"



( run in 1.561 second using v1.01-cache-2.11-cpan-39bf76dae61 )