Skip to content

Commit

Permalink
Merge pull request #23 from rockstaedt/22-quotes-in-path
Browse files Browse the repository at this point in the history
No such file or directory for path with spaces within
  • Loading branch information
rockstaedt authored Feb 12, 2023
2 parents 2346dc8 + 55c95fc commit d71a61a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion util/hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func DeleteHook(path, _ string) error {
}

func writeContent(writer io.Writer, exePath string) {
_, err := fmt.Fprintf(writer, "#!/bin/sh\n\n%s/commit-message-check validate $1\n", exePath)
_, err := fmt.Fprintf(writer, `#!/bin/sh\n\n"%s/commit-message-check" validate $1\n`, exePath)
if err != nil {
log.Printf("[ERROR]\t Could not write commit-msg script: %s", err)
}
Expand Down
8 changes: 4 additions & 4 deletions util/hook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func TestCreateHook(t *testing.T) {

contentBytes, err := os.ReadFile(fmt.Sprintf("%s/commit-msg", hookPath))
assert.Nil(t, err)
assert.Contains(t, string(contentBytes), "root/commit-message-check validate")
assert.Contains(t, string(contentBytes), `"root/commit-message-check" validate`)
})

t.Run("returns any error", func(t *testing.T) {
Expand Down Expand Up @@ -134,15 +134,15 @@ func TestWriteContent(t *testing.T) {

writeContent(buffer, "usr/tmp")

assert.Contains(t, buffer.String(), "#!/bin/sh\n\n")
assert.Contains(t, buffer.String(), `#!/bin/sh\n\n`)
})

t.Run("executes commit-message-check with root path", func(t *testing.T) {
t.Run("executes commit-message-check with root path and quotes path to handle spaces", func(t *testing.T) {
buffer.Reset()

writeContent(buffer, "usr/tmp")

assert.Contains(t, buffer.String(), "usr/tmp/commit-message-check validate $1\n")
assert.Contains(t, buffer.String(), `"usr/tmp/commit-message-check" validate $1\n`)
})

t.Run("logs any error", func(t *testing.T) {
Expand Down

0 comments on commit d71a61a

Please sign in to comment.