ADD: added command to add post commit hook

AGIM-f284da79: #closed
This commit is contained in:
Dominik Meyer 2018-09-16 00:21:37 +02:00
parent aefed27597
commit e475f7d8fb
No known key found for this signature in database
GPG Key ID: B4C312B600606B64
1 changed files with 35 additions and 0 deletions

View File

@ -0,0 +1,35 @@
package App::Git::IssueManager::AddHook;
#ABSTRACT: class implementing the Add-Hook command of the GIT IssueManager
use strict;
use warnings;
use MooseX::App::Command;
extends qw(App::Git::IssueManager);
use Git::LowLevel;
use Git::IssueManager;
use Git::IssueManager::Issue;
use Term::ANSIColor;
use Try::Tiny;
command_short_description 'add the post-commit hook for managing git issues to the repository';
command_usage 'git issue add-hook';
sub run
{
my $self = shift;
die("No .git directory found\n") unless -d ".git";
die("A post-commit hook is already installed. Please add hook manually\n") unless ! -e ".git/hooks/post-commit";
open my $hook,">",".git/hooks/post-commit";
print $hook "#!/bin/sh\n";
print $hook "git-issue-commit-hook\n";
close $hook;
system("chmod a+x .git/hooks/post-commit");
}
1;