首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Git首先运行提交任务,然后推送任务

Git首先运行提交任务,然后推送任务
EN

Stack Overflow用户
提问于 2016-05-07 22:26:18
回答 2查看 1.1K关注 0票数 5

我正在做项目,我想提交和推动git的使用,但我在运行git任务时遇到了一些问题,所以推送任务不等待提交.

任何人都可以帮我!我想让任务像第一次运行提交,然后自动推送和不运行推送任务,直到完成提交任务.

吞咽任务杯Git提交和推动!

代码语言:javascript
复制
var gulp              = require('gulp'),
    runSequence       = require('run-sequence'),
    gutil             = require('gulp-util'),
    git               = require('gulp-git'),
    prompt            = require('gulp-prompt');


/* task to commit and push all file on git
******************************************************************/
// git commit task with gulp prompt
gulp.task('gulp:commit', function(){
  // just source anything here - we just wan't to call the prompt for now
  gulp.src('./*')
  .pipe(prompt.prompt({
    type: 'input',
    name: 'commit',
    message: 'Please enter commit message...'
  }, function(res){
    // now add all files that should be committed
    // but make sure to exclude the .gitignored ones, since gulp-git tries to commit them, too
    return gulp.src([ '!node_modules/', './*' ], {buffer:false})
    .pipe(git.commit(res.commit));
   }));
});

// Run git push, remote is the remote repo, branch is the remote branch to push to
gulp.task('gulp:push', ['gulp:commit'], function(cb){
    git.push('origin', 'master', cb, function(err){
        if (err) throw err;
    });
});

// # task completed notification with green color!
gulp.task('gulp:done', ['gulp:push'], function(){
  console.log('');
  gutil.log(gutil.colors.green('************** Git push is done! **************'));
  console.log('');
});

// gulp task to commit and push data on git
gulp.task('git', function(){
  runSequence(['gulp:commit', 'gulp:push', 'gulp:done'])
});

EN

回答 2

Stack Overflow用户

发布于 2016-05-08 09:21:49

问题是,您正在告诉runSequence插件并行运行这些任务。解决方案非常简单:

代码语言:javascript
复制
// gulp task to commit and push data on git
gulp.task('git', function(){
  return runSequence('gulp:commit', 'gulp:push', 'gulp:done');
});

通过这样做,您可以确保gulp: push 只在gulp:commit完成之后运行,而在完成push之后,gulp: done 才会运行。

此外,我建议您返回 gulp :push中的流,并在gulp: done 中使用已完成的回调参数,如果不执行,则该gulp不知道这些任务何时结束:

代码语言:javascript
复制
// git commit task with gulp prompt
gulp.task('gulp:commit', function(){
  // just source anything here - we just wan't to call the prompt for now
  return gulp.src('./*')
  .pipe(prompt.prompt({
    type: 'input',
    name: 'commit',
    message: 'Please enter commit message...'
  }, function(res){
    // now add all files that should be committed
    // but make sure to exclude the .gitignored ones, since gulp-git tries to commit them, too
    return gulp.src([ '!node_modules/', './*' ], {buffer:false})
    .pipe(git.commit(res.commit));
   }));
});

// Run git push, remote is the remote repo, branch is the remote branch to push to
gulp.task('gulp:push', ['gulp:commit'], function(cb){
  return git.push('origin', 'master', cb, function(err){
    if (err) throw err;
  });
});

// # task completed notification with green color!
gulp.task('gulp:done', ['gulp:push'], function(done){
  console.log('');
  gutil.log(gutil.colors.green('************** Git push is done! **************'));
  console.log('');
  done();
});

编辑:您必须返回gulp:commit任务中的流,我更改了我的答案,向您展示了如何实现。

票数 1
EN

Stack Overflow用户

发布于 2016-08-17 00:47:18

实际上并不返回流(按设计)。见#49

为了解决这个问题,您可以使用像蓝鸟这样的允诺库。

,这是对我有用的东西,如github用户bfricka :所建议的那样

代码语言:javascript
复制
gulp.task('commit-changes', function (cb) {


    var q = require('bluebird'); //commit needs a a promise
    return new q(function (resolve, reject) {



        gulp.src('../')
                .pipe(git.add())
                .pipe(stream = git.commit("my commit message")).on('error', function (e) {
            console.log('No changes to commit');
        })

                .on('error', resolve) //resolve to allow the commit to resume even when there are not changes.
                .on('end', resolve);



        stream.resume(); //needed since commmit doesnt return stream by design.


        ;


    });

});
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37094350

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档