Skip to content

Commit

Permalink
to -> onto
Browse files Browse the repository at this point in the history
  • Loading branch information
cooper-oh committed Dec 16, 2024
1 parent 6bf4884 commit a7e227e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
8 changes: 4 additions & 4 deletions cmd/cherry-pick/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@ import (
)

var (
prNumber = flag.Int("pr", 0, "The PR number to cherry-pick (required)")
to = flag.String("to", "", "The branch to cherry-pick to (required)")
prNumber = flag.Int("pr", 0, "The PR number onto cherry-pick (required)")
onto = flag.String("onto", "", "The branch to cherry-pick onto (required)")
rebase = flag.Bool("rebase", false, "Rebase the cherry-pick")
)

func main() {
flag.Parse()
if *prNumber == 0 || *to == "" {
if *prNumber == 0 || *onto == "" {
flag.Usage()
os.Exit(2)
}

cherryPick := git.CherryPick{
PRNumber: *prNumber,
To: *to,
OnTo: *onto,
Rebase: *rebase,
}

Expand Down
12 changes: 6 additions & 6 deletions git/cherry-pick.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (

type CherryPick struct {
PRNumber int
To string
OnTo string
Rebase bool
}

Expand All @@ -40,7 +40,7 @@ func (cherryPick *CherryPick) RunWithContext(ctx context.Context) error {
}
}

var cherryPickBranchName = fmt.Sprintf("cherry-pick-pr-%d-to-%s-%d", cherryPick.PRNumber, cherryPick.To, time.Now().Unix())
var cherryPickBranchName = fmt.Sprintf("cherry-pick-pr-%d-onto-%s-%d", cherryPick.PRNumber, cherryPick.OnTo, time.Now().Unix())
tui.WithSpinner(ctx, fmt.Sprintf("Fetching PR #%d to branch %s", cherryPick.PRNumber, cherryPickBranchName), func(ctx context.Context) (string, error) {

if _, stderr, err := ExecContext(ctx, "git", "fetch", "--recurse-submodules", "origin", fmt.Sprintf("pull/%d/head:%s", cherryPick.PRNumber, cherryPickBranchName)); err != nil {
Expand All @@ -59,7 +59,7 @@ func (cherryPick *CherryPick) RunWithContext(ctx context.Context) error {
})

if cherryPick.Rebase {
tui.WithSpinner(ctx, fmt.Sprintf("Rebasing branch %s onto %s", cherryPickBranchName, cherryPick.To), func(ctx context.Context) (string, error) {
tui.WithSpinner(ctx, fmt.Sprintf("Rebasing branch %s onto %s", cherryPickBranchName, cherryPick.OnTo), func(ctx context.Context) (string, error) {
prDiff, stderr, err := gh.ExecContext(ctx, "pr", "diff", strconv.Itoa(cherryPick.PRNumber), "--patch")
if err != nil {
return "", fmt.Errorf("error getting PR diff: %w: %s", err, stderr.String())
Expand All @@ -69,10 +69,10 @@ func (cherryPick *CherryPick) RunWithContext(ctx context.Context) error {
return "", fmt.Errorf("error applying PR diff: %w: %s", err, stderr.String())
}

return fmt.Sprintf("Rebased branch %s onto %s", cherryPickBranchName, cherryPick.To), nil
return fmt.Sprintf("Rebased branch %s onto %s", cherryPickBranchName, cherryPick.OnTo), nil
})
} else {
tui.WithSpinner(ctx, fmt.Sprintf("Cherry-picking branch %s onto %s", cherryPickBranchName, cherryPick.To), func(ctx context.Context) (string, error) {
tui.WithSpinner(ctx, fmt.Sprintf("Cherry-picking branch %s onto %s", cherryPickBranchName, cherryPick.OnTo), func(ctx context.Context) (string, error) {
stdout, stderr, err := ExecContext(ctx, "gh", "pr", "view", strconv.Itoa(cherryPick.PRNumber), "--json", "--mergeCommit", "--jq", ".mergeCommit.oid")
if err != nil {
return "", fmt.Errorf("error getting PR merge commit: %w: %s", err, stderr.String())
Expand All @@ -87,7 +87,7 @@ func (cherryPick *CherryPick) RunWithContext(ctx context.Context) error {
return "", fmt.Errorf("error cherry-picking PR merge commit: %w: %s", err, stderr.String())
}

return fmt.Sprintf("Cherry-picked branch %s onto %s", cherryPickBranchName, cherryPick.To), nil
return fmt.Sprintf("Cherry-picked branch %s onto %s", cherryPickBranchName, cherryPick.OnTo), nil
})
}

Expand Down

0 comments on commit a7e227e

Please sign in to comment.