2016-05-07 18 views
6

Sto lavorando al progetto e voglio commettere e spingere su git usando by gulp ma sto affrontando qualche problema quando sto eseguendo git task così push quindi task non è in attesa di commit ....Gulp Git esegue prima attività di commit e poi spinge attività

Chiunque può fare il mio aiuto! Voglio rendere il compito come prima esecuzione commit e quindi spingere automaticamente e non eseguire attività push fino a completare l'attività di commit ....

Gulp Task per Gulp Git Commit e Push!

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

risposta

1

Il problema è che stai dicendo runSequence plugin per eseguire i compiti in parallelo. La soluzione è molto semplice:

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

In questo modo ci si assicura che sorso: spingere verrà eseguito solo dopo sorso: commetti finito, e dopo la spinta è fatto sorso: fatto verrà eseguito.

Inoltre, vi consiglio di restituire il flusso in sorso: spingere e utilizzare il parametro di callback fatto in sorso: fatto, se non lo fai sorso non sa quando questa attività si conclude:

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

MODIFICA: è necessario restituire lo stream nel file gulp: commit, ho modificato la risposta per mostrarvi come.

+0

non funziona ... e spingere compito non è in attesa di completamento per commettere compito! – Faizy

+0

Non si restituisce il flusso in ** gulp: commit **. Ho modificato la mia risposta per mostrarti come, provalo e dimmi se funziona. – franmartosr

+0

grazie, questo codice funziona ma ho notato una cosa che non spinge il mio commit corrente ma spingo il commit recente su gitihub! – Faizy

0

gulp-git commit non restituisce effettivamente un flusso (in base alla progettazione). Vedi Commit doesn't fire end #49.

Per aggirare questo problema, è possibile utilizzare una libreria di promessa come bluebird.

Ecco cosa ha funzionato per me, come suggerito da github bfricka utente:

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

"Grazie" sei così tanto – Faizy

+0

@Faizy - contento che abbia aiutato! Saresti così gentile da accettare una risposta, grazie! – AndrewD

Problemi correlati