1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | 23 23 23 23 23 1 9 1 1 1 1 1 1 1 23 1 2 6 1 23 23 2 21 23 | 'use strict'; var _ = require('lodash'); var execSync = require('shelljs').exec; var stripBom = require('strip-bom'); var map = require('map-stream'); var hookArgs = process.env.HOOK_ARGS ? process.env.HOOK_ARGS.split('\u263a') : []; function getIndexed() { return _.compact(execSync('git diff --cached --name-only --diff-filter=ACM', { silent: true }).output.split('\n')); } function streamFromIndexed(gulp) { return gulp.src(getIndexed()) .pipe(map(function (file, cb) { var hash = execSync('git ls-files -s ' + file.path, { silent: true }).output.split(' ')[1]; Iif (!hash || !hash.length) { // untracked file, use working copy return void cb(null, file); } var contents = execSync('git cat-file blob ' + hash, { silent: true }).output; file.contents = new Buffer(stripBom(contents)); cb(null, file); })); } var hooks = [ { name: 'applypatch-msg', src: hookArgs[0], stream: function (gulp) { return gulp.src(this.src); } }, { name: 'commit-msg', src: hookArgs[0], stream: function (gulp) { return gulp.src(this.src); } }, { name: 'post-applypatch' }, { name: 'post-checkout', extra: hookArgs }, { name: 'post-commit' }, { name: 'post-merge', extra: hookArgs[0] }, { // streamable(stdio) name: 'post-receive' }, { // streamable(stdio) name: 'post-rewrite', extra: hookArgs }, { name: 'post-update', extra: hookArgs }, { name: 'pre-applypatch', get src () { return getIndexed(); }, stream: streamFromIndexed }, { name: 'pre-auto-gc' }, { name: 'pre-commit', get src () { return getIndexed(); }, stream: streamFromIndexed }, { // streamable(stdio) name: 'pre-push', extra: hookArgs }, { // streamable(stdio) name: 'pre-receive' }, { name: 'pre-rebase', extra: hookArgs }, { name: 'prepare-commit-msg', src: hookArgs[0], extra: hookArgs.slice(1), stream: function (gulp) { return gulp.src(this.src); } }, { name: 'update', extra: hookArgs } ]; function getHookObj(name) { var hook = _.findWhere(hooks, { name: name }); if (!hook) { throw new Error('Invalid hook name: ' + name); } return _.defaults(hook, { src: null }); } module.exports = getHookObj; |