Skip to content

Commit

Permalink
Merge pull request #25 from rockstaedt/24-repair-validation
Browse files Browse the repository at this point in the history
Fix hook script
  • Loading branch information
rockstaedt authored Feb 13, 2023
2 parents d71a61a + 0cf65db commit 10945f6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
What is the pull request about? What changes were made?

## Linked Issue
Closes issue #_
Closes #_
5 changes: 4 additions & 1 deletion util/hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ 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.Fprint(writer, "#!/bin/sh\n\n")
_, err = fmt.Fprintf(writer, `"%s/commit-message-check" validate $1`, exePath)
_, err = fmt.Fprint(writer, "\n")

if err != nil {
log.Printf("[ERROR]\t Could not write commit-msg script: %s", err)
}
Expand Down
12 changes: 10 additions & 2 deletions util/hook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,23 @@ 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 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`)
})

t.Run("inserts a blank line at the end of file", func(t *testing.T) {
buffer.Reset()

writeContent(buffer, "usr/tmp")

assert.Contains(t, buffer.String(), "$1\n")
})

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

0 comments on commit 10945f6

Please sign in to comment.