我正在做项目,我想提交和推动git的使用,但我在运行git任务时遇到了一些问题,所以推送任务不等待提交.
任何人都可以帮我!我想让任务像第一次运行提交,然后自动推送和不运行推送任务,直到完成提交任务.
吞咽任务杯Git提交和推动!
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'])
});
发布于 2016-05-08 09:21:49
问题是,您正在告诉runSequence插件并行运行这些任务。解决方案非常简单:
// 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不知道这些任务何时结束:
// 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任务中的流,我更改了我的答案,向您展示了如何实现。
发布于 2016-08-17 00:47:18
实际上并不返回流(按设计)。见#49。
为了解决这个问题,您可以使用像蓝鸟这样的允诺库。
,这是对我有用的东西,如github用户bfricka :所建议的那样
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.
;
});
});https://stackoverflow.com/questions/37094350
复制相似问题