gpt4 book ai didi

git - 使用 GULP-GIT 一次添加、提交和推送

转载 作者:行者123 更新时间:2023-12-01 22:25:07 25 4
gpt4 key购买 nike

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

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;
})));
}
});

但这不起作用:它抛出异常:

/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)

知道出了什么问题吗?我该如何归档我的需求?谢谢。

最佳答案

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

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');
});

关于git - 使用 GULP-GIT 一次添加、提交和推送,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36188219/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com