Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Lazy loading of submodules #52

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions spec/git-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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", ->
Expand Down
8 changes: 7 additions & 1 deletion src/git.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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