diff --git a/spec/git-repository-async-spec.js b/spec/git-repository-async-spec.js index bbaa7ef75..b59bc35ab 100644 --- a/spec/git-repository-async-spec.js +++ b/spec/git-repository-async-spec.js @@ -45,6 +45,19 @@ describe('GitRepositoryAsync', () => { }) }) + describe('.openNodeGitRepository()', () => { + it('returns a new repository instance', async () => { + repo = openFixture('master.git') + + const originalRepo = await repo.getRepo() + expect(originalRepo).not.toBeNull() + + const nodeGitRepo = repo.openNodeGitRepository() + expect(nodeGitRepo).not.toBeNull() + expect(originalRepo).not.toBe(nodeGitRepo) + }) + }) + describe('.getPath()', () => { it('returns the repository path for a repository path', async () => { repo = openFixture('master.git') diff --git a/src/git-repository-async.js b/src/git-repository-async.js index 295fa5ca2..f48988f91 100644 --- a/src/git-repository-async.js +++ b/src/git-repository-async.js @@ -35,7 +35,10 @@ export default class GitRepositoryAsync { this.emitter = new Emitter() this.subscriptions = new CompositeDisposable() this.pathStatusCache = {} - this.repoPromise = Git.Repository.openExt(_path, 0, '') + // NB: This needs to happen before the following .openNodeGitRepository + // call. + this.openedPath = _path + this.repoPromise = this.openNodeGitRepository() this.isCaseInsensitive = fs.isCaseInsensitive() this.upstreamByPath = {} @@ -851,6 +854,16 @@ export default class GitRepositoryAsync { }) } + // Open a new instance of the underlying {NodeGit.Repository}. + // + // By opening multiple connections to the same underlying repository, users + // can safely access the same repository concurrently. + // + // Returns the new {NodeGit.Repository}. + openNodeGitRepository () { + return Git.Repository.openExt(this.openedPath, 0, '') + } + // Section: Private // ================