2016-05-09 4 views
0

私はほとんどの論理は単純で、ブランチをチェックアウトし、原点リモートにプッシュここhttps://www.npmjs.com/package/gulp-gitの連結一気-gitの作業

/** 
* Checkout production build branch. 
*/ 
gulp.task('checkout-dist', function(){ 
    git.checkout('dist', function (err) { 
    if (err) throw err; 
    }); 
}); 

/** 
* Checkout pre production build branch. 
*/ 
gulp.task('checkout-stage', function(){ 
    git.checkout('stage', function (err) { 
    if (err) throw err; 
    }); 
}); 

/** 
* Push production build branch. 
*/ 
gulp.task('push-dist', ['checkout-dist'], function(){ 
    git.push('origin', 'dist', {args: " -f"}, function (err) { 
    if (err) throw err; 
    }); 
}); 

/** 
* Push pre production build branch. 
*/ 
gulp.task('push-stage', ['checkout-stage'], function(){ 
    git.push('origin', 'stage', {args: " -f"}, function (err) { 
    if (err) throw err; 
    }); 
}); 

/** 
* Push production and pre production branches. 
*/ 
gulp.task('deploy-remote', ['push-stage', 'push-dist'], function(){ 
    git.checkout('master', function(err) { 
    if (err) throw err; 
    }); 
}); 

を提供するタスクの例をコピーしている以下の一気-gitのタスクを持っています。

gulp push-stageまたはgulp push-distでタスクを個別に実行すると、正常に動作しています。

しかし私はstageとdistを同時に押して、deploy-remoteという新しいタスクを作成しました。 そのタスクは、それが原点レポへのコミットをプッシュし、動作しますが、それはして終わりにクラッシュ:

[17:18:56] Starting 'checkout-stage'... 
[17:18:56] Finished 'checkout-stage' after 12 ms 
[17:18:56] Starting 'push-stage'... 
[17:18:56] Finished 'push-stage' after 9.41 ms 
[17:18:56] Starting 'checkout-dist'... 
[17:18:56] Finished 'checkout-dist' after 14 ms 
[17:18:56] Starting 'push-dist'... 
[17:18:56] Finished 'push-dist' after 14 ms 
[17:18:56] Starting 'deploy-remote'... 
[17:18:56] Finished 'deploy-remote' after 12 ms 

gulpfile.js:483 
    if (err) throw err; 
       ^
Error: Command failed: fatal: Unable to create '.git/index.lock': The file already exists. 

If no other git process is currently running, this probably means a 
git process crashed in this repository earlier. Make sure no other git 
process is running and remove the file manually to continue. 

    at ChildProcess.exithandler (child_process.js:658:15) 
    at ChildProcess.emit (events.js:98:17) 
    at maybeClose (child_process.js:766:16) 
    at Socket.<anonymous> (child_process.js:979:11) 
    at Socket.emit (events.js:95:17) 
    at Pipe.close (net.js:466:12) 

はどのようにこれが達成されなければなりませんか?

答えて

2

まず、これらのgit操作はすべて非同期です。つまり、コールバック関数cbを呼び出すことによって、終了時にgulpに伝える必要があります。例:

gulp.task('push-dist', ['checkout-dist'], function(cb) { 
    git.push('origin', 'dist', {args: " -f"}, function (err) { 
    cb(err); 
    }); 
}); 

第2に、同じリポジトリで同時に2つのgitプロセスを実行することはできません。これは実行している処理です。各gitプロセスは.git/index.lockファイルを作成し、他のgitプロセスが同じリポジトリにアクセスするのを防ぎます。

あなたがrun-sequence使って次々操作を実行する必要があります、

var runSequence = require('run-sequence'); 

gulp.task('checkout-master', function(cb) { 
    git.checkout('master', function(err) { 
    cb(err); 
    }); 
}); 

gulp.task('deploy-remote',, function(cb) { 
    runSequence('push-stage', 'push-dist', 'checkout-master', cb); 
}); 
+0

おかげで、didntは実行secuenceのパッケージを知っている魔法のように動作します – lapinkoira

関連する問題