From 28d550707985358a6b7768b05267150703a0141b Mon Sep 17 00:00:00 2001 From: Eric Villard Date: Fri, 24 Jun 2022 13:38:48 +0200 Subject: [PATCH] =?UTF-8?q?fix(hook):=20=F0=9F=90=9B=20fix=20regression=20?= =?UTF-8?q?that=20prevented=20displaying=20the=20cog=20verify=20message?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Eric Villard --- src/git/hooks/commit-msg | 8 +++++--- tests/commit-msg-hook-test | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/git/hooks/commit-msg b/src/git/hooks/commit-msg index 4af5094..a873e66 100755 --- a/src/git/hooks/commit-msg +++ b/src/git/hooks/commit-msg @@ -15,10 +15,12 @@ MESSAGE="$(cat "${COMMIT_MSG_FILE}")" [[ "${LEGACY_COMMIT_MESSAGE}" -ne 1 ]] || exit 0 -if "$(bin)"/cog verify "${MESSAGE}" |& grep -q "(not committed) - now"; then - echo "${MESSAGE}" | "$(bin)"/insert-icon > "${COMMIT_MSG_FILE}" +result="$("$(bin)"/cog verify "${MESSAGE}" |& cat)" +echo "$result" -else +if echo "${result}" | grep -q "(not committed) - now"; then + echo "${MESSAGE}" | "$(bin)"/insert-icon > "${COMMIT_MSG_FILE}" +else echo "See https://www.conventionalcommits.org/en/v1.0.0" exit 1 fi diff --git a/tests/commit-msg-hook-test b/tests/commit-msg-hook-test index 1aa5d74..77820b6 100644 --- a/tests/commit-msg-hook-test +++ b/tests/commit-msg-hook-test @@ -59,3 +59,21 @@ result="$?" assert_equals "0" "${result}" unlink "${commitmsgfile}" + +#### +echo -e "\n> Test display the cog verify success message:" +commitmsgfile="$(new_temp_file "$(cat "$(fixtures_dir)/COMMIT_EDITMSG")")" +result="$("$(hooks_dir)"/commit-msg "${commitmsgfile}" |& grep -o "(not committed) - now")" + +assert_equals "(not committed) - now" "${result}" + +unlink "${commitmsgfile}" + +#### +echo -e "\n> Test display the cog verify error message:" +commitmsgfile="$(new_temp_file "$(cat "$(fixtures_dir)/NOT_SEMANTIC_COMMIT_EDITMSG")")" +result="$("$(hooks_dir)"/commit-msg "${commitmsgfile}" |& grep "Caused by:")" + +assert_equals "Caused by:" "${result}" + +unlink "${commitmsgfile}"