(ctx *snap.Context)
| 2608 | } |
| 2609 | |
| 2610 | func runCommitReviewAndPush(ctx *snap.Context) error { |
| 2611 | if ctx.NArgs() != 0 { |
| 2612 | return reportError(ctx, fmt.Errorf("Usage: %s commitReviewAndPush", commandName)) |
| 2613 | } |
| 2614 | |
| 2615 | payload, err := prepareCommit(ctx) |
| 2616 | if err != nil { |
| 2617 | return err |
| 2618 | } |
| 2619 | |
| 2620 | updatedMessage, confirmed, err := promptCommitConfirmation(ctx, payload.message) |
| 2621 | if err != nil { |
| 2622 | return reportError(ctx, err) |
| 2623 | } |
| 2624 | |
| 2625 | if !confirmed { |
| 2626 | fmt.Fprintln(ctx.Stdout(), "Commit cancelled.") |
| 2627 | return nil |
| 2628 | } |
| 2629 | |
| 2630 | if updatedMessage != payload.message { |
| 2631 | trimmed := strings.TrimSpace(updatedMessage) |
| 2632 | if trimmed == "" { |
| 2633 | return reportError(ctx, fmt.Errorf("commit message is empty after editing")) |
| 2634 | } |
| 2635 | paragraphs := splitCommitMessageParagraphs(trimmed) |
| 2636 | if len(paragraphs) == 0 { |
| 2637 | return reportError(ctx, fmt.Errorf("commit message is empty after formatting")) |
| 2638 | } |
| 2639 | payload.message = trimmed |
| 2640 | payload.paragraphs = paragraphs |
| 2641 | } |
| 2642 | |
| 2643 | printProposedMessage(ctx, payload.message) |
| 2644 | if err := commitWithPayload(ctx, payload); err != nil { |
| 2645 | return err |
| 2646 | } |
| 2647 | printCommitSuccess(ctx, payload) |
| 2648 | |
| 2649 | if err := runGitCommandStreaming(ctx, "push"); err != nil { |
| 2650 | return reportError(ctx, fmt.Errorf("git push: %w", err)) |
| 2651 | } |
| 2652 | |
| 2653 | fmt.Fprintln(ctx.Stdout(), "✔️ Pushed") |
| 2654 | return nil |
| 2655 | } |
| 2656 | |
| 2657 | func prepareCommit(ctx *snap.Context) (*commitPayload, error) { |
| 2658 | if err := ensureGitRepository(); err != nil { |
no test coverage detected