Skip to content

Commit

Permalink
Updated push.js, default branch to push will be current branch with t…
Browse files Browse the repository at this point in the history
…his fix (#163)

* Default push to current branch

* Default push to current branch

* git push to current branch (no secondary argument)

* fix: space-before-blocks

* git push current branch by default - handled arguments
  • Loading branch information
masoomulhaqs authored and stephenlacy committed Jun 1, 2017
1 parent 8e4ecd9 commit 2aeb295
Showing 2 changed files with 53 additions and 18 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -136,6 +136,14 @@ gulp.task('push', function(){
});
});

// Run git push
// branch is the current branch & remote branch to push to
gulp.task('push', function(){
git.push('origin', function (err) {
if (err) throw err;
});
});

// Run git push with options
// branch is the remote branch to push to
gulp.task('push', function(){
63 changes: 45 additions & 18 deletions lib/push.js
Original file line number Diff line number Diff line change
@@ -3,30 +3,57 @@
var gutil = require('gulp-util');
var exec = require('child_process').exec;
var escape = require('any-shell-escape');
var revParse = require('./revParse');

module.exports = function (remote, branch, opt, cb) {

if (!remote) remote = 'origin';
if (branch === null) {
branch = '';
} else if (!branch) {
branch = 'master';

function setBranch(cb2) {
if (branch && typeof branch === 'function') {
cb = branch;
branch = null;
}
if (branch && Object.prototype.toString.call(branch) === '[object Object]') {
opt = branch;
branch = null;
}
if (!branch) {
revParse({ args: '--abbrev-ref HEAD' },
function callback(err, out) {
if (err) return cb2(err);
branch = out;
cb2();
});
} else {
cb2();
}
}
if (!cb && typeof opt === 'function') {
cb = opt;
opt = {};

function flush(err) {
if (err) return cb(err);
if (!cb && typeof opt === 'function') {
cb = opt;
opt = {};
}
if (!cb || typeof cb !== 'function') cb = function() {};
if (!opt) opt = {};
if (!opt.cwd) opt.cwd = process.cwd();
if (!opt.args) opt.args = ' ';

var cmd = 'git push ' + escape([].concat(remote, branch)) + ' ' + opt.args;
var maxBuffer = opt.maxBuffer || 200 * 1024;

return exec(cmd, {
cwd: opt.cwd,
maxBuffer: maxBuffer
}, function(err, stdout, stderr) {
if (err) return cb(err);
if (!opt.quiet) gutil.log(stdout, stderr);
cb();
});
}
if (!cb || typeof cb !== 'function') cb = function () {};
if (!opt) opt = {};
if (!opt.cwd) opt.cwd = process.cwd();
if (!opt.args) opt.args = ' ';

var cmd = 'git push ' + escape([].concat(remote, branch)) + ' ' + opt.args;
var maxBuffer = opt.maxBuffer || 200 * 1024;
return setBranch(flush);

return exec(cmd, {cwd: opt.cwd, maxBuffer: maxBuffer}, function(err, stdout, stderr) {
if (err) return cb(err);
if (!opt.quiet) gutil.log(stdout, stderr);
cb();
});
};

0 comments on commit 2aeb295

Please sign in to comment.