From e475f7d8fb940a32e4a7119baceb2d5e3e28831f Mon Sep 17 00:00:00 2001 From: Dominik Meyer Date: Sun, 16 Sep 2018 00:21:37 +0200 Subject: [PATCH] ADD: added command to add post commit hook AGIM-f284da79: #closed --- lib/App/Git/IssueManager/AddHook.pm | 35 +++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 lib/App/Git/IssueManager/AddHook.pm diff --git a/lib/App/Git/IssueManager/AddHook.pm b/lib/App/Git/IssueManager/AddHook.pm new file mode 100644 index 0000000..22df4f8 --- /dev/null +++ b/lib/App/Git/IssueManager/AddHook.pm @@ -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;