nodegit: getHeadCommit() 保存目录 (libgit2)

nodegit: getHeadCommit() holds the directory (libgit2)

在我使用 nodegit 克隆存储库并调用 getHeadCommit() 之后,Node 进程保留了该目录,这防止它被代码(fs-extra remove)或 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: EBUSY: resource busy or locked, unlink '***\.tmp\.git\objects\pack\pack-27924883cff8a0039ced57d07bad35459885ff9d.pack'

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

糟糕!我错过了 free 方法。它解决了问题。