code: func (s *Submodule) Repository() (*Repository, error) {
  	if !s.initialized {
  		return nil, ErrSubmoduleNotInitialized
  	}
  
  	storer, err := s.w.r.Storer.Module(s.c.Name)
  	if err != nil {
  		return nil, err
  	}
  
  	_, err = storer.Reference(plumbing.HEAD)
  	if err != nil && err != plumbing.ErrReferenceNotFound {
  		return nil, err
  	}
  
  	var exists bool
  	if err == nil {
  		exists = true
  	}
  
  	var worktree billy.Filesystem
  	if worktree, err = s.w.Filesystem.Chroot(s.c.Path); err != nil {
  		return nil, err
  	}
  
  	if exists {
  		return Open(storer, worktree)
  	}
  
  	r, err := Init(storer, worktree)
  	if err != nil {
  		return nil, err
  	}
  
  	_, err = r.CreateRemote(&config.RemoteConfig{
  		Name: DefaultRemoteName,
  		URLs: []string{s.c.URL},
  	})
  
  	return r, err
  }
docs: // Repository returns the Repository represented by this submodule