使用GULP-GIT一次添加,提交和推送 [英] Add, Commit and Push at Once using GULP-GIT

查看:92
本文介绍了使用GULP-GIT一次添加,提交和推送的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个在单个命令行中执行add .commitpush的任务,例如:gulp gitsend -m "My changes"

I'm trying to create a task that does add . , commit, and push in a single command line like : gulp gitsend -m "My changes"

var gulp = require('gulp');
var argv = require('yargs').argv;
var git = require('gulp-git');

gulp.task('gitsend', function() {
if (argv.m) {
    console.log('adding, commiting and pushing to git...');
    return gulp.src('.')
    .pipe(git.add())
    .pipe(git.commit(argv.m)
    .pipe(git.push('origin', 'master', function (err) {
        if (err) throw err;
    })));
}
});

但这不起作用:它引发异常:

But this is not working: it throws an exception:

/Users/me/myproj/front/node_modules/gulp-git/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:623
    var written = dest.write(chunk);
                       ^
TypeError: undefined is not a function
    at write (/Users/me/myproj/front/node_modules/gulp-git/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:623:24)
    at flow (/Users/me/myproj/front/node_modules/gulp-git/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:632:7)
    at DestroyableTransform.pipeOnReadable (/Users/me/myproj/front/node_modules/gulp-git/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:664:5)
    at DestroyableTransform.emit (events.js:104:17)
    at emitReadable_ (/Users/me/myproj/front/node_modules/gulp-git/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:448:10)
    at emitReadable (/Users/me/myproj/front/node_modules/gulp-git/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:444:5)
    at readableAddChunk (/Users/me/myproj/front/node_modules/gulp-git/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:187:9)
    at DestroyableTransform.Readable.push (/Users/me/myproj/front/node_modules/gulp-git/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:149:10)
    at DestroyableTransform.Transform.push (/Users/me/myproj/front/node_modules/gulp-git/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:145:32)
    at Array.forEach (native)

任何想法都出了什么问题,我该如何存档我的需求? 谢谢.

Any idea what's wrong and how can I archive my need ? Thank you.

推荐答案

您可以拆分单个任务(添加,提交,推送),然后使用运行顺序运行它们,以确保在推送之前先完成添加和提交

You can split the individual tasks out (add, commit, push) and then run them using run-sequence to ensure that add and commit are done first before pushing.

var gulp = require('gulp');
var argv = require('yargs').argv;
var git = require('gulp-git');
var runSequence = require('run-sequence');

gulp.task('init', function() {
  console.log(argv.m);
});

gulp.task('add', function() {
  console.log('adding...');
  return gulp.src('.')
    .pipe(git.add());
});

gulp.task('commit', function() {
  console.log('commiting');
  if (argv.m) {
    return gulp.src('.')
      .pipe(git.commit(argv.m));
  }
});

gulp.task('push', function(){
  console.log('pushing...');
  git.push('origin', 'master', function (err) {
    if (err) throw err;
  });
});

gulp.task('gitsend', function() {
  runSequence('add', 'commit', 'push');
});

这篇关于使用GULP-GIT一次添加,提交和推送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆