From b9655efa44459e4e34bbed2efffc4212a072f5c0 Mon Sep 17 00:00:00 2001 From: Mikhail Emelchenkov Date: Mon, 30 Mar 2015 01:10:10 +0300 Subject: [PATCH] Added 'quiet' option --- README.md | 6 ++++++ tasks/git_deploy.js | 23 ++++++++++++++++++++--- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 2548215..1b8b385 100644 --- a/README.md +++ b/README.md @@ -56,5 +56,11 @@ Default value: `'autocommit'` Commit message. +#### options.quiet +Type: `Boolean` +Default value: `true` + +Suppress git console output, including output from remote server when pushing. + ## Contributing If you can think of a way to unit test this plugin please take a shot at it. diff --git a/tasks/git_deploy.js b/tasks/git_deploy.js index a8a3727..7954bb1 100644 --- a/tasks/git_deploy.js +++ b/tasks/git_deploy.js @@ -18,7 +18,8 @@ module.exports = function(grunt) { // Merge task options with these defaults. var options = this.options({ message: 'autocommit', - branch: 'gh-pages' + branch: 'gh-pages', + quiet: true }); if (!options.url) { @@ -36,11 +37,22 @@ module.exports = function(grunt) { function git(args) { return function(cb) { grunt.log.writeln('Running ' + args.join(' ').green); - spawn({ + git = spawn({ cmd: 'git', args: args, opts: {cwd: src} }, cb); + + if (!options.quiet) { + // Log git output to console + git.stdout.on('data', function (data) { + process.stdout.write(data); + }); + + git.stderr.on('data', function (data) { + process.stderr.write(data); + }); + } }; } @@ -48,12 +60,17 @@ module.exports = function(grunt) { var done = this.async(); + var push_args = ['push', '--prune', '--force']; + if (options.quiet) + push_args.push('--quiet'); + push_args.push(options.url, options.branch); + grunt.util.async.series([ git(['init']), git(['checkout', '--orphan', options.branch]), git(['add', '--all']), git(['commit', '--message="' + options.message + '"']), - git(['push', '--prune', '--force', '--quiet', options.url, options.branch]) + git(push_args) ], done); });