diff --git a/CHANGELOG.md b/CHANGELOG.md index b2b91a9..6270417 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## Unreleased +### Fixed +- correct quoting of generated command ## [v0.17.0](https://github.com/stefanlogue/meteor/releases/tag/v0.17.0) - 2024-02-06 ### Fixed diff --git a/git.go b/git.go index 3bbce53..ec3fd76 100644 --- a/git.go +++ b/git.go @@ -55,17 +55,17 @@ func getGitTicketNumber(board string) string { } // buildCommitCommand builds the git commit command -func buildCommitCommand(msg string, body string) string { - args := append([]string{"commit", "-m", msg}, os.Args[1:]...) +func buildCommitCommand(msg string, body string, osArgs []string) ([]string, string) { + args := append([]string{"commit", "-m", msg}, osArgs...) if body != "" { args = append(args, "-m", body) } - return shellescape.QuoteCommand(args) + return args, fmt.Sprintf("git %v", shellescape.QuoteCommand(args)) } // commit commits the changes to git -func commit(command string) error { - cmd := exec.Command("git", command) +func commit(command []string) error { + cmd := exec.Command("git", command...) cmd.Stdin = os.Stdin cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr diff --git a/git_test.go b/git_test.go index d6eb8bf..e5db984 100644 --- a/git_test.go +++ b/git_test.go @@ -5,8 +5,8 @@ import "testing" func TestBuildCommitCommand(t *testing.T) { msg := "test" body := "test body" - expected := "commit -m test test body" - got := buildCommitCommand(msg, body) + expected := "git commit -m test -m 'test body'" + _, got := buildCommitCommand(msg, body, nil) if got != expected { t.Errorf("expected %s, got %s", expected, got) } diff --git a/main.go b/main.go index 8bd535c..7a1a8f9 100644 --- a/main.go +++ b/main.go @@ -231,10 +231,10 @@ func main() { newCommit.Body = newCommit.Body + buildCoauthorString(newCommit.Coauthors) } - commitCommand := buildCommitCommand(newCommit.Message, newCommit.Body) - printableCommitCommand := "git " + commitCommand + args := os.Args[1:] + rawCommitCommand, printableCommitCommand := buildCommitCommand(newCommit.Message, newCommit.Body, args) if doesWantToCommit { - err := commit(commitCommand) + err := commit(rawCommitCommand) if err != nil { writeToClipboard(printableCommitCommand) fail(