diff --git a/Gruntfile.js b/Gruntfile.js index dfff03d..f5d64a9 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -105,6 +105,14 @@ module.exports = function(grunt) { message: 'second deploy' }, src: 'tmp/src' + }, + null_deploy: { + options: { + url: '../repo', + tag: 'null', + message: 'null deploy, should not work' + }, + src: 'tmp/src' } }, @@ -125,7 +133,7 @@ module.exports = function(grunt) { // Whenever the "test" task is run, first clean the "tmp" dir, then run this // plugin's task(s), then test the result. - grunt.registerTask('test', ['clean', 'init_repo', 'copy:first', 'git_deploy:first', 'clean:deploy', 'clean:test_build', 'copy:second', 'git_deploy:second', 'nodeunit']); + grunt.registerTask('test', ['clean', 'init_repo', 'copy:first', 'git_deploy:first', 'clean:deploy', 'clean:test_build', 'copy:second', 'git_deploy:second', 'clean:deploy', 'clean:test_build', 'copy:second', 'git_deploy:null_deploy', 'nodeunit']); // By default, run all tests. grunt.registerTask('default', ['test']); diff --git a/tasks/git_deploy.js b/tasks/git_deploy.js index f8a400f..dda1d23 100644 --- a/tasks/git_deploy.js +++ b/tasks/git_deploy.js @@ -97,21 +97,45 @@ module.exports = function(grunt) { var done = this.async(); + // stage files for checkin + var commands = [ git(['clone', '-b', options.branch, options.url, '.' ]), git(['checkout', '-B', options.branch]), - copyIntoRepo( src, deployDir ), - git(['add', '--all']), - git(['commit', '--message=' + options.message ]) + copyIntoRepo( src, deployDir ) ]; - if ( options.tag ) { - commands.push( git(['tag', '-a', options.tag, '-m', options.tagMessage]) ); - } - - commands.push( git(['push', '--prune', '--force', '--quiet', '--follow-tags', options.url, options.branch]) ); + grunt.util.async.series(commands, function() { + spawn({ // determine if any files need to be checked in + cmd: 'git', + args: ['status'], + opts: {cwd: deployDir} + }, function(error, result, code) { + if(code == 0) { + if(result.stdout.indexOf('nothing to commit, working directory clean') < 0) { // files need to be checked in + commands = [ + git(['add', '--all']), + git(['commit', '--message=' + options.message ]) + ]; + + if ( options.tag ) { + commands.push( git(['tag', '-a', options.tag, '-m', options.tagMessage]) ); + } + + commands.push( git(['push', '--prune', '--force', '--quiet', '--follow-tags', options.url, options.branch]) ); + + grunt.util.async.series(commands, done); + } else { // files do not need to be checked in + grunt.log.writeln('Nothing for git_deploy to commit.'); + done(); + } + } else { + grunt.fail.warn('Error running "git status":' + result.stderr); + done(); + } + }); + }); - grunt.util.async.series(commands, done); }); };