public static function installGitMessageHook(Event $event)
    {
        $hookContent = self::HOOK_CONTENTS;
        $inputOutput = $event->getIO();
        $question = 'Do you want to install and activate the Git ';
        $question .= 'commit message hook? ';

        if ($inputOutput->askConfirmation($question, false)) {
            $errorMessage = "Couldn't locate the .git directory. ";
            $errorMessage .= 'Aborting the Git hook installation.';

            $gitDirectory = self::getGuardedGitDirectory($errorMessage, $inputOutput);

            if (false === $gitDirectory) {
                return false;
            }

            $hookFile = implode(DIRECTORY_SEPARATOR, [$gitDirectory, self::HOOKS_PATH, self::HOOK_FILENAME]);
            $existingHookFile = false;

            if (file_exists($hookFile)) {
                $existingHookFile = copy(
                    $hookFile,
                    $hookFile.self::BACKUP_EXTENSION
                );
            }

            file_put_contents($hookFile, $hookContent);
            chmod($hookFile, self::EXECUTABLE_PERMISSIONS);

            $inputOutput->write('Installed and activated the Git commit message hook.');

            if ($existingHookFile) {
                $inputOutput->write('Backed previous Git commit message hook.');
            }

            if ($inputOutput->isVerbose()) {
                $inputOutput->write('Wrote');
                $inputOutput->write("<comment>$hookContent</comment>");
                $inputOutput->write("into <info>$hookFile</info> and made it executable.");
            }

            return true;
        }

        $inputOutput->write('Aborted installation and activation of the Git commit message hook.');

        return false;
    }
public static function installGitMessageHook(Event $event)
    {
        $hookContent = self::HOOK_CONTENTS;
        $inputOutput = $event->getIO();
        $question = 'Do you want to install and activate the Git ';
        $question .= 'commit message hook? ';

        if ($inputOutput->askConfirmation($question, false)) {
            $errorMessage = "Couldn't locate the .git directory. ";
            $errorMessage .= 'Aborting the Git hook installation.';

            $gitDirectory = self::getGuardedGitDirectory($errorMessage, $inputOutput);

            if (false === $gitDirectory) {
                return false;
            }

            $hookFile = implode(DIRECTORY_SEPARATOR, [$gitDirectory, self::HOOKS_PATH, self::HOOK_FILENAME]);
            $existingHookFile = false;

            if (file_exists($hookFile)) {
                $existingHookFile = copy(
                    $hookFile,
                    $hookFile.self::BACKUP_EXTENSION
                );
            }

            file_put_contents($hookFile, $hookContent);
            chmod($hookFile, self::EXECUTABLE_PERMISSIONS);

            $inputOutput->write('Installed and activated the Git commit message hook.');

            if ($existingHookFile) {
                $inputOutput->write('Backed previous Git commit message hook.');
            }

            if ($inputOutput->isVerbose()) {
                $inputOutput->write('Wrote');
                $inputOutput->write("<comment>$hookContent</comment>");
                $inputOutput->write("into <info>$hookFile</info> and made it executable.");
            }

            return true;
        }

        $inputOutput->write('Aborted installation and activation of the Git commit message hook.');

        return false;
    }
public static function installGitMessageHook ( Event $ event ) { $ hookContent = self :: HOOK_CONTENTS ; $ inputOutput = $ event -> getIO ( ) ; $ question = 'Do you want to install and activate the Git ' ; $ question .= 'commit message hook? ' ; if ( $ inputOutput -> askConfirmation ( $ question , false ) ) { $ errorMessage = "Couldn't locate the .git directory. " ; $ errorMessage .= 'Aborting the Git hook installation.' ; $ gitDirectory = self :: getGuardedGitDirectory ( $ errorMessage , $ inputOutput ) ; if ( false === $ gitDirectory ) { return false ; } $ hookFile = implode ( DIRECTORY_SEPARATOR , [ $ gitDirectory , self :: HOOKS_PATH , self :: HOOK_FILENAME ] ) ; $ existingHookFile = false ; if ( file_exists ( $ hookFile ) ) { $ existingHookFile = copy ( $ hookFile , $ hookFile . self :: BACKUP_EXTENSION ) ; } file_put_contents ( $ hookFile , $ hookContent ) ; chmod ( $ hookFile , self :: EXECUTABLE_PERMISSIONS ) ; $ inputOutput -> write ( 'Installed and activated the Git commit message hook.' ) ; if ( $ existingHookFile ) { $ inputOutput -> write ( 'Backed previous Git commit message hook.' ) ; } if ( $ inputOutput -> isVerbose ( ) ) { $ inputOutput -> write ( 'Wrote' ) ; $ inputOutput -> write ( "<comment>$hookContent</comment>" ) ; $ inputOutput -> write ( "into <info>$hookFile</info> and made it executable." ) ; } return true ; } $ inputOutput -> write ( 'Aborted installation and activation of the Git commit message hook.' ) ; return false ; }
Installs and activates the Git commit message
hook when confirmed by the user. An existing hook
is backed with the .bak extension.

@param Event $event The script event

@return bool
Installs and activates the Git commit message hook when confirmed by the user . An existing hook is backed with the . bak extension .