Last active
August 29, 2015 13:57
-
-
Save yocontra/9538591 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var through = require('through2'); | |
var gutil = require('gulp-util'); | |
var exec = require('child_process').exec; | |
var escape = require('any-shell-escape'); | |
module.exports = function (message, opt) { | |
if(!opt) opt = {}; | |
if(!message) throw new Error('gulp-git: Commit message is required git.commit("commit message")'); | |
if(!opt.args) opt.args = ' '; | |
var files = []; | |
var defaultCwd = process.cwd(); | |
var write = function(file, enc, cb){ | |
files.push(file); | |
cb(); | |
}; | |
var flush = function(cb){ | |
// if we got files pick the cwd off the first one, otherwise just use process.cwd | |
var fileCwd = (files.length > 0 ? files[0].cwd : defaultCwd); | |
// if we got cwd as an option prefer that over fileCwd | |
var cwd = opt.cwd || fileCwd; | |
var cmd = 'git commit -m "' + message + '" ' + escape(files) + ' ' + opt.args; | |
exec(cmd, {cwd: cwd}, function(err, stdout, stderr){ | |
if(err) return cb(err); | |
gutil.log(stdout, stderr); | |
// emit all buffered files | |
files.forEach(this.push.bind(this)); | |
cb(); | |
}); | |
}; | |
var stream = through.obj(write, flush); | |
return stream; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment