Skip to content

Commit d71a61a

Browse files
authored
Merge pull request #23 from rockstaedt/22-quotes-in-path
No such file or directory for path with spaces within
2 parents 2346dc8 + 55c95fc commit d71a61a

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

util/hook.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func DeleteHook(path, _ string) error {
5151
}
5252

5353
func writeContent(writer io.Writer, exePath string) {
54-
_, err := fmt.Fprintf(writer, "#!/bin/sh\n\n%s/commit-message-check validate $1\n", exePath)
54+
_, err := fmt.Fprintf(writer, `#!/bin/sh\n\n"%s/commit-message-check" validate $1\n`, exePath)
5555
if err != nil {
5656
log.Printf("[ERROR]\t Could not write commit-msg script: %s", err)
5757
}

util/hook_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func TestCreateHook(t *testing.T) {
9191

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

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

135135
writeContent(buffer, "usr/tmp")
136136

137-
assert.Contains(t, buffer.String(), "#!/bin/sh\n\n")
137+
assert.Contains(t, buffer.String(), `#!/bin/sh\n\n`)
138138
})
139139

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

143143
writeContent(buffer, "usr/tmp")
144144

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

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

0 commit comments

Comments
 (0)