From 83669c54939da875e6ffa7a6979ead4e65de5512 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eric=20Rockst=C3=A4dt?= Date: Sun, 12 Feb 2023 17:50:07 +0100 Subject: [PATCH 1/3] Fix new lines in hook script --- util/hook.go | 4 +++- util/hook_test.go | 12 ++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/util/hook.go b/util/hook.go index 8c3e0ce..a5c3e8f 100644 --- a/util/hook.go +++ b/util/hook.go @@ -51,7 +51,9 @@ 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) } diff --git a/util/hook_test.go b/util/hook_test.go index 2767c48..fda7c7a 100644 --- a/util/hook_test.go +++ b/util/hook_test.go @@ -134,7 +134,7 @@ 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) { @@ -142,7 +142,15 @@ func TestWriteContent(t *testing.T) { 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) { From 0ec2638bdb84b083c832246e41c924a92e95e07b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eric=20Rockst=C3=A4dt?= Date: Sun, 12 Feb 2023 17:50:20 +0100 Subject: [PATCH 2/3] Reformat file --- util/hook.go | 1 + 1 file changed, 1 insertion(+) diff --git a/util/hook.go b/util/hook.go index a5c3e8f..9e4a914 100644 --- a/util/hook.go +++ b/util/hook.go @@ -54,6 +54,7 @@ func writeContent(writer io.Writer, exePath string) { _, 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) } From 0cf65dbc5b937634f02591da6c26d8ce05057621 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eric=20Rockst=C3=A4dt?= Date: Sun, 12 Feb 2023 17:59:42 +0100 Subject: [PATCH 3/3] Update template --- .github/PULL_REQUEST_TEMPLATE.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 3a55eab..473dd6f 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -2,4 +2,4 @@ What is the pull request about? What changes were made? ## Linked Issue -Closes issue #_ +Closes #_