MCPcopy Index your code
hub / github.com/nikivdev/go / runGitMirrorPull

Function runGitMirrorPull

cli/flow/main.go:4149–4211  ·  view source on GitHub ↗
(ctx *snap.Context, opts gitMirrorOptions)

Source from the content-addressed store, hash-verified

4147}
4148
4149func runGitMirrorPull(ctx *snap.Context, opts gitMirrorOptions) error {
4150 remote, err := resolveGitMirrorRemote(opts.remote)
4151 if err != nil {
4152 return err
4153 }
4154 branch, err := resolveGitMirrorBranch(opts.branch)
4155 if err != nil {
4156 return err
4157 }
4158 strategy := strings.ToLower(strings.TrimSpace(opts.strategy))
4159 if strategy == "" {
4160 strategy = "rebase"
4161 }
4162
4163 remoteRef, err := fetchMirrorBranch(ctx, remote, branch)
4164 if err != nil {
4165 return err
4166 }
4167
4168 localRef := fmt.Sprintf("refs/heads/%s", branch)
4169 localExists, err := gitRefExists(localRef)
4170 if err != nil {
4171 return fmt.Errorf("check local branch %s: %w", branch, err)
4172 }
4173 if !localExists {
4174 if err := runGitCommandStreaming(ctx, "checkout", "-b", branch, remoteRef); err != nil {
4175 return fmt.Errorf("git checkout -b %s %s: %w", branch, remoteRef, err)
4176 }
4177 fmt.Fprintf(ctx.Stdout(), "✔️ Created local branch %s from %s\n", branch, remoteRef)
4178 return nil
4179 }
4180
4181 current, err := currentGitBranch()
4182 if err != nil {
4183 return err
4184 }
4185 if current != branch {
4186 if err := runGitCommandStreaming(ctx, "checkout", branch); err != nil {
4187 return fmt.Errorf("git checkout %s: %w", branch, err)
4188 }
4189 }
4190
4191 switch strategy {
4192 case "rebase":
4193 if err := runGitCommandStreaming(ctx, "rebase", remoteRef); err != nil {
4194 return fmt.Errorf("git rebase %s: %w", remoteRef, err)
4195 }
4196 case "merge":
4197 if err := runGitCommandStreaming(ctx, "merge", "--no-ff", remoteRef); err != nil {
4198 return fmt.Errorf("git merge --no-ff %s: %w", remoteRef, err)
4199 }
4200 case "ff-only":
4201 if err := runGitCommandStreaming(ctx, "merge", "--ff-only", remoteRef); err != nil {
4202 return fmt.Errorf("git merge --ff-only %s: %w", remoteRef, err)
4203 }
4204 default:
4205 printGitMirrorUsage(ctx.Stderr())
4206 return fmt.Errorf("unsupported --strategy %q", strategy)

Callers 1

runGitMirrorFunction · 0.85

Calls 7

resolveGitMirrorRemoteFunction · 0.85
resolveGitMirrorBranchFunction · 0.85
fetchMirrorBranchFunction · 0.85
gitRefExistsFunction · 0.85
runGitCommandStreamingFunction · 0.85
currentGitBranchFunction · 0.85
printGitMirrorUsageFunction · 0.85

Tested by

no test coverage detected