# Read parameters
# NOTHING TO READ HERE

# Set failing on command fail, and undefined variable use
set -eu

# This hook is invoked by git-commit, and can be bypassed with the
# --no-verify option. It takes no parameters, and is invoked before
# obtaining the proposed commit log message and making a commit.
# Exiting with a non-zero status from this script causes the git
# commit command to abort before creating a commit.

# The default pre-commit hook, when enabled, catches introduction of
# lines with trailing whitespaces and aborts the commit when such a
# line is found.

# All the git commit hooks are invoked with the environment variable
# GIT_EDITOR=: if the command will not bring up an editor to modify
# the commit message.

# The default pre-commit hook, when enabled and with the hooks.allownonascii
# config option unset or set to false prevents the use of non-ASCII filenames.

# We currently use this hook to update the changelog of the project
# and make sure all files are prettified before sending them to the commit.
# Generated files are added to the commit.

# Show welcome message
echo "**************************"
echo "Running pre commit hooks"
echo "**************************"
echo ""

# Run license
echo "\nAdd license text to code files\n"
npx --no -- gobstones-scripts run license --silent

# Run changelog
echo "\nRun changelog\n"
# Only run if not first commit
if git-log &> /dev/null; then
    npx --no -- gobstones-scripts run changelog --silent
fi

# Run prettify
echo "Run prettify\n"
npx --no -- gobstones-scripts run prettify --silent

# Add all generated files
echo "\nAdd generated files to commit\n"
git add --all

# Exit
exit 0
