2017 © Pedro Peláez
 

library git-hooks

Provide a bridge between Git hooks and scripts under VCS.

image

cheppers/git-hooks

Provide a bridge between Git hooks and scripts under VCS.

  • Sunday, January 8, 2017
  • by Sweetchuck
  • Repository
  • 4 Watchers
  • 0 Stars
  • 6,097 Installations
  • PHP
  • 17 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 11 Versions
  • 0 % Grown

The README.md

sweetchuck/git-hooks

Triggers custom scripts from Git hooks., (*1)

This package provides a bridge between the un-versioned ./.git/hooks/* scripts and scripts in your Git repository., (*2)

CircleCI, (*3)

When to use

If you want to put your Git hook scripts under VCS to share them with your teammates then this is the tool you are looking for., (*4)

How to use

  1. Step into you existing package's directory (or create a new one with git init && composer init)
  2. Run composer require --dev 'sweetchuck/git-hooks'
  3. Then you have two option
    1. Rely on Git hook scripts which are shipped with this package and implement the logic in your ./.git-hooks file.
    2. Or create a ./git-hooks directory and create Git hook files in it. (eg: ./git-hooks/pre-commit)
  4. The deployment script will be automatically triggered by the post-install-cmd Composer event.

Configuration

Example composer.json file:, (*5)

{
    "extra": {
        "sweetchuck/git-hooks": {
            "core.hooksPath": "./git-hooks",
            "symlink": true
        }
    }
}

Configuration - core.hooksPath

Type: string, (*6)

Default value: vendor/sweetchuck/git-hooks/git-hooks (dynamically detected), (*7)

If the Git version is >= v2.9 then this value will be used to set git config core.hooksPath <PATH>. If Git is older than 2.9 then the content of this directory will be symbolically linked or copied to ./.git/hooks directory., (*8)

Type: boolean, (*9)

Default value: false, (*10)

This configuration option will be used only if Git version is older than v2.9. Copy or symlink Git hook files from the original location (provided by the core.hooksPath configuration) to the ./.git/hooks., (*11)

Example ./.git-hooks file

If you use the Git hooks script from this package (vendor/sweetchuck/git-hooks/git-hooks) you will need custom script which catches Git hooks add triggers something really useful., (*12)

Copy the content below into ./.git-hooks, (*13)

#!/usr/bin/env bash

echo "BEGIN Git hook: ${sghHookName}"

function sghExit ()
{
    echo "END   Git hook: ${sghHookName}"

    exit $1
}

# @todo Better detection for executables: php, composer.phar.
sghRobo="$(composer config 'bin-dir')/robo"

test -s "${sghBridge}.local" && . "${sghBridge}.local"

sghTask="githook:${sghHookName}"

# Exit without error if "robo" doesn't exists or it has no corresponding task.
test -x "$sghRobo" || sghExit 0
"${sghRobo}" help "${sghTask}" 1> /dev/null 2>&1 || sghExit 0

if [ "$sghHasInput" = 'true' ]; then
    "$sghRobo" "${sghTask}" $@ <<< $(</dev/stdin) || sghExit $?
else
    "$sghRobo" "${sghTask}" $@ || sghExit $?
fi

sghExit 0

Example ./RoboFile.php

<?php

/**
 * Git hook tasks have to be started with 'githook' prefix.
 * So the method name format is: githook<GitHookNameInCamelCaseFormat>
 * Or use the @command annotation.
 */
class RoboFile extends \Robo\Tasks
{

    /**
     * Demo pre-commit callback.
     *
     * @command githook:pre-commit
     */
    public function githookPreCommit()
    {
        $this->say('The Git pre-commit hook is running');
    }
}

The Versions

08/01 2017
09/07 2016

dev-core-hooks-path

dev-core-hooks-path

Provide a bridge between Git hooks and scripts under VCS.

  Sources   Download

GPL-2.0

The Development Requires

07/06 2016

v0.0.3

0.0.3.0

Provide a bridge between Git hooks and Robo tasks.

  Sources   Download

GPL-2.0

The Development Requires

01/06 2016

v0.0.2

0.0.2.0

Provide a bridge between Git hooks and Robo tasks.

  Sources   Download

GPL-2.0

The Development Requires

28/05 2016

v0.0.1

0.0.1.0

Provide a bridge between Git hooks and Robo tasks.

  Sources   Download

GPL-2.0