After I clone the repository using nodegit
and call getHeadCommit()
, the Node process holds the directory, which prevents it from being removed by code (fs-extra remove), nor by OS.
console.log((async (): Promise<void> => {
const tempDirectory: string = path.join(process.cwd(), '.tmp');
console.log('clone');
const repository: nodegit.Repository = await nodegit.Clone.clone(
'ssh://git@***.git',
tempDirectory,
{
checkoutBranch: 'master',
fetchOpts: {
callbacks: {
certificateCheck: (): number => 1,
credentials: (url: string, userName: string): nodegit.Cred =>
nodegit.Cred.sshKeyNew(
userName,
path.join(os.homedir(), '.ssh', 'id_rsa.pub'),
path.join(os.homedir(), '.ssh', 'id_rsa'),
''
)
}
}
}
);
console.log('get head commit');
const commit: nodegit.Commit = await repository.getHeadCommit();
console.log('remove');
await fse.remove(tempDirectory); // Here Node hangs
console.log('end');
})());
Error message:
Error: EBUSY: resource busy or locked, unlink '***\.tmp\.git\objects\pack\pack-27924883cff8a0039ced57d07bad35459885ff9d.pack'
Is there an error in my code? Or is there a method in nodegit
for releasing the repository directory after using repository.getHeadCommit()
?
Oops! I missed the free method. It fixed the problem.