Skip to content

Commit

Permalink
Merge pull request #16 from Cheppers/move-hooks
Browse files Browse the repository at this point in the history
Move hooks
  • Loading branch information
Sweetchuck authored Jul 7, 2016
2 parents b21bc33 + 6316146 commit 9f30dfd
Show file tree
Hide file tree
Showing 43 changed files with 200 additions and 546 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
/release/
/vendor/

/cheppers-git-hooks-robo-*.tar
/cheppers-git-hooks-robo-*.zip
/cheppers-git-hooks-*.tar
/cheppers-git-hooks-*.zip
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@

# Trigger Robo tasks from Git hooks
# Trigger custom scripts from Git hooks

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

[![Build Status](https://travis-ci.org/Cheppers/git-hooks-robo.svg?branch=master)](https://travis-ci.org/Cheppers/git-hooks-robo)
[![Total Downloads](https://poser.pugx.org/cheppers/git-hooks-robo/downloads.png)](https://packagist.org/packages/cheppers/git-hooks-robo)
[![Build Status](https://travis-ci.org/Cheppers/git-hooks.svg?branch=master)](https://travis-ci.org/Cheppers/git-hooks)
[![Total Downloads](https://poser.pugx.org/cheppers/git-hooks/downloads.png)](https://packagist.org/packages/cheppers/git-hooks)


## When to use
Expand Down Expand Up @@ -43,16 +43,16 @@ teammates then this is the tool you are looking for.
{
"type": "package",
"package": {
"name": "cheppers/git-hooks-robo",
"name": "cheppers/git-hooks",
"version": "0.0.5",
"type": "git-hook",
"dist": {
"type": "tar",
"url": "https://github.com/Cheppers/git-hooks-robo/releases/download/v0.0.5/v0.0.5.tar.gz"
"url": "https://github.com/Cheppers/git-hooks/releases/download/v0.0.5/v0.0.5.tar.gz"
},
"source": {
"type": "git",
"url": "https://github.com/Cheppers/git-hooks-robo.git",
"url": "https://github.com/Cheppers/git-hooks.git",
"reference": "v0.0.5"
}
}
Expand Down
49 changes: 21 additions & 28 deletions RoboFile.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* @file
* Robo task definitions for cheppers/git-hooks-robo.
* Robo task definitions for cheppers/git-hooks.
*/

use Robo\Tasks;
Expand Down Expand Up @@ -41,6 +41,7 @@ class RoboFile extends Tasks
* @var string[]
*/
protected $filesToDeploy = [
'_common' => ['base_mask' => 0666],
'applypatch-msg' => ['base_mask' => 0777],
'commit-msg' => ['base_mask' => 0777],
'post-applypatch' => ['base_mask' => 0777],
Expand Down Expand Up @@ -91,41 +92,33 @@ public function releaseCreate($version)
/** @var \Robo\Collection\Collection $collection */
$collection = $this->collection();

$collection->add($this
->taskFilesystemStack()
->remove('release'));
$name = "{$this->packageVendor}-{$this->packageName}-{$version}";

$cmd = sprintf(
'composer archive --format=%s --dir=%s --file=%s',
escapeshellarg('zip'),
escapeshellarg('release'),
escapeshellarg("v{$version}")
);
$collection->add($this->taskExec($cmd));
$fs_stack = $this->taskFilesystemStack();
$collection->add($fs_stack);

$collection->add($this
->taskExtract("release/v{$version}.zip")
->to("release/{$this->packageName}-{$version}"));
$fs_stack
->remove("release/$name")
->remove("release/$name.tar.gz");

$collection->add($this
->taskFilesystemStack()
->remove("release/v{$version}.zip"));

$fs_stack_chmod = $this->taskFilesystemStack();
foreach ($this->filesToDeploy as $file_name => $file_meta) {
$fs_stack_chmod->chmod(
"release/{$this->packageName}-{$version}/$file_name",
$fs_stack->copy(
"hooks/$file_name",
"release/$name/$file_name"
);

$fs_stack->chmod(
"release/$name/$file_name",
$file_meta['base_mask'],
0022
);
}
$collection->add($fs_stack_chmod);

foreach (['tar.gz', 'zip'] as $extension) {
$collection->add($this
->taskPack("release/{$this->packageVendor}-{$this->packageName}-{$version}.$extension")
->addDir("{$this->packageName}-{$version}", "release/{$this->packageName}-{$version}"));
}
$collection->add(
$this
->taskPack("release/$name.tar.gz")
->addDir($name, "release/$name")
);

$collection->run();
}
Expand Down Expand Up @@ -243,7 +236,7 @@ protected function getTaskDeployGitHooks()
$git_dir = preg_replace('@^' . preg_quote("$current_dir/", '@') . '@', './', $git_dir);
foreach ($this->filesToDeploy as $file_name => $file_meta) {
$dst = "$git_dir/hooks/$file_name";
$fsStack->copy($file_name, $dst);
$fsStack->copy("hooks/$file_name", $dst);
$fsStack->chmod($dst, $file_meta['base_mask'], umask());
}

Expand Down
25 changes: 0 additions & 25 deletions applypatch-msg

This file was deleted.

26 changes: 0 additions & 26 deletions commit-msg

This file was deleted.

37 changes: 19 additions & 18 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,26 @@
"exclude": [
"/*",
"/.*",
"!/hooks/_common",
"!/hooks/applypatch-msg",
"!/hooks/commit-msg",
"!/hooks/post-applypatch",
"!/hooks/post-checkout",
"!/hooks/post-commit",
"!/hooks/post-merge",
"!/hooks/post-receive",
"!/hooks/post-rewrite",
"!/hooks/post-update",
"!/hooks/pre-applypatch",
"!/hooks/pre-auto-gc",
"!/hooks/pre-commit",
"!/hooks/pre-push",
"!/hooks/pre-rebase",
"!/hooks/pre-receive",
"!/hooks/prepare-commit-msg",
"!/hooks/push-to-checkout",
"!/hooks/update",
"!/composer.json",
"!/applypatch-msg",
"!/commit-msg",
"!/post-applypatch",
"!/post-checkout",
"!/post-commit",
"!/post-merge",
"!/post-receive",
"!/post-rewrite",
"!/post-update",
"!/pre-applypatch",
"!/pre-auto-gc",
"!/pre-commit",
"!/pre-push",
"!/pre-rebase",
"!/pre-receive",
"!/prepare-commit-msg",
"!/push-to-checkout",
"!/update",
"!/README.md"
]
},
Expand Down
45 changes: 23 additions & 22 deletions features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,24 +51,25 @@ class FeatureContext extends \PHPUnit_Framework_Assert implements Context
* @var string[]
*/
protected static $gitHooks = [
'applypatch-msg' => 0777,
'commit-msg' => 0777,
'post-applypatch' => 0777,
'post-checkout' => 0777,
'post-commit' => 0777,
'post-merge' => 0777,
'post-receive' => 0666,
'post-rewrite' => 0666,
'post-update' => 0777,
'pre-applypatch' => 0777,
'pre-auto-gc' => 0777,
'pre-commit' => 0777,
'pre-push' => 0777,
'pre-rebase' => 0777,
'pre-receive' => 0666,
'prepare-commit-msg' => 0777,
'push-to-checkout' => 0777,
'update' => 0777,
'_common' => ['base_mask' => 0666],
'applypatch-msg' => ['base_mask' => 0777],
'commit-msg' => ['base_mask' => 0777],
'post-applypatch' => ['base_mask' => 0777],
'post-checkout' => ['base_mask' => 0777],
'post-commit' => ['base_mask' => 0777],
'post-merge' => ['base_mask' => 0777],
'post-receive' => ['base_mask' => 0666],
'post-rewrite' => ['base_mask' => 0666],
'post-update' => ['base_mask' => 0777],
'pre-applypatch' => ['base_mask' => 0777],
'pre-auto-gc' => ['base_mask' => 0777],
'pre-commit' => ['base_mask' => 0777],
'pre-push' => ['base_mask' => 0777],
'pre-rebase' => ['base_mask' => 0777],
'pre-receive' => ['base_mask' => 0666],
'prepare-commit-msg' => ['base_mask' => 0777],
'push-to-checkout' => ['base_mask' => 0777],
'update' => ['base_mask' => 0777],
];

/**
Expand Down Expand Up @@ -119,11 +120,11 @@ protected static function initGitTemplate()
static::$fs->mkdir($dir);

$mask = umask();
foreach (static::$gitHooks as $file => $mode) {
$src = static::$projectRootDir . "/$file";
$dst = "$git_template_dir/hooks/$file";
foreach (static::$gitHooks as $file_name => $info) {
$src = static::$projectRootDir . "/hooks/$file_name";
$dst = "$git_template_dir/hooks/$file_name";
static::$fs->copy($src, $dst, true);
static::$fs->chmod($dst, $mode, $mask);
static::$fs->chmod($dst, $info['base_mask'], $mask);
}
}

Expand Down
4 changes: 2 additions & 2 deletions fixtures/git-template/config
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

[user]
name = git-hooks-robo
email = git-hooks-robo@example.com
name = git-hooks
email = [email protected]
4 changes: 2 additions & 2 deletions fixtures/project-template/basic/composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cheppers/git-hooks-robo-helper",
"description": "Helper project for cheppers/git-hooks-robo",
"name": "cheppers/git-hooks-helper",
"description": "Helper project for cheppers/git-hooks",
"license": "proprietary",
"minimum-stability": "dev",
"prefer-stable": true,
Expand Down
8 changes: 0 additions & 8 deletions pre-auto-gc → hooks/_common
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
#!/usr/bin/env bash
##
# The hook is called with the following parameters:
# No parameters.
#
# Standard input format:
# NULL
##

hasInput='true'
if [ "$(git rev-parse --is-bare-repository)" = 'true' ]; then
gitHooksBridge='./.git-hooks'
else
Expand Down
7 changes: 7 additions & 0 deletions hooks/applypatch-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash
##
# @see https://git-scm.com/docs/githooks#_applypatch_msg
##

hasInput='true'
. "$(dirname $0)/_common"
7 changes: 7 additions & 0 deletions hooks/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash
##
# @see https://git-scm.com/docs/githooks#_commit_msg
##

hasInput='true'
. "$(dirname $0)/_common"
7 changes: 7 additions & 0 deletions hooks/post-applypatch
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash
##
# @see https://git-scm.com/docs/githooks#_post_applypatch
##

hasInput='true'
. "$(dirname $0)/_common"
7 changes: 7 additions & 0 deletions hooks/post-checkout
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash
##
# @see https://git-scm.com/docs/githooks#_post_checkout
##

hasInput='true'
. "$(dirname $0)/_common"
7 changes: 7 additions & 0 deletions hooks/post-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash
##
# @see https://git-scm.com/docs/githooks#_post_commit
##

hasInput='true'
. "$(dirname $0)/_common"
7 changes: 7 additions & 0 deletions hooks/post-merge
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash
##
# @see https://git-scm.com/docs/githooks#_post_merge
##

hasInput='true'
. "$(dirname $0)/_common"
7 changes: 7 additions & 0 deletions hooks/post-receive
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash
##
# @see https://git-scm.com/docs/githooks#post-receive
##

hasInput='true'
. "$(dirname $0)/_common"
7 changes: 7 additions & 0 deletions hooks/post-rewrite
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash
##
# @see https://git-scm.com/docs/githooks#_post_rewrite
##

hasInput='true'
. "$(dirname $0)/_common"
7 changes: 7 additions & 0 deletions hooks/post-update
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash
##
# @see https://git-scm.com/docs/githooks#post-update
##

hasInput='true'
. "$(dirname $0)/_common"
7 changes: 7 additions & 0 deletions hooks/pre-applypatch
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash
##
# @see https://git-scm.com/docs/githooks#_pre_applypatch
##

hasInput='true'
. "$(dirname $0)/_common"
Loading

0 comments on commit 9f30dfd

Please sign in to comment.