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

Function runGitMirrorTake

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

Source from the content-addressed store, hash-verified

4211}
4212
4213func runGitMirrorTake(ctx *snap.Context, opts gitMirrorOptions) error {
4214 dirty, err := gitWorkingTreeDirty()
4215 if err != nil {
4216 return err
4217 }
4218 if dirty {
4219 return fmt.Errorf("working tree is not clean; commit/stash changes before gitMirror take")
4220 }
4221
4222 remote, err := resolveGitMirrorRemote(opts.remote)
4223 if err != nil {
4224 return err
4225 }
4226
4227 currentBranch, err := currentGitBranch()
4228 if err != nil {
4229 return err
4230 }
4231 if currentBranch == "" || currentBranch == "HEAD" {
4232 return fmt.Errorf("detached HEAD; checkout a destination branch first")
4233 }
4234
4235 sourceBranch := strings.TrimSpace(opts.branch)
4236 if sourceBranch == "" {
4237 sourceBranch = currentBranch
4238 }
4239
4240 remoteRef, err := fetchMirrorBranch(ctx, remote, sourceBranch)
4241 if err != nil {
4242 return err
4243 }
4244
4245 if err := runGitCommandStreaming(ctx, "merge", "--squash", "--no-commit", remoteRef); err != nil {
4246 return fmt.Errorf("git merge --squash --no-commit %s: %w", remoteRef, err)
4247 }
4248
4249 fmt.Fprintf(ctx.Stdout(), "✔️ Staged squashed changes from %s into %s\n", remoteRef, currentBranch)
4250 fmt.Fprintf(ctx.Stdout(), "Next: f commit\n")
4251 return nil
4252}
4253
4254func resolveGitMirrorRemote(override string) (string, error) {
4255 remote := strings.TrimSpace(override)

Callers 1

runGitMirrorFunction · 0.85

Calls 5

gitWorkingTreeDirtyFunction · 0.85
resolveGitMirrorRemoteFunction · 0.85
currentGitBranchFunction · 0.85
fetchMirrorBranchFunction · 0.85
runGitCommandStreamingFunction · 0.85

Tested by

no test coverage detected