#!/usr/bin/env bash SCRIPT_DIR=$(dirname $(realpath ${BASH_SOURCE[0]})) GIT_DIR=$(git rev-parse --git-dir) GIT_ROOT=$(git rev-parse --show-toplevel) MSG_FILE="$GIT_DIR/SUBSYSTEMS_SPLIT_MSG" usage() { cat >&$1 <&2 exit 1 fi author_name=$(git log -n 1 --format=%an) author_email=$(git log -n 1 --format=%ae) author="$author_name <$author_email>" git log -n 1 --format=%B > "$MSG_FILE" if $option_edit; then if [[ -z $EDITOR ]]; then echo "Environment variable EDITOR is required for option --edit." >&2 exit 1 fi ($EDITOR "$MSG_FILE") elif ! $option_copy; then if head -n 1 "$MSG_FILE" | grep "^[^: ]\+\s*:" -q; then sed '1 s,^[^: ]\+\s*,$subsystem,' -i "$MSG_FILE" else buff_file="$(mktemp)" awk ' NR == 1 { l=sub(/^\s\+/, "", $line); print "$subsystem: " \ tolower(substr($l, 1, 1)) \ substr($l, 2); } NR != 1 ' "$MSG_FILE" > "$buff_file" mv "$buff_file" "$MSG_FILE" rm "$buff_file" fi fi HEAD=$(git rev-parse HEAD) git reset HEAD~1 --soft if ! "$SCRIPT_DIR/git-commit-subsystems" -F "$MSG_FILE" --author="$author"; then echo "Error on calling git-commit-subsystems." >&2 git reset $HEAD exit 1 fi