MCPcopy Index your code
hub / github.com/rilldata/rill / GitPush

Method GitPush

cli/pkg/local/git.go:234–293  ·  view source on GitHub ↗
(ctx context.Context, r *connect.Request[localv1.GitPushRequest])

Source from the content-addressed store, hash-verified

232}
233
234func (s *Server) GitPush(ctx context.Context, r *connect.Request[localv1.GitPushRequest]) (*connect.Response[localv1.GitPushResponse], error) {
235 // Get authenticated admin client
236 if !s.app.ch.IsAuthenticated() {
237 return nil, errors.New("must authenticate before performing this action")
238 }
239
240 projects, err := s.app.ch.InferProjects(ctx, s.app.ch.Org, s.app.ProjectPath)
241 if err != nil {
242 if !errors.Is(err, cmdutil.ErrInferProjectFailed) {
243 return nil, err
244 }
245 return nil, errors.New("repo is not connected to a project")
246 }
247 project := projects[0]
248
249 gitPath, subpath, err := gitutil.InferRepoRootAndSubpath(s.app.ProjectPath)
250 // Not a git repo
251 if err != nil {
252 return nil, connect.NewError(connect.CodeFailedPrecondition, err)
253 }
254 if project.Subpath != subpath {
255 return nil, errors.New("detected subpath within git repo does not match project subpath")
256 }
257
258 author, err := s.app.ch.GitSignature(ctx, gitPath)
259 if err != nil {
260 return nil, err
261 }
262
263 config, err := s.app.ch.GitHelper(s.app.ch.Org, project.Name, gitPath).GitConfig(ctx)
264 if err != nil {
265 return nil, err
266 }
267 err = gitutil.SetRemote(gitPath, config)
268 if err != nil {
269 return nil, err
270 }
271
272 // fetch the status again
273 gs, err := gitutil.RunGitStatus(gitPath, subpath, config.RemoteName(), "")
274 if err != nil {
275 return nil, err
276 }
277 if gs.RemoteCommits > 0 && !r.Msg.Force {
278 return nil, connect.NewError(connect.CodeFailedPrecondition, errors.New("cannot push with remote commits present, please pull first"))
279 }
280
281 var choice string
282 if r.Msg.Force {
283 choice = "2"
284 } else {
285 choice = "1"
286 }
287 err = s.app.ch.CommitAndSafePush(ctx, gitPath, config, r.Msg.CommitMessage, author, choice)
288 if err != nil {
289 return nil, err
290 }
291

Callers

nothing calls this directly

Calls 10

InferRepoRootAndSubpathFunction · 0.92
SetRemoteFunction · 0.92
RunGitStatusFunction · 0.92
IsAuthenticatedMethod · 0.80
InferProjectsMethod · 0.80
GitSignatureMethod · 0.80
GitConfigMethod · 0.80
GitHelperMethod · 0.80
RemoteNameMethod · 0.80
CommitAndSafePushMethod · 0.80

Tested by

no test coverage detected