Hello,
I use Promise for a initialize node project.
I want to insert in my MongoDb the name of files on all of my branch on my git repository.
I use nodegit to manipulate repo, for every nodegit method the return is a Promise. But i need to loop on all branch reference for get all files and branch name.
After that i can prepare my array for insert in database on next promise.
Code look like :
// List all branchs
.then((branchs) => {
let promises = [];
let allBranchFiles = [];
branchs.map((branch) => {
let q = repo.checkoutBranch(branch, config.checkoutOpts)
.then(() => repo.getCurrentBranch())
.then((ref) => {
return new Promise((resolve, reject) => {
fs.readdir('./myRepo/', (err, files) => {
files.map((file) => {
allBranchFiles.push({fileName: file, branch: branch});
});
resolve(allBranchFiles);
});
});
});
promises.push(q);
});
return Promise.all(promises);
})
That code finish by two way :
- First :
{ Error: the index is locked; this might be due to a concurrent or crashed process at Error (native) errno: -14 }
I'm sure no other process use git in this repo!
- Second :
All of my files get the same value for "branch" but they are on separate branchs.
Thank you for helping me guys !
Cya.