diff --git a/spec/git-spec.coffee b/spec/git-spec.coffee index 1c001efe..376efd30 100644 --- a/spec/git-spec.coffee +++ b/spec/git-spec.coffee @@ -23,6 +23,8 @@ describe "git", -> describe "when the path is a repository", -> it "returns a repository", -> expect(git.open(__dirname)).not.toBeNull() + it "has @submodules unevaluated", -> + expect(typeof(git.open(__dirname).submodules)).toBe('function') describe "when the path isn't a repository", -> it "returns null", -> diff --git a/src/git.coffee b/src/git.coffee index d1927a19..02441d83 100644 --- a/src/git.coffee +++ b/src/git.coffee @@ -157,6 +157,9 @@ Repository::submoduleForPath = (path) -> path = @relativize(path) return null unless path + if @submodules instanceof Function + @submodules() + for submodulePath, submoduleRepo of @submodules if path is submodulePath return submoduleRepo @@ -228,5 +231,8 @@ openSubmodules = (repository) -> exports.open = (repositoryPath) -> repository = openRepository(repositoryPath) - openSubmodules(repository) if repository? + if repository? + # openSubmodules may be long (e.g., on network FS), + # so loading them lazily + repository.submodules = -> openSubmodules(repository) repository