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

Function runSmartCherryPick

cli/flow/main.go:3567–3776  ·  view source on GitHub ↗
(ctx *snap.Context)

Source from the content-addressed store, hash-verified

3565}
3566
3567func runSmartCherryPick(ctx *snap.Context) error {
3568 if err := ensureGitRepository(); err != nil {
3569 return err
3570 }
3571
3572 args := ctx.Args()
3573 if len(args) == 0 {
3574 fmt.Fprintln(ctx.Stderr(), "Usage: smartCherryPick <commit-hash> [end-hash]")
3575 fmt.Fprintln(ctx.Stderr(), " Single commit: smartCherryPick abc123")
3576 fmt.Fprintln(ctx.Stderr(), " Range of commits: smartCherryPick abc123 def456")
3577 return fmt.Errorf("missing commit hash argument")
3578 }
3579
3580 startHash := args[0]
3581 var endHash string
3582 if len(args) > 1 {
3583 endHash = args[1]
3584 }
3585
3586 // Get list of commits to cherry-pick
3587 var commits []string
3588 if endHash == "" {
3589 // Single commit
3590 commits = []string{startHash}
3591 } else {
3592 // Range of commits (from startHash to endHash, inclusive)
3593 cmd := exec.Command("git", "rev-list", "--reverse", startHash+"^.."+endHash)
3594 output, err := cmd.Output()
3595 if err != nil {
3596 return fmt.Errorf("failed to get commit range: %w", err)
3597 }
3598 lines := strings.Split(strings.TrimSpace(string(output)), "\n")
3599 for _, line := range lines {
3600 if line != "" {
3601 commits = append(commits, line)
3602 }
3603 }
3604 }
3605
3606 if len(commits) == 0 {
3607 return fmt.Errorf("no commits found in range")
3608 }
3609
3610 fmt.Fprintf(ctx.Stdout(), "Smart cherry-picking %d commit(s)...\n", len(commits))
3611
3612 // Get current working directory
3613 cwd, err := os.Getwd()
3614 if err != nil {
3615 return fmt.Errorf("failed to get working directory: %w", err)
3616 }
3617
3618 for i, commit := range commits {
3619 fmt.Fprintf(ctx.Stdout(), "\n[%d/%d] Processing commit %s\n", i+1, len(commits), commit)
3620
3621 // Get commit info for context
3622 commitMsgCmd := exec.Command("git", "log", "-1", "--format=%s", commit)
3623 commitMsgOut, _ := commitMsgCmd.Output()
3624 commitMsg := strings.TrimSpace(string(commitMsgOut))

Callers 1

mainFunction · 0.85

Calls 3

ensureGitRepositoryFunction · 0.85
getConflictedFilesFunction · 0.85
StringMethod · 0.80

Tested by

no test coverage detected