Skip to content

Commit

Permalink
test(git): first test
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanlogue committed Feb 6, 2024
1 parent b1dfbee commit 41fb04b
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions git.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
6 changes: 3 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 41fb04b

Please sign in to comment.