#!/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.
