首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >尝试实现gulp git和gulp提示,以允许自定义提交消息。

尝试实现gulp git和gulp提示,以允许自定义提交消息。
EN

Stack Overflow用户
提问于 2015-04-10 19:06:15
回答 1查看 1.6K关注 0票数 1

当我试图用gulp提示符实现git时,我得到了一些错误。我试图让用户在输入命令时输入自己唯一的git提交消息。应该在用户输入gulp命令之后显示消息。

这是gulp命令

代码语言:javascript
复制
//git commit task with gulp prompt
gulp.task('commit', function(){
    var message;
    gulp.src('./*', {buffer:false})
    .pipe(prompt.prompt({
        type: 'input',
        name: 'commit',
        message: 'Please enter commit message...'
    },  function(res){
        message = res.commit;
    }))
    .pipe(git.commit(message));
});

目前,在将命令输入终端后,我将得到以下错误。

代码语言:javascript
复制
TypeError: Cannot call method 'indexOf' of undefined
  at Object.module.exports [as commit] (/Users/me/Desktop/Example 4/node_modules/gulp-git/lib/commit.js:15:18)
  at Gulp.gulp.task.gulp.src.pipe.git.add.args (/Users/me/Desktop/Example 4/gulpfile.js:190:15)
  at module.exports (/Users/me/Desktop/Example 4/node_modules/gulp/node_modules/orchestrator/lib/runTask.js:34:7)
  at Gulp.Orchestrator._runTask (/Users/me/Desktop/Example 4/node_modules/gulp/node_modules/orchestrator/index.js:273:3)
  at Gulp.Orchestrator._runStep (/Users/me/Desktop/Example 4/node_modules/gulp/node_modules/orchestrator/index.js:214:10)
  at Gulp.Orchestrator.start (/Users/me/Desktop/Example 4/node_modules/gulp/node_modules/orchestrator/index.js:134:8)
  at /usr/local/lib/node_modules/gulp/bin/gulp.js:129:20
  at process._tickCallback (node.js:442:13)
  at Function.Module.runMain (module.js:499:11)
  at startup (node.js:119:16)
  at node.js:929:3

[?] Please enter commit message...
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-04-10 21:23:24

gulp-提示符在流中不能很好地工作,所以当git.commit仍然是undefined时,git(这里是:undefined)将被执行。因此,gulp git块需要在gulp提示的回调中移动:

代码语言:javascript
复制
// git commit task with gulp prompt
gulp.task('commit', function(){
    // just source anything here - we just wan't to call the prompt for now
    gulp.src('package.json')
    .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));
    }));
});
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29568957

复制
相关文章

相似问题

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