MCPcopy Create free account
hub / github.com/nikivdev/go / editCommitMessage

Function editCommitMessage

cli/flow/main.go:2773–2803  ·  view source on GitHub ↗
(ctx *snap.Context, current string)

Source from the content-addressed store, hash-verified

2771}
2772
2773func editCommitMessage(ctx *snap.Context, current string) (string, error) {
2774 tmpFile, err := os.CreateTemp("", commandName+"-commit-*.md")
2775 if err != nil {
2776 return "", err
2777 }
2778 defer os.Remove(tmpFile.Name())
2779
2780 if _, err := tmpFile.WriteString(current + "\n"); err != nil {
2781 tmpFile.Close()
2782 return "", err
2783 }
2784 if err := tmpFile.Close(); err != nil {
2785 return "", err
2786 }
2787
2788 editor := findEditor()
2789 cmd := exec.Command(editor, tmpFile.Name())
2790 cmd.Stdout = ctx.Stdout()
2791 cmd.Stderr = ctx.Stderr()
2792 cmd.Stdin = ctx.Stdin()
2793 if err := cmd.Run(); err != nil {
2794 return "", err
2795 }
2796
2797 content, err := os.ReadFile(tmpFile.Name())
2798 if err != nil {
2799 return "", err
2800 }
2801
2802 return string(content), nil
2803}
2804
2805func findEditor() string {
2806 for _, env := range []string{"GIT_EDITOR", "VISUAL", "EDITOR"} {

Callers 1

promptCommitConfirmationFunction · 0.85

Calls 1

findEditorFunction · 0.85

Tested by

no test coverage detected