I'm currently writing a node.js module. I'm using var exec = require('child_process').exec;
from the node.js api. But I have to execute 2 git commands with exec successively.
I always get the following error message:
exec error: Error: Command failed: fatal: Unable to create '~/Git/project/.git/index.lock': File 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.
I need to execute the seconed command after the first is finished - keyword: sync So far I tried it with execSync but it won't run on windows systems, which is a no go.
Currently I'm using the asyncblock module, but I gives me the error I mentioned above, too.
This happens when both values in the updateList are true, if one is false all works as expected.
var loadPackageJson = function(updateList){
if(updateList.foo === true){
update('foo/package.json');
}
if (updateList.bar === true){
update('bar/package.json');
}
};
var update = function(path){
var packageJson = JSON.parse(fs.readFileSync(path,'utf8'));
incrementVersion(packageJson);
asyncblock(function(flow){
exec('git log -1 HEAD', flow.add('commit'));
var result = flow.wait('commit');
var commit=result.split('\n');
console.info(commit[0]);
setValueInPackageJson('commit', commit[0], packageJson);
writeUpdatedPackageJson(path, packageJson);
flow.wait();
exec('git add ' + path, flow.add('add'));
flow.wait('add'); //error is thrown here
console.info('added ' + path + ' successful to commit');
});
};
How can I execute both git commands synchronously?
/edit I know the following Thread on SO, but I helps me not to fix this problem. I found the hint with asyncblock on this thread.
/edit2 The output on the console looks like the following:
Version: 0.6.14
Version: 0.0.901
commit a3ed4fd8545b736aa9feea1bea52c5e0aa6a07ac
foo/package.json successfully updated
commit a3ed4fd8545b736aa9feea1bea52c5e0aa6a07ac
bar/package.json successfully updated
In my eyes this looks like node parallelized the processing of the loadPackageJson
function.
BR & Thanks, mybecks