#!/usr/bin/env bash

# Get the list of files that are about to be committed and filter out only the .jl files
files=$(git diff --cached --name-only --diff-filter=ACM | grep "\.jl$")

# If no files are found, exit
if [ -z "$files" ]; then
    exit 0
fi

# Run the herb formatter on the list of files
julia --startup-file=no -O1 --color=yes .dev/herb_format.jl --check $files

# If the formatter exited with an error, abort the commit
if [ $? -ne 0 ]; then
    echo "Error: formatter must be run on the files before committing."
    echo "Please run julia .dev/herb_format.jl YOUR_CHANGED_FILES.jl"
    exit 1
fi
