(ctx context.Context, r *connect.Request[localv1.GitStatusRequest])
| 12 | ) |
| 13 | |
| 14 | func (s *Server) GitStatus(ctx context.Context, r *connect.Request[localv1.GitStatusRequest]) (*connect.Response[localv1.GitStatusResponse], error) { |
| 15 | gitPath, subPath, err := gitutil.InferRepoRootAndSubpath(s.app.ProjectPath) |
| 16 | if err != nil { |
| 17 | // Not a git repo |
| 18 | return nil, connect.NewError(connect.CodeFailedPrecondition, err) |
| 19 | } |
| 20 | // Get authenticated admin client |
| 21 | if !s.app.ch.IsAuthenticated() { |
| 22 | // if not authenticated do not return local/remote changes info |
| 23 | st, err := gitutil.RunGitStatus(gitPath, subPath, "origin", "") |
| 24 | if err != nil { |
| 25 | return nil, err |
| 26 | } |
| 27 | return connect.NewResponse(&localv1.GitStatusResponse{ |
| 28 | Branch: st.Branch, |
| 29 | GithubUrl: st.RemoteURL, |
| 30 | Subpath: subPath, |
| 31 | ManagedGit: false, |
| 32 | }), nil |
| 33 | } |
| 34 | |
| 35 | // TODO: cache project inference |
| 36 | projects, err := s.app.ch.InferProjects(ctx, s.app.ch.Org, s.app.ProjectPath) |
| 37 | if err != nil { |
| 38 | if !errors.Is(err, cmdutil.ErrInferProjectFailed) { |
| 39 | return nil, err |
| 40 | } |
| 41 | // if not connected to a project do not return local/remote changes info |
| 42 | st, err := gitutil.RunGitStatus(gitPath, subPath, "origin", "") |
| 43 | if err != nil { |
| 44 | return nil, err |
| 45 | } |
| 46 | return connect.NewResponse(&localv1.GitStatusResponse{ |
| 47 | Branch: st.Branch, |
| 48 | GithubUrl: st.RemoteURL, |
| 49 | Subpath: subPath, |
| 50 | ManagedGit: false, |
| 51 | }), nil |
| 52 | } |
| 53 | project := projects[0] |
| 54 | |
| 55 | if subPath != project.Subpath { |
| 56 | // unlikely but just in case |
| 57 | return nil, connect.NewError(connect.CodeUnknown, errors.New("detected subpath within git repo does not match project subpath")) |
| 58 | } |
| 59 | |
| 60 | // get ephemeral git credentials |
| 61 | config, err := s.app.ch.GitHelper(s.app.ch.Org, project.Name, gitPath).GitConfig(ctx) |
| 62 | if err != nil { |
| 63 | return nil, err |
| 64 | } |
| 65 | // set remote |
| 66 | // usually not needed but the older flow did not set the remote by name `rill` |
| 67 | err = gitutil.SetRemote(gitPath, config) |
| 68 | if err != nil { |
| 69 | return nil, err |
| 70 | } |
| 71 | err = gitutil.GitFetch(ctx, gitPath, config) |
nothing calls this directly
no test coverage detected