MCPcopy Create free account
hub / github.com/go-git/go-git / Repository

Method Repository

submodule.go:102–162  ·  view source on GitHub ↗

Repository returns the Repository represented by this submodule

()

Source from the content-addressed store, hash-verified

100
101// Repository returns the Repository represented by this submodule
102func (s *Submodule) Repository() (*Repository, error) {
103 if !s.initialized {
104 return nil, ErrSubmoduleNotInitialized
105 }
106
107 storer, err := s.w.r.Storer.Module(s.c.Name)
108 if err != nil {
109 return nil, err
110 }
111
112 _, err = storer.Reference(plumbing.HEAD)
113 if err != nil && err != plumbing.ErrReferenceNotFound {
114 return nil, err
115 }
116
117 var exists bool
118 if err == nil {
119 exists = true
120 }
121
122 var worktree billy.Filesystem
123 if worktree, err = s.w.Filesystem.Chroot(s.c.Path); err != nil {
124 return nil, err
125 }
126
127 if exists {
128 return Open(storer, worktree)
129 }
130
131 r, err := Init(storer, worktree)
132 if err != nil {
133 return nil, err
134 }
135
136 moduleEndpoint, err := transport.NewEndpoint(s.c.URL)
137 if err != nil {
138 return nil, err
139 }
140
141 if !path.IsAbs(moduleEndpoint.Path) && moduleEndpoint.Protocol == "file" {
142 remotes, err := s.w.r.Remotes()
143 if err != nil {
144 return nil, err
145 }
146
147 rootEndpoint, err := transport.NewEndpoint(remotes[0].c.URLs[0])
148 if err != nil {
149 return nil, err
150 }
151
152 rootEndpoint.Path = path.Join(rootEndpoint.Path, moduleEndpoint.Path)
153 *moduleEndpoint = *rootEndpoint
154 }
155
156 _, err = r.CreateRemote(&config.RemoteConfig{
157 Name: DefaultRemoteName,
158 URLs: []string{moduleEndpoint.String()},
159 })

Callers 10

TestSubmoduleParseScpMethod · 0.95
statusMethod · 0.95
updateMethod · 0.95
TestUpdateMethod · 0.80
mainFunction · 0.80

Calls 10

StringMethod · 0.95
NewEndpointFunction · 0.92
OpenFunction · 0.85
InitFunction · 0.85
ChrootMethod · 0.80
RemotesMethod · 0.80
JoinMethod · 0.80
CreateRemoteMethod · 0.80
ModuleMethod · 0.65
ReferenceMethod · 0.65