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

时间:2017-12-07 13:50:26

标签: libgit2 nodegit

使用nodegit克隆存储库并调用getHeadCommit()后,Node进程会保存目录,以防止代码(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()

后释放存储库目录

1 个答案:

答案 0 :(得分:0)

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