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

Function runGitMirrorSetup

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

Source from the content-addressed store, hash-verified

4093}
4094
4095func runGitMirrorSetup(ctx *snap.Context, opts gitMirrorOptions) error {
4096 remote := strings.TrimSpace(opts.remote)
4097 url := strings.TrimSpace(opts.url)
4098 if remote == "" || url == "" {
4099 printGitMirrorUsage(ctx.Stderr())
4100 return fmt.Errorf("setup requires --remote and --url")
4101 }
4102
4103 exists, currentURL, err := gitRemoteState(remote)
4104 if err != nil {
4105 return err
4106 }
4107
4108 if !exists {
4109 if err := runGitCommandStreaming(ctx, "remote", "add", remote, url); err != nil {
4110 return fmt.Errorf("git remote add %s %s: %w", remote, url, err)
4111 }
4112 } else if !urlsEquivalent(currentURL, url) {
4113 if err := runGitCommandStreaming(ctx, "remote", "set-url", remote, url); err != nil {
4114 return fmt.Errorf("git remote set-url %s %s: %w", remote, url, err)
4115 }
4116 }
4117
4118 if err := runGitCommandStreaming(ctx, "fetch", remote, "--prune"); err != nil {
4119 return fmt.Errorf("git fetch %s --prune: %w", remote, err)
4120 }
4121 if err := setGitLocalConfig("fgo.collabRemote", remote); err != nil {
4122 return err
4123 }
4124
4125 fmt.Fprintf(ctx.Stdout(), "✔️ Mirror remote ready: %s -> %s\n", remote, url)
4126 fmt.Fprintf(ctx.Stdout(), "Stored as default in local git config key fgo.collabRemote.\n")
4127 fmt.Fprintf(ctx.Stdout(), "Next: %s gitMirror push\n", commandName)
4128 return nil
4129}
4130
4131func runGitMirrorPush(ctx *snap.Context, opts gitMirrorOptions) error {
4132 remote, err := resolveGitMirrorRemote(opts.remote)

Callers 1

runGitMirrorFunction · 0.85

Calls 5

printGitMirrorUsageFunction · 0.85
gitRemoteStateFunction · 0.85
runGitCommandStreamingFunction · 0.85
urlsEquivalentFunction · 0.85
setGitLocalConfigFunction · 0.85

Tested by

no test coverage detected