2016-05-07 15 views
6

मैं प्रोजेक्ट पर काम कर रहा हूं और मैं गलती से गिट पर प्रतिबद्धता और धक्का देना चाहता हूं लेकिन जब मैं गिट कार्य चला रहा हूं तो मुझे कुछ समस्या का सामना करना पड़ रहा है, इसलिए धक्का कार्य के लिए इंतजार नहीं कर रहा है ....गुलप गिट पहले प्रतिबद्ध कार्य को चलाते हैं तो कार्य

कोई भी मेरी मदद कर सकता है! मैं कार्य को पहले रन प्रतिबद्ध करने की तरह बनाना चाहता हूं और फिर स्वचालित रूप से धक्का देता हूं और पूर्ण कार्य कार्य तक पुश कार्य नहीं चलाता ....

गुलप गिट कमिट और पुश के लिए गुल टास्क!

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

उत्तर

1

समस्या आप समानांतर में कार्य चलाने के लिए runSequence कह रहे हैं प्लगइन है। समाधान वास्तव में सरल है:

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

ऐसा करने से आप यह सुनिश्चित करें कि घूंट: धक्का केवल घूंट के बाद चलेगा: प्रतिबद्ध तैयार कर लिया और धक्का किया जाता है के बाद घूंट: किया चलेंगे।

इसके अलावा, मैं सुझाव है कि आप घूँट में धारा वापसी: धक्का और में किया कॉलबैक पैरामीटर का उपयोग घूंट: किया, अगर आपको लगता है कि घूंट नहीं करते पता नहीं है जब इस कार्य समाप्त होता है:

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

संपादित करें: आपको में स्ट्रीम वापस करना होगा: कार्य भी करें, मैंने आपको यह दिखाने के लिए अपना जवाब बदल दिया।

+0

काम नहीं कर रहा है ... और धक्का कार्य कार्य के लिए प्रतिबद्ध के लिए पूरा के लिए इंतजार नहीं कर रहा है! – Faizy

+0

आप स्ट्रीम को ** gulp में वापस नहीं करते हैं: ** ** भी प्रतिबद्ध करें। मैंने आपको यह दिखाने के लिए अपना जवाब संपादित किया कि, कैसे प्रयास करें और मुझे बताएं कि यह काम करता है या नहीं। – franmartosr

+0

धन्यवाद, यह कोड काम कर रहा है लेकिन मैंने एक बात देखी है कि यह मेरी वर्तमान प्रतिबद्धता को धक्का नहीं दे रहा है बल्कि गिटहब पर हालिया प्रतिबद्धता को दबा रहा है! – Faizy

0

gulp-git प्रतिबद्ध वास्तव में एक स्ट्रीम (डिज़ाइन द्वारा) नहीं लौटाता है। Commit doesn't fire end #49 देखें।

इसके आसपास पाने के लिए, आप bluebird जैसी वादा लाइब्रेरी का उपयोग कर सकते हैं।

यहाँ, मेरे लिए काम किया 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. 


     ; 


    }); 

}); 
+0

"धन्यवाद" आप बहुत – Faizy

+0

@Faizy - खुशी हुई इससे मदद मिली! क्या आप उत्तर स्वीकार करने के लिए बहुत दयालु होंगे, धन्यवाद! – AndrewD

संबंधित मुद्दे