#!/bin/sh

# $1 is the path to a commit message file

# Exit if a rebase is in progress
if git rev-parse --git-dir >/dev/null 2>&1 && [ -d "$(git rev-parse --git-dir)/rebase-merge" ] || [ -d "$(git rev-parse --git-dir)/rebase-apply" ]; then
  exit 0
fi

# Exit 0 if aiautocommit does not exist
# This can happen if another system, with a shell which does not load ~/.zshrc and friends,
# attempts to commit.
if ! command -v aiautocommit >/dev/null 2>&1; then
  exit 0
fi

aiautocommit commit --output-file "$1"
