From 71f09a81b0c190d69e28a6c122b559560fc72a26 Mon Sep 17 00:00:00 2001 From: welpo Date: Wed, 7 Feb 2024 17:13:45 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=B7=20misc(CI):=20use=20git-sumi=20hoo?= =?UTF-8?q?k=20to=20lint=20commit=20messages?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .githooks/commit-msg | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100755 .githooks/commit-msg diff --git a/.githooks/commit-msg b/.githooks/commit-msg new file mode 100755 index 000000000..b77e47ec8 --- /dev/null +++ b/.githooks/commit-msg @@ -0,0 +1,25 @@ +#!/usr/bin/env bash + +# Commit-msg hook generated by git-sumi. +# For more information and documentation, visit: https://sumi.rs + +set -e # Exit on any error. + +# Get the current branch name. +current_branch=$(git rev-parse --abbrev-ref HEAD) + +# Check if the current branch is 'main'. +if [ "$current_branch" != "main" ]; then + exit 0 # Exit successfully without running git-sumi. +fi + +# Check if git-sumi is installed. +if ! command -v git-sumi &> /dev/null +then + echo "git-sumi is not installed. Please install it. See https://sumi.rs for instructions." + echo "Alternatively, edit or remove the commit-msg hook in .git/hooks/commit-msg." + exit 1 +fi + +# Run git-sumi on the commit message if on the 'main' branch. +git-sumi -- "$(cat $1)" # Exit with error if linting fails.