lollipopwizardkid
lollipopwizardkid

Reputation: 91

Trying to implement gulp-git and gulp-prompt to allow custom commit messages

I'm getting a number of errors when attempting to implement gulp-git with gulp-prompt. I'm trying to give the user the ability to enter their own unique git commit message when the type the command gulp commit. The message should be displayed after the user types the gulp-commit command.

Here is the gulp command

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

Currently I am getting the following errors after I type the command into the terminal..

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...

Upvotes: 1

Views: 1590

Answers (1)

xsh.7
xsh.7

Reputation: 6250

gulp-prompt does not work well with streams, so gulp-git (here: git.commit) will be executed while message is still undefined. Therefore the gulp-git block needs to be moved inside gulp-prompt's callback:

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

Upvotes: 4

Related Questions