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;