0

nodegit在我使用和调用克隆存储库后getHeadCommit(),节点进程会保存该目录,从而防止它被代码(fs-extra remove)或操作系统删除。

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: EBUSY: resource busy or locked, unlink '***\.tmp\.git\objects\pack\pack-27924883cff8a0039ced57d07bad35459885ff9d.pack'

我的代码有错误吗?或者有没有一种方法可以在nodegit使用后释放存储库目录repository.getHeadCommit()

4

1 回答 1

0

哎呀!我错过了免费方法。它解决了这个问题。

于 2017-12-08T07:44:17.587 回答